/** * Loads all selected submissions as a zip file. * * Called when this component receives an HTTP GET request to * /submissions/exercisesheet/$sheetid/user/$userid. * * @param int $sheetid The id of the sheet of which the submissions should * be zipped. * @param int $userid The id of the user whose submissions should be zipped. * * @author Till Uhlig * @date 2014 */ public function loadSubmissionAsZip($sheetid, $userid) { $result = Request::routeRequest('GET', '/submission/group/user/' . $userid . '/exercisesheet/' . $sheetid . '/selected', $this->app->request->headers->all(), '', $this->_submission, 'submission'); if ($result['status'] >= 200 && $result['status'] <= 299) { $submissions = Submission::decodeSubmission($result['content']); $files = array(); foreach ($submissions as $submission) { $file = $submission->getFile(); $file->setDisplayName($file->getDisplayName()); $files[] = $file; } $result = Request::routeRequest('POST', '/zip/' . $sheetid . '.zip', $this->app->request->headers->all(), File::encodeFile($files), $this->_zip, 'zip'); if ($result['status'] >= 200 && $result['status'] <= 299) { $this->app->response->setBody($result['content']); $this->app->response->setStatus(200); if (isset($result['headers']['Content-Type'])) { $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']); } if (isset($result['headers']['Content-Disposition'])) { $this->app->response->headers->set('Content-Disposition', $result['headers']['Content-Disposition']); } $this->app->stop(); } } $this->app->response->setBody(''); $this->app->response->setStatus(404); $this->app->stop(); }
set_time_limit(180); $URI = $databaseURI . "/group/exercisesheet/{$sid}"; $groups = http_get($URI, true, $message); $groups = Group::decodeGroup($groups); if ($message == "200") { $URI = $databaseURI . "/exercisesheet/{$sid}/exercise"; $exerciseSheet = http_get($URI, true, $message); $exerciseSheet = ExerciseSheet::decodeExerciseSheet($exerciseSheet); if ($message == "200") { $exercises = array(); foreach ($exerciseSheet->getExercises() as $exercise) { $exercises[] = $exercise->getId(); } $URI = $databaseURI . "/submission/exercisesheet/{$sid}/selected"; $submissions = http_get($URI, true, $message); $submissions = Submission::decodeSubmission($submissions); if ($message == "200") { $users = array(); foreach ($exercises as $exercise) { $users[$exercise] = array(); foreach ($groups as $group) { $users[$exercise][] = $group->getLeader()->getId(); } } unset($groups); $submitted = array(); foreach ($exercises as $exercise) { $submitted[$exercise] = array(); } foreach ($submissions as $submission) { $submitted[$submission->getExerciseId()][] = $submission->getLeaderId();
public static function ExtractSubmission($data, $singleResult = false, $FileExtension = '', $SubmissionExtension = '', $isResult = true) { // generates an assoc array of files by using a defined list of // its attributes $files = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $FileExtension); // generates an assoc array of submissions by using a defined list of // its attributes $submissions = DBJson::getObjectsByAttributes($data, Submission::getDBPrimaryKey(), Submission::getDBConvert(), $SubmissionExtension); // sets the selectedForGroup attribute foreach ($submissions as &$submission) { if (isset($submission['selectedForGroup'])) { if (isset($submission['id']) && $submission['id'] == $submission['selectedForGroup']) { $submission['selectedForGroup'] = (string) 1; } else { unset($submission['selectedForGroup']); } } } // concatenates the submissions and the associated files $res = DBJson::concatObjectListsSingleResult($data, $submissions, Submission::getDBPrimaryKey(), Submission::getDBConvert()['S_file'], $files, File::getDBPrimaryKey(), $FileExtension, $SubmissionExtension); if ($isResult) { // to reindex $res = array_values($res); $res = Submission::decodeSubmission($res, false); if ($singleResult == true) { // only one object as result if (count($res) > 0) { $res = $res[0]; } } } return $res; }
//echo $result; if ($message != "201") { $result = Submission::decodeSubmission($result); $exercise = $key + 1; $errormsg = Language::Get('main', 'errorUploadSubmission', $langTemplate, array('status' => $message, 'exerciseName' => $exercise['name'])); if ($result !== null && !empty($result)) { $errormsg .= "<br><br>"; $messages = $result->getMessages(); foreach ($messages as $message) { $errormsg .= str_replace("\n", '<br>', $message) . '<br>'; } } $notifications[] = MakeNotification('error', $errormsg); continue; } else { $result = Submission::decodeSubmission($result); // if using forms, upload user input if (isset($exercise['choices'])) { $i = 0; foreach ($formdata as &$form) { $choices = $form->getChoices(); foreach ($choices as &$choice) { $choice->setSubmissionId($result->getId()); } $URL = $serverURI . '/DB/DBChoice/formResult/choice'; $result2 = http_post_data($URL, Choice::encodeChoice($choices), true, $message); if ($message != "201") { $result2 = Choice::decodeChoice($result2); $exercise = $key + 1; $errormsg = Language::Get('main', 'errorUploadSubmission', $langTemplate, array('status' => $message, 'exerciseName' => $exercise['name'])); if ($result2 !== null) {
/** * 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)); } }
} if (!isset($exercise['submission']) && (isset($statusID) && $statusID != 0 || isset($tutorID) && $tutorID != 'all')) { continue; } if (isset($exercise['submission'])) { if (isset($exercise['submission']['marking'])) { // submission + marking $tempMarking = Marking::decodeMarking(json_encode($exercise['submission']['marking'])); $tempSubmission = Submission::decodeSubmission(json_encode($exercise['submission'])); $tempMarking->setSubmission($tempSubmission); $markings[] = $tempMarking; } else { // no marking $tempMarking = Marking::createMarking($newMarkings, $uid, null, $exercise['submission']['id'], null, null, 1, null, $timestamp, null); $newMarkings--; $tempSubmission = Submission::decodeSubmission(json_encode($exercise['submission'])); $tempMarking->setSubmission($tempSubmission); $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; } } } }
<?php if (isset($_POST['action']) && isset($_POST['action']) && $_POST['action'] == "AssignManually") { set_time_limit(180); // automatically assigns all unassigned proposed submissions to tutors if (isset($_POST['actionAssignAllProposals'])) { // load user data from the database $URL = $getSiteURI . "/tutorassign/user/{$uid}/course/{$cid}/exercisesheet/{$sid}"; $tutorAssign_data = http_get($URL, true); $tutorAssign_data = json_decode($tutorAssign_data, true); $markings = array(); if (!empty($tutorAssign_data['tutorAssignments'])) { foreach ($tutorAssign_data['tutorAssignments'] as $tutorAssignment) { if (isset($tutorAssignment['proposalSubmissions'])) { foreach ($tutorAssignment['proposalSubmissions'] as $submission) { $sub = Submission::decodeSubmission(json_encode($submission)); $marking = new Marking(); $marking->setSubmission($sub); $marking->setStatus(1); $marking->setTutorId($tutorAssignment['tutor']['id']); $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 {
/** * the constructor * * @param $data an assoc array with the object informations */ public function __construct($data = array()) { if ($data === null) { $data = array(); } foreach ($data as $key => $value) { if (isset($key)) { if ($key == 'attachment') { $this->{$key} = Attachment::decodeAttachment($value, false); } else { if ($key == 'workFiles') { $this->{$key} = Attachment::decodeAttachment($value, false); } else { if ($key == 'target') { $this->{$key} = Component::decodeComponent($value, false); } else { if ($key == 'submission') { $this->{$key} = Submission::decodeSubmission($value, false); } else { if ($key == 'rawSubmission') { $this->{$key} = Submission::decodeSubmission($value, false); } else { if ($key == 'marking') { $this->{$key} = Marking::decodeMarking($value, false); } else { if ($key == 'exercise') { $this->{$key} = Exercise::decodeExercise($value, false); } else { $func = 'set' . strtoupper($key[0]) . substr($key, 1); $methodVariable = array($this, $func); if (is_callable($methodVariable)) { $this->{$func}($value); } else { $this->{$key} = $value; } } } } } } } } } } }
/** * the constructor * * @param $data an assoc array with the object informations */ public function __construct($data = array()) { if ($data === null) { $data = array(); } foreach ($data as $key => $value) { if (isset($key)) { if ($key == 'submissions') { $this->{$key} = Submission::decodeSubmission($value, false); } elseif ($key == 'attachments') { $this->{$key} = File::decodeFile($value, false); } elseif ($key == 'fileTypes') { $this->{$key} = ExerciseFileType::decodeExerciseFileType($value, false); } else { $func = 'set' . strtoupper($key[0]) . substr($key, 1); $methodVariable = array($this, $func); if (is_callable($methodVariable)) { $this->{$func}($value); } else { $this->{$key} = $value; } } } } }
/** * Updates the selected submission of a group. * * @param string $databaseURI The url at which the database server is running. * @param int $leaderId The id of the the group's leader * @param int $submissionUd The new selected submission * @param int $exerciseId The submission's exercise id. * @param string &$message A reference to a variable that will contain the HTTP * status code on return. * * @return string On success rturns a json object, representing the selected * submission in the database. NULL otherwise. */ function updateSelectedSubmission($databaseURI, $leaderId, $submissionId, $exerciseId, &$message, $newFlag = null) { $selectedSubmission = SelectedSubmission::createSelectedSubmission($leaderId, $submissionId, $exerciseId); $URL = $databaseURI . '/selectedsubmission'; $returnedSubmission = http_post_data($URL, json_encode($selectedSubmission), true, $message); if ($message != "201") { $URL = $databaseURI . '/selectedsubmission/leader/' . $leaderId . '/exercise/' . $exerciseId; $returnedSubmission = http_put_data($URL, json_encode($selectedSubmission), true, $message); } if ($newFlag !== null) { // todo: treat the case if the previous operation failed if ($submissionId === null) { $ret = Submission::decodeSubmission($returnedSubmission); $submissionId = $ret->getId(); } $URL = $databaseURI . '/submission/submission/' . $submissionId; $submissionUpdate = Submission::createSubmission($submissionId, null, null, null, null, null, null, $newFlag); $returnedSubmission2 = http_put_data($URL, json_encode($submissionUpdate), true, $message2); } return $returnedSubmission; }