[Poll] Store poll response to DB

This commit is contained in:
Daniel
2020-11-04 19:43:36 +00:00
committed by Hugo Sales
parent 3725818e4f
commit 27a0c43f7b
3 changed files with 39 additions and 27 deletions

View File

@@ -139,11 +139,29 @@ class Poll extends Entity
return self::create(['question' => $question, 'options' => $options]);
}
public function getOptionsArr()
public function getOptionsArr(): array
{
return explode("\n", $this->options);
}
/**
* Is this a valid selection index?
*
* @param int $selection (1-based)
*
* @return bool
*/
public function isValidSelection($selection): bool
{
if ($selection != (int) $selection) {
return false;
}
if ($selection < 1 || $selection > count($this->getOptionsArr())) {
return false;
}
return true;
}
//from old version
/**
* Get a bookmark based on a notice
@@ -159,26 +177,6 @@ class Poll extends Entity
}
*/
/**
* Is this a valid selection index?
*
* @param int $selection (1-based)
*
* @return bool
*/
/*
public function isValidSelection($selection)
{
if ($selection != intval($selection)) {
return false;
}
if ($selection < 1 || $selection > count($this->getOptions())) {
return false;
}
return true;
}
*/
/*
public function getNotice()
{