/** * Adds the component to a course */ public function addCourse($pre = '') { $this->loadConfig($pre); $pre = ($pre === '' ? '' : '_') . $pre; Logger::Log('starts POST AddCourse', LogLevel::DEBUG); // decode the received course data, as an object $insert = Course::decodeCourse($this->_app->request->getBody()); // always been an array $arr = true; if (!is_array($insert)) { $insert = array($insert); $arr = false; } // this array contains the indices of the inserted objects $res = array(); foreach ($insert as $in) { // starts a query, by using a given file $result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/AddCourse.sql', array('object' => $in, 'pre' => $pre)); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $queryResult = Query::decodeQuery($result['content']); $res[] = $in; $this->_app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { Logger::Log('POST AddCourse failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->_app->response->setBody(Course::encodeCourse($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Course::encodeCourse($res[0])); } else { $this->_app->response->setBody(Course::encodeCourse($res)); } }
/** * Sendet den Inhalt von $file an $linkName und behandelt die Antwort * * @param string $linkName Der Name des Ausgangs * @param string $file Der Pfad des SQL Templates * @param mixed[] $params Die Variablen, welche im Template verwendet werden können (Bsp.: array('time'=>12) * @param int $positiveStatus Der Status, welcher als erfolgreiche Antwort gesehen wird (Bsp.: 200) * @param callable $positiveMethod Im positiven Fall wird diese Methode aufgerufen * @param mixed[] $positiveParams Die Werte, welche an die positive Funktion übergeben werden * @param callable $negativeMethod Im negativen Fall wird diese Methode aufgerufen * @param mixed[] $negativeParams Die Werte, welche an die negative Funktion übergeben werden * @param bool $checkSession Ob die Sessiondaten in der Datenbank geprüft werden sollen * @return mixed Das Ergebnis der aufgerufenen Resultatfunktion */ public function callSqlTemplate($linkName, $file, $params, $positiveStatus, callable $positiveMethod, $positiveParams, callable $negativeMethod, $negativeParams, $checkSession = true) { $link = CConfig::getLink($this->_conf->getLinks(), $linkName); // führe nun den Aufruf mit der SQL $file aus $result = DBRequest::getRoutedSqlFile($link, $file, $params, $checkSession); if ($result['status'] == $positiveStatus) { // die Antwort war so, wie wir sie erwartet haben $queryResult = Query::decodeQuery($result['content']); if (!is_array($queryResult)) { $queryResult = array($queryResult); } // rufe nun die positive Methode auf return call_user_func_array($positiveMethod, array_merge(array("input" => $queryResult), $positiveParams)); } // ansonsten rufen wir die negative Methode auf return call_user_func_array($negativeMethod, $negativeParams); }