Created
December 16, 2013 11:58
-
-
Save Tocacar/7985959 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//answer entity class | |
/** | |
* Set answer | |
* | |
* If answer is an array, converts to | |
* string with 'CSV:' prepended. This | |
* value is used to detect whether or not | |
* to convert answer back to array for form | |
* choice widget (checkbox requires array) | |
* | |
* @param string $answer | |
* @return Answer | |
*/ | |
public function setAnswer($answer) | |
{ | |
if(is_array($answer)){ | |
$answer = implode (',', $answer); | |
$answer = 'CSV:'.$answer; | |
} | |
$this->answer = $answer; | |
return $this; | |
} | |
/** | |
* Set answer as array | |
* | |
* Converts string answer into array | |
* | |
* @param $answer | |
* @return $this | |
*/ | |
public function setAnswerAsArray($answer) | |
{ | |
$answer = str_replace('CSV:', '', $answer); | |
$this->answer = explode(',', $answer); | |
return $this; | |
} | |
/** | |
* Get answer | |
* | |
* @return string | |
*/ | |
public function getAnswer() | |
{ | |
return $this->answer; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// event listener that sets data in form before it is displayed | |
if(substr($answer->getAnswer(), 0, 4) == "CSV:"){ | |
$answer->setAnswerAsArray($answer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment