Example #1
0
 public function save()
 {
     $this->load->table('question');
     $this->load->module_table('maze', 'response');
     $question = new Question_delegate();
     $question->bind($_POST);
     $question->store();
     $responses = $this->input->post('response');
     $response_ids = array();
     foreach ($responses as $response) {
         $resp = new Response_delegate();
         $resp->bind($response);
         $resp->question_id = $question->id;
         $resp->store();
         if (false === empty($resp->id)) {
             $response_ids[] = $resp->id;
         }
     }
     if (0 < sizeof($response_ids)) {
         $query = 'DELETE FROM ' . $this->db->protect_identifiers('responses') . ' WHERE question_id = ? AND id NOT IN (' . implode(',', $response_ids) . ')';
         $this->db->query($query, array($question->id));
     }
     redirect('admin/questions');
 }
Example #2
0
 /**
  * Answer a question
  *
  * @param int $id	response id
  */
 public function answer($id)
 {
     $result = new AnswerVO();
     $result->success = true;
     $this->load->model('current_room');
     $this->load->table('response');
     $this->load->table('response_log');
     try {
         $response = new Response_delegate($id);
         $response->load();
         $this->current_room->setId($this->gamesession->getRoom());
         $current_room =& $this->current_room->getRoom();
         /**
          * Log the response for later analysis
          */
         $response_log = new Response_log_delegate();
         $response_log->gamesession_id = $this->gamesession->getId();
         $response_log->response_id = $id;
         $response_log->store();
         if ($id != $response->id) {
             $result->success = false;
             $result->message = $this->_createMessage('Unable to load response');
         } else {
             if (1 == $response->end_game_immediately) {
                 $result->success = false;
                 $result->message = $this->_createMessage($response->response, '', 'Exit Maze', 'restartGame');
             } else {
                 $this->gamesession->setPoints($this->gamesession->getPoints() + $response->points_awarded);
                 $this->gamesession->setTimeRemaining($this->gamesession->getTimeRemaining() - $response->schedule_change);
                 ObjectHelper::shallowCopy($this->gamesession, &$result);
                 ObjectHelper::shallowCopy($response, &$result);
                 if (1 == $response->move_ahead) {
                     $this->gamesession->addCompletedQuestion($response->question_id);
                     $this->current_room->setId($this->gamesession->getRoom());
                     $new_room =& $this->current_room->getRedirectRoom();
                     if (false === empty($new_room)) {
                         if (false === empty($new_room->force_orientation)) {
                             $this->gamesession->setCurrentOrientation($new_room->force_orientation);
                         }
                         $result->new_room = $this->_serializeRoom($this->current_room->getRedirectRoom());
                         $this->gamesession->setRoom($new_room->id);
                     }
                     if (1 == $current_room->end_point) {
                         $result->success = false;
                         $result->message = $this->_createMessage($response->response, '', 'See Results', 'showFinish');
                     }
                 }
                 $result->progress_img = site_url(self::PROGRESS_METER_PREFIX . $this->gamesession->getLevel() . '_' . sizeof($this->gamesession->getCompletedQuestions()) . '.gif');
             }
         }
     } catch (Exception $e) {
         $result->success = false;
         $result->message = $result->message = $this->_createMessage($e->getMessage());
     }
     if (0 >= $this->gamesession->getTimeRemaining()) {
         $result->success = false;
         $result->message = $this->_createMessage($response->response, 'Out of Time', 'See Results', 'showFinish');
     }
     echo json_encode($result);
 }