Beispiel #1
0
 function update_action($range_id)
 {
     $vote_id = self::ensureMD5(Request::option('vote_id'));
     $choice = self::ensureMD5(Request::option('choice'));
     $q = \Cliqr\Question::find($vote_id);
     # no such active question in this range_id
     if (!$q->isActiveIn($range_id)) {
         throw new Trails_Exception(400);
     }
     $status = $q->recordAnswer($choice);
     if (Request::isXhr()) {
         if ($status) {
             $this->response->set_status(204, "No Content");
             return $this->render_nothing();
         } else {
             throw new Trails_Exception(500, "Could not record");
         }
     } else {
         if ($status) {
             $this->response->set_status(204, "No Content");
         } else {
             $this->response->set_status(500, "Could not record");
         }
         # TODO
         $this->render_nothing();
     }
 }
Beispiel #2
0
 private function updateQuestion($question, $params)
 {
     $dirty = false;
     // UPDATE QUESTION
     if (isset($params['question'])) {
         $question->setQuestion($q = $params['question']);
         $question->setTitle(my_substr($q, 0, 50));
         $dirty = true;
     }
     // UPDATE CHOICES
     // TODO zuviel in dieser action, besser nur 10 zeilen pro function
     if (isset($params['answers'])) {
         $answers = array();
         foreach ($question->getAnswers() as $answer) {
             $answers[$answer['answer_id']] = $answer;
         }
         $new_answers = array();
         foreach ($params['answers'] as $id => $choice) {
             if ($choice !== '') {
                 $new_answers[] = is_int($id) ? Question::makeChoice($choice) : array_merge($answers[$id], array('text' => $choice));
             }
         }
         $question->setAnswers($new_answers);
         $dirty = true;
     }
     if ($dirty) {
         $question->executeWrite();
     }
     return $question->isError();
 }