Пример #1
0
 /**
  * Processes a submissions
  *
  * Called when this component receives an HTTP POST request to
  * /submission(/).
  */
 public function postSubmission()
 {
     $this->app->response->setStatus(201);
     $body = $this->app->request->getBody();
     $submissions = Submission::decodeSubmission($body);
     // always been an array
     $arr = true;
     if (!is_array($submissions)) {
         $submissions = array($submissions);
         $arr = false;
     }
     $res = array();
     foreach ($submissions as $submission) {
         $fail = false;
         $process = new Process();
         $process->setRawSubmission($submission);
         $eid = $submission->getExerciseId();
         // load processor data from database
         $result = Request::routeRequest('GET', '/process/exercise/' . $eid, array(), '', $this->_processorDb, 'process');
         $processors = null;
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $processors = Process::decodeProcess($result['content']);
         } else {
             if ($result['status'] != 404) {
                 $submission->addMessage("Interner Fehler");
                 $res[] = $submission;
                 $this->app->response->setStatus(409);
                 continue;
             }
         }
         $result2 = Request::routeRequest('GET', '/exercisefiletype/exercise/' . $eid, array(), '', $this->_getExerciseExerciseFileType, 'exercisefiletype');
         $exerciseFileTypes = null;
         if ($result2['status'] >= 200 && $result2['status'] <= 299) {
             $exerciseFileTypes = ExerciseFileType::decodeExerciseFileType($result2['content']);
             if (!is_array($exerciseFileTypes)) {
                 $exerciseFileTypes = array($exerciseFileTypes);
             }
             $filePath = null;
             if ($submission->getFile() != null) {
                 $file = $submission->getFile()->getBody(true);
                 if ($file !== null) {
                     $fileHash = sha1($file);
                     $filePath = '/tmp/' . $fileHash;
                     if ($submission->getFile()->getDisplayName() != null) {
                         LProcessor::generatepath($filePath);
                         file_put_contents($filePath . '/' . $submission->getFile()->getDisplayName(), $file);
                         $filePath .= '/' . $submission->getFile()->getDisplayName();
                     } else {
                         LProcessor::generatepath($filePath);
                         file_put_contents($filePath . '/tmp', $file);
                         $filePath .= '/tmp';
                     }
                 }
             }
             // check file type
             if ($filePath != null) {
                 $found = false;
                 $types = array();
                 $mimeType = MimeReader::get_mime($filePath);
                 $foundExtension = isset(pathinfo($filePath)['extension']) ? pathinfo($filePath)['extension'] : '-';
                 foreach ($exerciseFileTypes as $type) {
                     $types[] = $type->getText();
                     $type = explode(' ', str_replace('*', '', $type->getText()));
                     //echo MimeReader::get_mime($filePath);
                     if (strpos($mimeType, $type[0]) !== false && (!isset($type[1]) || '.' . $foundExtension == $type[1])) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found && count($exerciseFileTypes) > 0) {
                     $submission->addMessage("falscher Dateityp \nGefunden: " . $mimeType . " ." . $foundExtension . "\nErlaubt: " . implode(',', $types));
                     $res[] = $submission;
                     $this->app->response->setStatus(409);
                     unlink($filePath);
                     continue;
                 }
                 unlink($filePath);
             }
         } else {
             if ($result2['status'] != 404) {
                 $submission->addMessage("Interner Fehler");
                 $res[] = $submission;
                 $this->app->response->setStatus(409);
                 continue;
             }
         }
         // process submission
         if ($processors !== null) {
             if (!is_array($processors)) {
                 $processors = array($processors);
             }
             foreach ($processors as $pro) {
                 $component = $pro->getTarget();
                 if ($process->getExercise() === null) {
                     $process->setExercise($pro->getExercise());
                 }
                 $process->setParameter($pro->getParameter());
                 $process->setAttachment($pro->getAttachment());
                 $process->setTarget($pro->getTarget());
                 $process->setWorkFiles($pro->getWorkFiles());
                 //echo Process::encodeProcess($process)."_______";// return;
                 $result = Request::post($component->getAddress() . '/process', array(), Process::encodeProcess($process));
                 //echo $result['content'].'_______';
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $process = Process::decodeProcess($result['content']);
                 } else {
                     $fail = true;
                     $submission->addMessage("Beim Verarbeiten der Einsendung ist ein Fehler aufgetreten");
                     if (isset($result['content'])) {
                         $content = Process::decodeProcess($result['content']);
                         $submission->setStatus($content->getStatus());
                         $submission->addMessages($content->getMessages());
                     }
                     break;
                 }
             }
         }
         if ($fail) {
             if (isset($submission)) {
                 $submission->setFile(null);
             }
             $res[] = $submission;
             $this->app->response->setStatus(409);
             continue;
         }
         // upload submission
         $uploadSubmission = $process->getSubmission();
         if ($uploadSubmission === null) {
             $uploadSubmission = $process->getRawSubmission();
             if ($uploadSubmission->getFile() != null) {
                 $file = $uploadSubmission->getFile();
                 if ($file->getDisplayName() == null) {
                     $file->setDisplayName($submission->getExerciseName());
                 }
             }
         }
         if ($uploadSubmission !== null) {
             ///echo Submission::encodeSubmission($uploadSubmission);return;
             $result = Request::routeRequest('POST', '/submission', array(), Submission::encodeSubmission($uploadSubmission), $this->_submission, 'submission');
             //var_dump($result);return;
             // checks the correctness of the query
             if ($result['status'] >= 200 && $result['status'] <= 299) {
                 $queryResult = Submission::decodeSubmission($result['content']);
                 $uploadSubmission->setId($queryResult->getId());
                 $uploadSubmission->setFile($queryResult->getFile());
                 if ($process->getMarking() !== null) {
                     $process->getMarking()->setSubmission($queryResult);
                 }
             } else {
                 $uploadSubmission->addMessage("Beim Speichern der Einsendung ist ein Fehler aufgetreten.");
                 //var_dump($uploadSubmission); return;
                 if (isset($result['content'])) {
                     $content = Submission::decodeSubmission($result['content']);
                     $uploadSubmission->setStatus($content->getStatus());
                     $uploadSubmission->addMessages($content->getMessages());
                 }
                 $uploadSubmission->setStatus(409);
                 $res[] = $uploadSubmission;
                 $this->app->response->setStatus(409);
                 continue;
             }
         }
         // upload marking
         if ($process->getMarking() !== null) {
             //echo Marking::encodeMarking($process->getMarking());
             $result = Request::routeRequest('POST', '/marking', array(), Marking::encodeMarking($process->getMarking()), $this->_marking, 'marking');
             // checks the correctness of the query
             if ($result['status'] >= 200 && $result['status'] <= 299) {
                 $queryResult = Marking::decodeMarking($result['content']);
             } else {
                 $uploadSubmission->addMessage("Beim Speichern der Korrektur ist ein Fehler aufgetreten");
                 if (isset($result['content'])) {
                     $content = Marking::decodeMarking($result['content']);
                     $uploadSubmission->addMessages($content->getMessages());
                 }
                 $res[] = $uploadSubmission;
                 $this->app->response->setStatus(409);
                 continue;
             }
         }
         $rr = $process->getSubmission();
         if ($rr === null) {
             $rr = $process->getRawSubmission();
         }
         $res[] = $rr;
     }
     if (!$arr && count($res) == 1) {
         $this->app->response->setBody(Submission::encodeSubmission($res[0]));
     } else {
         $this->app->response->setBody(Submission::encodeSubmission($res));
     }
 }
Пример #2
0
 /**
  * Adds a new marking.
  *
  * Called when this component receives an HTTP POST request to
  * /marking(/).
  * The request body should contain a JSON object representing the new marking.
  *
  * @author Till Uhlig
  * @date 2014
  */
 public function addMarking()
 {
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $markings = Marking::decodeMarking($body);
     $this->app->response->setStatus(201);
     // always been an array
     $arr = true;
     if (!is_array($markings)) {
         $markings = array($markings);
         $arr = false;
     }
     // this array contains the inserted objects
     $res = array();
     foreach ($markings as $marking) {
         if ($marking->getDate() === null) {
             $marking->setDate(time());
         }
         $file = $marking->getFile();
         if (!isset($file)) {
             $file = new File();
         }
         if ($file->getTimeStamp() === null) {
             $file->setTimeStamp(time());
         }
         // upload file to filesystem
         $result = Request::routeRequest('POST', '/file', $this->app->request->headers->all(), File::encodeFile($file), $this->_file, 'file');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             // file is uploaded
             $newFile = File::decodeFile($result['content']);
             $file->setAddress($newFile->getAddress());
             $file->setHash($newFile->getHash());
             $file->setFileId($newFile->getFileId());
             $file->setBody(null);
             $marking->setFile($file);
             // upload marking to database
             if ($marking->getId() === null) {
                 $result = Request::routeRequest('POST', '/marking', $this->app->request->headers->all(), Marking::encodeMarking($marking), $this->_marking, 'marking');
             } else {
                 $result = Request::routeRequest('PUT', '/marking/marking/' . $marking->getId(), $this->app->request->headers->all(), Marking::encodeMarking($marking), $this->_marking, 'marking');
             }
             if ($result['status'] >= 200 && $result['status'] <= 299) {
                 // marking is uploaded
                 $newmarking = Marking::decodeMarking($result['content']);
                 if (is_array($newmarking)) {
                     $newmarking = $newmarking[0];
                 }
                 if ($newmarking->getId() !== null) {
                     $marking->setId($newmarking->getId());
                 }
                 $res[] = $marking;
                 if (isset($result['headers']['Content-Type'])) {
                     $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
                 }
             } else {
                 Logger::Log('POST AddMarking failed', LogLevel::ERROR);
                 $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
                 $this->app->response->setBody(Marking::encodeMarking($res));
                 $this->app->stop();
             }
         } else {
             Logger::Log('POST AddMarking failed', LogLevel::ERROR);
             $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->app->response->setBody(Marking::encodeMarking($res));
             $this->app->stop();
         }
     }
     if (!$arr && count($res) == 1) {
         $this->app->response->setBody(Marking::encodeMarking($res[0]));
     } else {
         $this->app->response->setBody(Marking::encodeMarking($res));
     }
 }
Пример #3
0
                // "unassigned" can't obtain proposals (-1 -> "unassiged")
                if ($selectedTutorID != -1) {
                    foreach ($proposals as $props) {
                        // assign to selected tutor
                        $sub = new Submission();
                        $sub->setId($props);
                        $marking = new Marking();
                        $marking->setSubmission($sub);
                        $marking->setStatus(1);
                        $marking->setTutorId($selectedTutorID);
                        $markings[] = $marking;
                    }
                }
            }
            $URI = $serverURI . "/logic/LMarking/marking";
            http_post_data($URI, Marking::encodeMarking($markings), true, $message);
            if ($message == "201" || $message == "200") {
                $msg = Language::Get('main', 'successAssignment', $langTemplate);
                $assignManuallyNotifications[] = MakeNotification("success", $msg);
            } else {
                $msg = Language::Get('main', 'errorAssignment', $langTemplate);
                $assignManuallyNotifications[] = MakeNotification("error", $msg);
            }
        } else {
            if (!isset($assignManuallyNotifications)) {
                $assignManuallyNotifications = array();
            }
            $assignManuallyNotifications = $assignManuallyNotifications + $f->notifications;
        }
    }
}
Пример #4
0
                        $markings[] = $tempMarking;
                    }
                } else {
                    // no submission
                    $tempMarking = Marking::createMarking($newMarkings, $uid, null, null, null, null, 1, null, $timestamp, null);
                    $tempSubmission = Submission::createSubmission($newMarkings, $group['leader']['id'], null, $exercise['id'], null, null, $timestamp, null, $group['leader']['id'], null);
                    $tempSubmission->setSelectedForGroup(1);
                    $newMarkings--;
                    $tempMarking->setSubmission($tempSubmission);
                    $markings[] = $tempMarking;
                }
            }
        }
    }
    $URI = $logicURI . '/tutor/archive/user/' . $uid . '/exercisesheet/' . $sid . '/withnames';
    $csvFile = http_post_data($URI, Marking::encodeMarking($markings), true);
    echo $csvFile;
    exit(0);
}
$markingTool_data['filesystemURI'] = $filesystemURI;
// adds the selected sheetID, tutorID and statusID
$markingTool_data['sheetID'] = $sid;
if (isset($tutorID)) {
    $markingTool_data['tutorID'] = $tutorID;
}
if (isset($statusID)) {
    $markingTool_data['statusID'] = $statusID;
}
if (isset($_POST['sortUsers'])) {
    $markingTool_data['sortUsers'] = $_POST['sortUsers'];
}
Пример #5
0
/**
 * Stores a marking in the database.
 *
 * @param $points The points of the marking
 * @param $tutorComment The tutor's comment
 * @param $status The status of the marking
 * @param $submissionID The id of the submission, if set, -1 otherwise
 * @param $markingID The id of the marking, if set, -1 otherwise
 * @param $leaderID The id of the group leader
 * @param $tutorID The id of the tutor who creates the marking
 * @param $eID The id of the exercisesheet
 *
 * @return bool Returns true on success, false otherwise 
 */
function saveMarking($points, $tutorComment, $status, $submissionID, $markingID, $leaderID, $tutorID, $eID)
{
    global $databaseURI;
    // submission and marking already exist and don't
    // need to be created before adding the marking data
    if ($submissionID != -1 && $markingID != -1) {
        $newMarking = Marking::createMarking($markingID, $tutorID, null, null, $tutorComment, null, $status, $points, time());
        $newMarking = Marking::encodeMarking($newMarking);
        $URI = $databaseURI . "/marking/{$markingID}";
        http_put_data($URI, $newMarking, true, $message);
        if ($message != 201) {
            return false;
        } else {
            return true;
        }
    } elseif ($submissionID != -1 && $markingID == -1) {
        // only the submission exists, the marking still
        // needs to be created before adding the marking data
        // creates the marking in the database
        $marking = createMarking($points, $tutorComment, $status, $submissionID, $tutorID);
        if (empty($marking)) {
            return false;
        } else {
            return true;
        }
    } elseif ($submissionID == -1 && $markingID == -1) {
        // neither the submission nor the marking exist - they both
        // need to be created before adding the marking data
        // creates the submission in the database
        $submission = createSubmission($leaderID, $eID);
        if (!empty($submission)) {
            // creates the marking in the database
            $submissionID = $submission['id'];
            $marking = createMarking($points, $tutorComment, $status, $submissionID, $tutorID);
            if (!empty($marking)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}