Example #1
0
 public function actionAnswer($id)
 {
     // get chosen variant IDs
     $chosenAnswers = array_values($_POST);
     // add answers for all answer variants for the given poll
     $poll = Poll::findById($id);
     foreach ($poll->questions as $question) {
         foreach ($question->variants as $variant) {
             $answer = new Answer();
             $answer->variant = $variant;
             $answer->answer = in_array($variant->id, $chosenAnswers);
             $answer->save(false);
             // but do not commit
         }
     }
     Model::flush();
     // commit
     $this->redirect($this->url('poll.stat', array('id' => $id)));
 }