51 public $multiply =
false;
85 public $allowAnonymous;
92 public $additionalFields = array();
115 public function init()
117 if($this->forwardTo === null){
118 $this->forwardTo = Yii::app()->request->requestUri;
122 public function run()
124 if(!$this->votedShow && Yii::app()->getModule(
'vote')->isUserVoted($this->
id)) {
125 $this->render(
'PoolWidget_hidden');
133 $question->id = $this->id;
134 $question->text = $this->question;
135 $question->author_id = $this->author_id;
136 if(!$question->save()){
137 throw new Exception(print_r($question->getErrors(),
true));
139 } elseif($question->text != $this->question || $question->author_id != $this->author_id) {
140 $question->text = $this->question;
141 $question->author_id = $this->author_id;
142 $question->update(array(
'text',
'author_id'));
145 $answerByKey = array();
146 foreach ($question->answers as $answ) {
147 $answerByKey[$answ->answer_key] = $answ;
149 $activeAnswers = array();
150 foreach ($this->answers as $answerKey => $answer) {
151 if(!is_string($answerKey)) {
152 throw new Exception(
VoteModule::t(
'Answer id should be string type. Answer: "{answer}". Id: {id}', array(
'{answer}' => $answer[
'text'],
'{id}' => $answerKey)));
154 if(isset($answerByKey[$answerKey])) {
155 $existedAnswer = $answerByKey[$answerKey];
156 unset($answerByKey[$answerKey]);
157 if($existedAnswer->active != 1 || $existedAnswer->order != $answer[
'order'] || $existedAnswer->text != $answer[
'text']) {
158 $existedAnswer->active = 1;
159 $existedAnswer->order = $answer[
'order'];
160 $existedAnswer->text = $answer[
'text'];
161 $existedAnswer->update(array(
'active',
'order',
'text'));
163 $activeAnswers[] = $existedAnswer;
165 $newAnswer =
new Answer();
166 $newAnswer->question_id = $question->id;
167 $newAnswer->answer_key = $answerKey;
168 $newAnswer->order = $answer[
'order'];
169 $newAnswer->text = $answer[
'text'];
170 if(!$newAnswer->save()){
171 throw new Exception(print_r($newAnswer->getErrors(),
true));
173 $activeAnswers[] = $newAnswer;
177 foreach ($answerByKey as $answer) {
178 if ($answer->active != 0) {
180 $answer->update(array(
'active'));
183 usort($activeAnswers,
function($a, $b){
return $a->order - $b->order;});
184 $answersData = array();
185 foreach ($activeAnswers as $answ) {
186 $answersData[$answ->id] = $answ->text;
188 $this->render(
'PoolWidget', array(
'question' => $question,
'answers' => $answersData));
191 public function getSecureResultOptions()
193 return Yii::app()->securityManager->hashData(serialize($this->resultOptions));