Example #1
0
 public function get($functionName, $sqlFile, $preChoice, $preForm, $preExercise, $formid, $choiceid, $courseid, $esid, $eid, $singleResult = false, $checkSession = true)
 {
     $this->loadConfig($preChoice, $preForm, $preExercise);
     $preChoice = ($preChoice === '' ? '' : '_') . $preChoice;
     $preForm = ($preForm === '' ? '' : '_') . $preForm;
     $preExercise = ($preExercise === '' ? '' : '_') . $preExercise;
     Logger::Log('starts GET ' . $functionName, LogLevel::DEBUG);
     // checks whether incoming data has the correct data type
     $choiceid = DBJson::mysql_real_escape_string($choiceid);
     $formid = DBJson::mysql_real_escape_string($formid);
     $preChoice = DBJson::mysql_real_escape_string($preChoice);
     $preForm = DBJson::mysql_real_escape_string($preForm);
     $preExercise = DBJson::mysql_real_escape_string($preExercise);
     // starts a query, by using a given file
     $result = DBRequest::getRoutedSqlFile($this->query, $sqlFile, array('formid' => $formid, 'choiceid' => $choiceid, 'courseid' => $courseid, 'esid' => $esid, 'eid' => $eid, 'preChoice' => $preChoice, 'preForm' => $preForm, 'preExercise' => $preExercise), $checkSession);
     // checks the correctness of the query
     if ($result['status'] >= 200 && $result['status'] <= 299) {
         $query = Query::decodeQuery($result['content']);
         if (is_array($query)) {
             $query = $query[count($query) - 1];
         }
         if ($query->getNumRows() > 0) {
             $res = Choice::ExtractChoice($query->getResponse(), $singleResult);
             $this->_app->response->setBody(Choice::encodeChoice($res));
             $this->_app->response->setStatus(200);
             if (isset($result['headers']['Content-Type'])) {
                 $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
             $this->_app->stop();
         } else {
             $result['status'] = 404;
         }
     }
     Logger::Log('GET ' . $functionName . ' failed', LogLevel::ERROR);
     $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
     $this->_app->response->setBody(Choice::encodeChoice(new Choice()));
     $this->_app->stop();
 }