Example #1
0
 public function get($functionName, $sqlFile, $userid, $courseid, $esid, $eid, $suid, $aid, $singleResult = false, $checkSession = true)
 {
     Logger::Log('starts GET ' . $functionName, LogLevel::DEBUG);
     // checks whether incoming data has the correct data type
     DBJson::checkInput($this->_app, $userid == '' ? true : ctype_digit($userid), $courseid == '' ? true : ctype_digit($courseid), $esid == '' ? true : ctype_digit($esid), $eid == '' ? true : ctype_digit($eid), $suid == '' ? true : ctype_digit($suid), $aid == '' ? true : ctype_digit($aid));
     // starts a query, by using a given file
     $result = DBRequest::getRoutedSqlFile($this->query, $sqlFile, array('userid' => $userid, 'courseid' => $courseid, 'esid' => $esid, 'eid' => $eid, 'suid' => $suid, 'aid' => $aid), $checkSession);
     // checks the correctness of the query
     if ($result['status'] >= 200 && $result['status'] <= 299) {
         $query = Query::decodeQuery($result['content']);
         if ($query->getNumRows() > 0) {
             $res = Attachment::ExtractAttachment($query->getResponse(), $singleResult);
             $this->_app->response->setBody(Attachment::encodeAttachment($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(Attachment::encodeAttachment(new Attachment()));
     $this->_app->stop();
 }
Example #2
0
 /**
  * Returns a specific component.
  *
  * @param $componentid a database component identifier
  */
 public function getComponent($componentid)
 {
     // checks whether incoming data has the correct data type
     DBJson::checkInput($this->_app, ctype_digit($componentid));
     // starts a query
     ob_start();
     eval("?>" . file_get_contents(dirname(__FILE__) . '/Sql/GetComponent.sql'));
     $sql = ob_get_contents();
     ob_end_clean();
     $result = DBRequest::request($sql, false, parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE));
     // checks the correctness of the query
     if ((!isset($result['errno']) || !$result['errno']) && $result['content']) {
         $data = DBJson::getRows($result['content']);
         $components = DBJson::getResultObjectsByAttributes($data, Component::getDBPrimaryKey(), Component::getDBConvert());
         $this->_app->response->setBody(json_encode($components));
         $this->_app->response->setStatus(200);
     } else {
         Logger::Log('GET GetComponent failed', LogLevel::ERROR);
         $this->_app->response->setStatus(409);
     }
 }