/** * Adds the component to a course * * Called when this component receives an HTTP POST request to * /course(/). */ public function addCourse() { Logger::Log('starts POST AddCourse', LogLevel::DEBUG); $header = $this->app->request->headers->all(); $body = $this->app->request->getBody(); $courses = Course::decodeCourse($body); $processes = array(); if (!is_array($courses)) { $courses = array($courses); } foreach ($courses as $course) { $process = new Process(); $exercise = new Exercise(); $exercise->setCourseId($course->getId()); $process->setExercise($exercise); $component = new Component(); $component->setId($this->_conf->getId()); $process->setTarget($component); $processes[] = $process; } foreach ($this->_postProcess as $_link) { $result = Request::routeRequest('POST', '/process', $header, Process::encodeProcess($processes), $_link, 'process'); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $this->app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { /* if ($courses->getId()!==null){ $this->deleteCourse($courses->getId()); }*/ Logger::Log('POST AddCourse failed', LogLevel::ERROR); $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->app->response->setBody(Course::encodeCourse($courses)); $this->app->stop(); } } $this->app->response->setBody(Course::encodeCourse($courses)); }
/** * Adds the component to a course * * Called when this component receives an HTTP POST request to * /course(/). */ public function addCourse() { Logger::Log('starts POST AddCourse', LogLevel::DEBUG); $body = $this->app->request->getBody(); // die Daten der Veranstaltung kommen über den Aufrufkörper rein $courses = Course::decodeCourse($body); $processes = array(); if (!is_array($courses)) { $courses = array($courses); } // wenn die Komponente direkt in mehrere Veranstaltungen eingetragen werden soll, // wird das Eintragen für alle vorgenommen foreach ($courses as $course) { // ab hier wird der neue Eintrag zusammengestellt $process = new Process(); $exercise = new Exercise(); $exercise->setCourseId($course->getId()); $process->setExercise($exercise); $component = new Component(); $component->setId($this->_conf->getId()); $process->setTarget($component); // und nun wird gesammelt $processes[] = $process; } // die erstellten Einträge können nun an den Zuständigen geschickt werden foreach ($this->_postProcess as $_link) { $result = Request::routeRequest('POST', '/process', array(), Process::encodeProcess($processes), $_link, 'process'); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { // wenn der Erstellvorgang erfolgreich war, können wir dies melden $this->app->response->setStatus(201); if (isset($result['headers']['Content-Type'])) { $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } } else { // der Eintrag konnte nicht erstellt werden /* if ($courses->getId()!==null){ $this->deleteCourse($courses->getId()); }*/ Logger::Log('POST AddCourse failed', LogLevel::ERROR); // gibt den Status der "Erstellanfrage" zurück oder eine 409 und zusätzlich // das eingehende Veranstaltungsobjekt $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->app->response->setBody(Course::encodeCourse($courses)); $this->app->stop(); } } // die bearbeiteten Veranstaltungen können nun zur Ausgabe hinzugefügt werden $this->app->response->setBody(Course::encodeCourse($courses)); }