Esempio n. 1
0
 /**
  * Deletes an exercise sheet.
  *
  * Called when this component receives an HTTP DELETE request to
  * /exercisesheet/exercisesheet/$sheetid(/).
  * Deletes the exercise sheet information from the database first. At success
  * the file belongs to this exercise will be deleted from the filesystem.
  *
  * @param int $sheetid The id of the exercise sheet that is being deleted.
  */
 public function deleteExerciseSheet($sheetid)
 {
     $this->app->response->setStatus(201);
     Logger::Log('starts DELETE DeleteExerciseSheet', LogLevel::DEBUG);
     $body = $this->app->request->getBody();
     $res = null;
     // getExerciseSheet
     $result = Request::routeRequest('GET', '/exercisesheet/' . $sheetid, array(), '', $this->_getExerciseSheet, 'exercisesheet');
     // checks the correctness of the query
     if ($result['status'] >= 200 && $result['status'] <= 299 && isset($result['content'])) {
         $exerciseSheet = ExerciseSheet::decodeExerciseSheet($result['content']);
         $sampleFile = $exerciseSheet->getSampleSolution();
         $sheetFile = $exerciseSheet->getSheetFile();
         // delete exerciseSheet
         $result = Request::routeRequest('DELETE', '/exercisesheet/' . $sheetid, array(), '', $this->_deleteExerciseSheet, 'exercisesheet');
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             // exerciseSheet is deleted
             // delete sampleSolution if exists
             if ($sampleFile !== null) {
                 $result = Request::routeRequest('DELETE', '/file/' . $sampleFile->getFileId(), array(), '', $this->_deleteFile, 'file');
             }
             // delete sheetFile if exists
             if ($sheetFile !== null) {
                 $result = Request::routeRequest('DELETE', '/file/' . $sheetFile->getFileId(), array(), '', $this->_deleteFile, 'file');
             }
             $res = new ExerciseSheet();
         } else {
             $res = null;
             $this->app->response->setStatus(409);
         }
     } else {
         $res = null;
         $this->app->response->setStatus(409);
     }
     if ($this->app->response->getStatus() != 201) {
         Logger::Log('DELETE DeleteExerciseSheet failed', LogLevel::ERROR);
     }
     $this->app->response->setBody(ExerciseSheet::encodeExerciseSheet($res));
 }
Esempio n. 2
0
                     // save mimeTypes in validated Exercises
                     $validatedExercises[$key1][$key2]['mime-type'] = $mimeTypes;
                 }
             }  else {
                 $notifications = array_merge($notifications, $eval->notifications);
                 $correctExercise = false;
                 break;
             }
         }
     }*/
 // only if validation was correct
 //$ready = $f->evaluate(true);
 $ready = true;
 if ($ready == true && $noFile == false && $correctExercise == true && $correctDates == true) {
     // encode to JSON
     $myExerciseSheetJSON = ExerciseSheet::encodeExerciseSheet($myExerciseSheet);
     // Post ExcercisSheet to logic Controllers to create it and get saved data
     $output = http_post_data($logicURI . "/exercisesheet", $myExerciseSheetJSON, true, $message);
     $output = json_decode($output, true);
     // create subtasks as exercise
     if ($message == 201) {
         if (isset($output['id'])) {
             $id = $output['id'];
             $sid = $id;
         }
         if ($sheet_data_old !== null) {
             // get removed exercises
             if (isset($sheet_data_old['exercises'])) {
                 function comp_func_cr($a, $b)
                 {
                     if (!isset($b['id'])) {