Example #1
0
 /**
  * Processes a process
  *
  * Called when this component receives an HTTP POST request to
  * /process(/).
  */
 public function postProcess()
 {
     $this->app->response->setStatus(201);
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $process = Process::decodeProcess($body);
     // always been an array
     $arr = true;
     if (!is_array($process)) {
         $process = array($process);
         $arr = false;
     }
     // this array contains the indices of the inserted objects
     $res = array();
     foreach ($process as $pro) {
         $eid = $pro->getExercise()->getId();
         // loads the form from database
         $result = Request::routeRequest('GET', '/form/exercise/' . $eid, $this->app->request->headers->all(), '', $this->_formDb, 'form');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             // only one form as result
             $forms = Form::decodeForm($result['content']);
             $forms = $forms[0];
             $formdata = $pro->getRawSubmission()->getFile();
             $timestamp = $formdata->getTimeStamp();
             if ($timestamp === null) {
                 $timestamp = time();
             }
             if ($formdata !== null && $forms !== null) {
                 $formdata = Form::decodeForm($formdata->getBody(true));
                 if (is_array($formdata)) {
                     $formdata = $formdata[0];
                 }
                 if ($formdata !== null) {
                     // evaluate the formdata
                     $points = 0;
                     $answers = $formdata->getChoices();
                     $correctAnswers = $forms->getChoices();
                     $allcorrect = true;
                     if ($forms->getType() == 0) {
                         $parameter = explode(' ', strtolower($pro->getParameter()));
                         if ($parameter === null || count($parameter) === 0 || $parameter[0] === '') {
                             if (DefaultNormalizer::normalizeText($correctAnswers[0]->getText()) != DefaultNormalizer::normalizeText($answers[0]->getText())) {
                                 $allcorrect = false;
                             }
                         } elseif (strtolower($parameter[0]) === 'distance1') {
                             $similarity = 0;
                             similar_text(DefaultNormalizer::normalizeText($answers[0]->getText()), DefaultNormalizer::normalizeText($correctAnswers[0]->getText()), $similarity);
                             if (isset($parameter[1])) {
                                 if ($similarity < $parameter[1]) {
                                     $allcorrect = false;
                                 }
                             } else {
                                 if ($similarity < 100) {
                                     $allcorrect = false;
                                 }
                             }
                         } elseif (strtolower($parameter[0]) === 'regularexpression') {
                             $i = 1;
                             $test = $parameter[$i];
                             while ($i < count($parameter)) {
                                 if (@preg_match($test, DefaultNormalizer::normalizeText($answers[0]->getText())) !== false) {
                                     break;
                                 }
                                 $test .= ' ' . $parameter[$i];
                                 $i++;
                             }
                             $match = @preg_match($test, DefaultNormalizer::normalizeText(DefaultNormalizer::normalizeText($answers[0]->getText())));
                             if ($match === false || $match == false || $test == '') {
                                 $allcorrect = false;
                             }
                         }
                     } elseif ($forms->getType() == 1) {
                         foreach ($correctAnswers as $mask) {
                             $foundInStudentsAnswer = false;
                             foreach ($answers as $answer) {
                                 if ($answer->getText() === $mask->getChoiceId()) {
                                     $foundInStudentsAnswer = true;
                                     break;
                                 }
                             }
                             if ($mask->getCorrect() === '1' && !$foundInStudentsAnswer) {
                                 $allcorrect = false;
                                 break;
                             } elseif ($mask->getCorrect() === '0' && $foundInStudentsAnswer) {
                                 $allcorrect = false;
                                 break;
                             }
                         }
                     } elseif ($forms->getType() == 2) {
                         foreach ($correctAnswers as $mask) {
                             $foundInStudentsAnswer = false;
                             foreach ($answers as $answer) {
                                 if ($answer->getText() === $mask->getChoiceId()) {
                                     $foundInStudentsAnswer = true;
                                     break;
                                 }
                             }
                             if ($mask->getCorrect() === '1' && !$foundInStudentsAnswer) {
                                 $allcorrect = false;
                                 break;
                             } elseif ($mask->getCorrect() === '0' && $foundInStudentsAnswer) {
                                 $allcorrect = false;
                                 break;
                             }
                         }
                     }
                     if ($allcorrect) {
                         $points = $pro->getExercise()->getMaxPoints();
                     }
                     // save the marking
                     #region Form to PDF
                     if ($pro->getMarking() === null) {
                         $raw = $pro->getRawSubmission();
                         $exerciseName = '';
                         if ($raw !== null) {
                             $exerciseName = $raw->getExerciseName();
                         }
                         $answer = "";
                         if ($forms->getType() == 0) {
                             $answer = $formdata->getChoices()[0]->getText();
                         }
                         if ($forms->getType() == 1) {
                             $answer = $this->ChoiceIdToText($formdata->getChoices()[0]->getText(), $forms->getChoices());
                         }
                         if ($forms->getType() == 2) {
                             foreach ($formdata->getChoices() as $chosen) {
                                 $answer .= $this->ChoiceIdToText($chosen->getText(), $forms->getChoices()) . '<br>';
                             }
                         }
                         $answer2 = "";
                         foreach ($forms->getChoices() as $chosen) {
                             if ($chosen->getCorrect() === '1') {
                                 $answer2 .= $chosen->getText() . '<br>';
                             }
                         }
                         $Text = "<h1>AUFGABE {$exerciseName}</h1>" . "<hr>";
                         if ($forms->getTask() !== null && trim($forms->getTask()) != '') {
                             $Text .= "<p>" . "<h2>Aufgabenstellung:</h2>" . $forms->getTask() . "</p>";
                         }
                         $Text .= "<p>" . "<h2>Antwort:</h2>" . "<span style=\"color: " . ($points === 0 ? 'red' : 'black') . "\">" . $answer . "</span></p>";
                         if ($points === 0) {
                             $Text .= "<p>" . "<h2>L&ouml;sung:</h2><span style=\"color: green\">" . $answer2 . "</span></p>";
                         }
                         if ($forms->getSolution() !== null && trim($forms->getSolution()) != '') {
                             $Text .= "<p>" . "<h2>L&ouml;sungsbegr&uuml;ndung:</h2>" . $forms->getSolution() . "</p>";
                         }
                         $Text .= "<p style=\"text-align: center;\">" . "<h2><span style=\"color: red\">{$points}P</span></h2>" . "</p>";
                         $pdf = Pdf::createPdf($Text);
                         //echo Pdf::encodePdf($pdf);return;
                         $result = Request::routeRequest('POST', '/pdf', array(), Pdf::encodePdf($pdf), $this->_pdf, 'pdf');
                         // checks the correctness of the query
                         if ($result['status'] >= 200 && $result['status'] <= 299) {
                             $pdf = File::decodeFile($result['content']);
                             $pdf->setDisplayName($exerciseName . '.pdf');
                             $pdf->setTimeStamp($timestamp);
                             $pdf->setBody(null);
                             $submission = $pro->getSubmission();
                             if ($submission === null) {
                                 $submission = $pro->getRawSubmission();
                             }
                             $studentId = $pro->getRawSubmission() !== null ? $pro->getRawSubmission()->getStudentId() : null;
                             if ($studentId === null) {
                                 $studentId = $pro->getSubmission() !== null ? $pro->getSubmission()->getStudentId() : null;
                             }
                             $marking = Marking::createMarking(null, $studentId, null, null, null, null, 3, $points, $submission->getDate() !== null ? $submission->getDate() : time());
                             if (is_object($submission)) {
                                 $marking->setSubmission(clone $submission);
                             }
                             $marking->setFile($pdf);
                             $pro->setMarking($marking);
                         } else {
                             $res[] = null;
                             $this->app->response->setStatus(409);
                             continue;
                         }
                     }
                     #endregion
                     $rawSubmission = $pro->getRawSubmission();
                     $rawFile = $rawSubmission->getFile();
                     $rawFile->setBody(Form::encodeForm($formdata), true);
                     $rawSubmission->setFile($rawFile);
                     $rawSubmission->setExerciseId($eid);
                     $pro->setRawSubmission($rawSubmission);
                     $res[] = $pro;
                     continue;
                 }
             }
         }
         $this->app->response->setStatus(409);
         $res[] = null;
     }
     if (!$arr && count($res) == 1) {
         $this->app->response->setBody(Process::encodeProcess($res[0]));
     } else {
         $this->app->response->setBody(Process::encodeProcess($res));
     }
 }
Example #2
0
 /**
  * Adds a form.
  *
  * Called when this component receives an HTTP POST request to
  * /form(/).
  */
 public function addForm()
 {
     Logger::Log('starts POST AddForm', LogLevel::DEBUG);
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $this->app->response->setStatus(201);
     $forms = Form::decodeForm($body);
     // always been an array
     $arr = true;
     if (!is_array($forms)) {
         $forms = array($forms);
         $arr = false;
     }
     // this array contains the indices of the inserted objects
     $res = array();
     $choices = array();
     foreach ($forms as $key => $form) {
         $choices[] = $form->getChoices();
         $forms[$key]->setChoices(null);
     }
     $resForms = array();
     foreach ($forms as $form) {
         $method = 'POST';
         $URL = '/form';
         if ($form->getFormId() !== null) {
             $method = 'PUT';
             $URL = '/form/' . $form->getFormId();
         }
         $result = Request::routeRequest($method, $URL, array(), Form::encodeForm($form), $this->_form, 'form');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299 && isset($result['content'])) {
             $newform = Form::decodeForm($result['content']);
             if ($form->getFormId() === null) {
                 $form->setFormId($newform->getFormId());
             }
             $resForms[] = $form;
         } else {
             $f = new Form();
             $f->setStatus(409);
             $resForms[] = $f;
         }
     }
     $forms = $resForms;
     $i = 0;
     foreach ($choices as &$choicelist) {
         foreach ($choicelist as $key2 => $choice) {
             if ($forms[$i]->getFormId() !== null) {
                 $formId = $forms[$i]->getFormId();
                 $choicelist[$key2]->setFormId($formId);
                 $method = 'POST';
                 $URL = '/choice';
                 if ($choicelist[$key2]->getChoiceId() !== null) {
                     $method = 'PUT';
                     $URL = '/choice/' . $choice->getChoiceId();
                 }
                 $result = Request::routeRequest($method, $URL, array(), Choice::encodeChoice($choicelist[$key2]), $this->_choice, 'choice');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $newchoice = Choice::decodeChoice($result['content']);
                     if ($choicelist[$key2]->getChoiceId() === null) {
                         $choicelist[$key2]->setChoiceId($newchoice->getChoiceId());
                     }
                     $choicelist[$key2]->setStatus(201);
                 } else {
                     $choicelist[$key2]->setStatus(409);
                 }
             }
         }
         $forms[$i]->setChoices($choicelist);
         $i++;
     }
     // checks the correctness of the query
     /*if ( $result['status'] >= 200 && 
                  $result['status'] <= 299 && isset($result['content'])){
                 $newforms = Form::decodeForm($result['content']);
                 if ( !is_array( $newforms ) )
                     $newforms = array($newforms);
                     
                 $i=0;    
                 foreach ($forms as &$form){
                     if ($form->getFormId() === null)
                         $form->setFormId($newforms[$i]->getFormId());
                     $i++;
                 }            
     
                 $sendChoices = array();
                 $i=0;
                 foreach ( $choices as $choicelist ){
                     foreach ( $choicelist as $choice ){
                         $choice->setFormId($forms[$i]->getFormId());
                         $sendChoices[] = $choice;
                     }
                 $i++; 
                 }
                 $choices = $sendChoices;
                 
                 $result = Request::routeRequest( 
                                                 'POST',
                                                 '/choice',
                                                 $this->app->request->headers->all( ),
                                                 Choice::encodeChoice($choices),
                                                 $this->_choice,
                                                 'choice'
                                                 );
                                 
                 // checks the correctness of the query
                 if ( $result['status'] >= 200 && 
                      $result['status'] <= 299 ){
                     $newchoices = Choice::decodeChoice($result['content']);
     
                     $choicelist = array();
                     $i=0;
                     foreach ( $choices as &$choice ){
                         $choice->setChoiceId($newchoices[$i]->getChoiceId());
                         
                         if (!isset($choicelist[$choice->getFormId()]))
                             $choicelist[$choice->getFormId()] = array();
                           
                         $choicelist[$choice->getFormId()][] = $choice;
                         
                         $i++;
                     }
                     
                     foreach ( $forms as &$form ){
                         $form->setChoices($choicelist[$form->getFormId()]);
                     }
                     
                     $res[] = $forms;
                     
                 } else{
                     // remove forms on failure
                     foreach ($forms as $form){
                         $result = Request::routeRequest( 
                                         'DELETE',
                                         '/form/'.$form->getFormId(),
                                         $this->app->request->headers->all( ),
                                         '',
                                         $this->_form,
                                         'form'
                                         );
                     }
                     
                     $res[] = null;
                     $this->app->response->setStatus( 409 );
                 }
                           
             } else {
                 $res[] = null;
                 $this->app->response->setStatus( 409 );
             }*/
     if ($this->app->response->getStatus() != 201) {
         Logger::Log('POST AddForms failed', LogLevel::ERROR);
     }
     if (!$arr && count($res) == 1) {
         $this->app->response->setBody(Form::encodeForm($res[0]));
     } else {
         $this->app->response->setBody(Form::encodeForm($res));
     }
 }
Example #3
0
 /**
  * Processes a process
  *
  * Called when this component receives an HTTP POST request to
  * /process(/).
  */
 public function postProcess()
 {
     $this->app->response->setStatus(201);
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $process = Process::decodeProcess($body);
     // always been an array
     $arr = true;
     if (!is_array($process)) {
         $process = array($process);
         $arr = false;
     }
     // this array contains the indices of the inserted objects
     $res = array();
     foreach ($process as $pro) {
         $eid = $pro->getExercise()->getId();
         // loads the form from database
         $result = Request::routeRequest('GET', '/form/exercise/' . $eid, $this->app->request->headers->all(), '', $this->_formDb, 'form');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             // only one form as result
             $forms = Form::decodeForm($result['content']);
             $forms = $forms[0];
             $formdata = $pro->getRawSubmission()->getFile();
             $timestamp = $formdata->getTimeStamp();
             if ($timestamp === null) {
                 $timestamp = time();
             }
             if ($formdata !== null && $forms !== null) {
                 $formdata = Form::decodeForm($formdata->getBody(true));
                 if (is_array($formdata)) {
                     $formdata = $formdata[0];
                 }
                 if ($formdata !== null) {
                     // check the submission
                     $fail = false;
                     $parameter = explode(' ', strtolower($pro->getParameter()));
                     $choices = $formdata->getChoices();
                     if ($forms->getType() == 0) {
                         foreach ($choices as &$choice) {
                             $i = 0;
                             for ($i < 0; $i < count($parameter); $i++) {
                                 $param = $parameter[$i];
                                 if ($param === null || $param === '') {
                                     continue;
                                 }
                                 switch ($param) {
                                     case 'isnumeric':
                                         if (!@preg_match("%^-?([0-9])+([,]([0-9])+)?\$%", DefaultNormalizer::normalizeText($choice->getText()))) {
                                             $fail = true;
                                             $pro->addMessage('"' . $choice->getText() . '" ist keine gültige Zahl. <br>Bsp.: -0,00');
                                         }
                                         break;
                                     case 'isdigit':
                                         if (!ctype_digit(DefaultNormalizer::normalizeText($choice->getText()))) {
                                             $fail = true;
                                             $pro->addMessage('"' . $choice->getText() . '" ist keine gültige Ziffernfolge.');
                                         }
                                         break;
                                     case 'isprintable':
                                         if (!ctype_print(DefaultNormalizer::normalizeText($choice->getText()))) {
                                             $fail = true;
                                             $pro->addMessage('"' . $choice->getText() . '" enthält nicht-druckbare Zeichen.');
                                         }
                                         break;
                                     case 'isalpha':
                                         if (!ctype_alpha(DefaultNormalizer::normalizeText($choice->getText()))) {
                                             $fail = true;
                                             $pro->addMessage('"' . $choice->getText() . '" ist keine gültige Buchstabenfolge.');
                                         }
                                         break;
                                     case 'isalphanum':
                                         if (!ctype_alnum(DefaultNormalizer::normalizeText($choice->getText()))) {
                                             $fail = true;
                                             $pro->addMessage('"' . $choice->getText() . '" ist nicht alphanumerisch.');
                                         }
                                         break;
                                     case 'ishex':
                                         if (!ctype_xdigit(DefaultNormalizer::normalizeText($choice->getText()))) {
                                             $fail = true;
                                             $pro->addMessage('"' . $choice->getText() . '" ist keine gültige Hexadezimalzahl.');
                                         }
                                         break;
                                     default:
                                         $test = $parameter[$i];
                                         $i++;
                                         while ($i < count($parameter)) {
                                             if (@preg_match($test, DefaultNormalizer::normalizeText($choice->getText())) !== false) {
                                                 break;
                                             }
                                             $test .= ' ' . $parameter[$i];
                                             $i++;
                                         }
                                         $match = @preg_match($test, DefaultNormalizer::normalizeText($choice->getText()));
                                         if ($match === false) {
                                             $fail = true;
                                             $pro->addMessage('"' . $test . '" ist kein gültiger regulärer Ausdruck.');
                                         } elseif ($match == false) {
                                             $fail = true;
                                             $pro->addMessage('"' . $choice->getText() . '" entspricht nicht dem regulären Ausdruck "' . $test . '".');
                                         }
                                         break;
                                 }
                             }
                         }
                     }
                     if ($fail) {
                         // received submission isn't correct
                         $pro->setStatus(409);
                         $res[] = $pro;
                         $this->app->response->setStatus(409);
                         continue;
                     }
                     // save the submission
                     #region Form to PDF
                     if ($pro->getSubmission() === null) {
                         $raw = $pro->getRawSubmission();
                         $exerciseName = '';
                         if ($raw !== null) {
                             $exerciseName = $raw->getExerciseName();
                         }
                         $answer = "";
                         if ($forms->getType() == 0) {
                             $answer = $formdata->getChoices()[0]->getText();
                         }
                         if ($forms->getType() == 1) {
                             $answer = $this->ChoiceIdToText($formdata->getChoices()[0]->getText(), $forms->getChoices());
                         }
                         if ($forms->getType() == 2) {
                             foreach ($formdata->getChoices() as $chosen) {
                                 $answer .= $this->ChoiceIdToText($chosen->getText(), $forms->getChoices()) . '<br>';
                             }
                         }
                         $Text = "<h1>AUFGABE {$exerciseName}</h1>" . "<hr>";
                         if ($forms->getTask() !== null && trim($forms->getTask()) != '') {
                             $Text .= "<p>" . "<h2>Aufgabenstellung:</h2>" . $forms->getTask() . "</p>";
                         }
                         $Text .= "<p>" . "<h2>Antwort:</h2>" . $answer . "</p>";
                         $pdf = Pdf::createPdf($Text);
                         $pdf->setText($Text);
                         //echo Pdf::encodePdf($pdf);return;
                         $result = Request::routeRequest('POST', '/pdf', array(), Pdf::encodePdf($pdf), $this->_pdf, 'pdf');
                         // checks the correctness of the query
                         if ($result['status'] >= 200 && $result['status'] <= 299) {
                             $pdf = File::decodeFile($result['content']);
                             $pdf->setDisplayName($exerciseName . '.pdf');
                             $pdf->setTimeStamp($timestamp);
                             $pdf->setBody(null);
                             if (is_object($pro->getRawSubmission())) {
                                 $submission = clone $pro->getRawSubmission();
                             } else {
                                 $submission = new Submission();
                             }
                             $submission->setFile($pdf);
                             $submission->setExerciseId($eid);
                             $pro->setSubmission($submission);
                         } else {
                             $pro->setStatus(409);
                             $res[] = $pro;
                             $this->app->response->setStatus(409);
                             continue;
                         }
                     }
                     #endregion
                     $rawSubmission = $pro->getRawSubmission();
                     $rawFile = $rawSubmission->getFile();
                     $rawFile->setBody(Form::encodeForm($formdata), true);
                     $rawSubmission->setFile($rawFile);
                     $rawSubmission->setExerciseId($eid);
                     $pro->setRawSubmission($rawSubmission);
                     $pro->setStatus(201);
                     $res[] = $pro;
                     continue;
                 }
             }
         }
         $this->app->response->setStatus(409);
         $pro->setStatus(409);
         $res[] = $pro;
     }
     if (!$arr && count($res) == 1) {
         $this->app->response->setBody(Process::encodeProcess($res[0]));
     } else {
         $this->app->response->setBody(Process::encodeProcess($res));
     }
 }
Example #4
0
        if ($allowed === null || $allowed == 1) {
            $msg = Language::Get('main', 'expiredExercisePerionDesc', $langTemplate, array('endDate' => date('d.m.Y  -  H:i', $upload_data['exerciseSheet']['endDate'])));
            $notifications[] = MakeNotification('warning', $msg);
        } else {
            set_error(Language::Get('main', 'expiredExercisePerion', $langTemplate, array('endDate' => date('d.m.Y  -  H:i', $upload_data['exerciseSheet']['endDate']))));
        }
    } elseif (!$hasStarted) {
        set_error(Language::Get('main', 'noStartedExercisePeriod', $langTemplate, array('startDate' => date('d.m.Y  -  H:i', $upload_data['exerciseSheet']['startDate']))));
    }
} else {
    set_error(Language::Get('main', 'noExercisePeriod', $langTemplate));
}
//$formdata = file_get_contents('FormSample.json');
$URL = $serverURI . "/DB/DBForm/form/exercisesheet/{$sid}";
$formdata = http_get($URL, true);
$formdata = Form::decodeForm($formdata);
if (!is_array($formdata)) {
    $formdata = array($formdata);
}
foreach ($formdata as $value) {
    foreach ($upload_data['exercises'] as &$key) {
        if ($value->getExerciseId() == $key['id']) {
            $key['form'] = $value;
            break;
        }
    }
}
$upload_data['hasStarted'] = $hasStarted;
$upload_data['isExpired'] = $isExpired;
$user_course_data = $upload_data['user'];
$menu = MakeNavigationElement($user_course_data, PRIVILEGE_LEVEL::STUDENT);
Example #5
0
 public static function ExtractForm($data, $singleResult = false, $FormsExtension = '', $ChoiceExtension = '', $isResult = true)
 {
     // generates an assoc array of an forms by using a defined
     // list of its attributes
     $forms = DBJson::getObjectsByAttributes($data, Form::getDBPrimaryKey(), Form::getDBConvert(), $FormsExtension);
     // generates an assoc array of choices by using a defined
     // list of its attributes
     $choices = DBJson::getObjectsByAttributes($data, Choice::getDBPrimaryKey(), Choice::getDBConvert(), $ChoiceExtension);
     // concatenates the forms and the associated choices
     $res = DBJson::concatObjectListResult($data, $forms, Form::getDBPrimaryKey(), Form::getDBConvert()['FO_choices'], $choices, Choice::getDBPrimaryKey(), $ChoiceExtension, $FormsExtension);
     if ($isResult) {
         // to reindex
         $res = array_values($res);
         $res = Form::decodeForm($res, false);
         if ($singleResult) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Example #6
0
 /**
  * Adds a form.
  *
  * Called when this component receives an HTTP POST request to
  * (/$pre)/form(/).
  */
 public function addForm()
 {
     Logger::Log('starts POST AddForm', LogLevel::DEBUG);
     // decode the received choice data, as an object
     $insert = Form::decodeForm($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/AddForm.sql', array('object' => $in));
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $queryResult = Query::decodeQuery($result['content']);
             // sets the new auto-increment id
             $obj = new Form();
             $course = Course::ExtractCourse($queryResult[count($queryResult) - 1]->getResponse(), true);
             $obj->setFormId($course->getId() . '_' . $queryResult[count($queryResult) - 2]->getInsertId());
             $res[] = $obj;
             $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 AddForm failed', LogLevel::ERROR);
             $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->_app->response->setBody(Form::encodeForm($res));
             $this->_app->stop();
         }
     }
     if (!$arr && count($res) == 1) {
         $this->_app->response->setBody(Form::encodeForm($res[0]));
     } else {
         $this->_app->response->setBody(Form::encodeForm($res));
     }
 }