コード例 #1
0
ファイル: LFormProcessor.php プロジェクト: sawh/ostepu-system
 /**
  * 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));
     }
 }
コード例 #2
0
ファイル: Download.php プロジェクト: sawh/ostepu-system
    $found = false;
    foreach ($data['courses'] as $key => $course) {
        if ($course['course']['id'] == $cid) {
            $data['courses'] = array($course);
            $found = true;
            break;
        }
    }
    if (!$found) {
        $data['courses'] = array();
    }
    $user_course_data = $data;
    Authentication::checkRights($permission, $cid, $uid, $user_course_data);
}
$_GET = cleanInput($_GET);
$types = Marking::getStatusDefinition();
$status = null;
foreach ($types as $type) {
    if (isset($_GET['downloadCSV_' . $type['id']])) {
        $status = $type['id'];
        $_GET['downloadCSV'] = $_GET['downloadCSV_' . $type['id']];
        break;
    }
}
if (isset($_GET['downloadCSV'])) {
    checkPermission(PRIVILEGE_LEVEL::TUTOR);
    $sid = cleanInput($_GET['downloadCSV']);
    $location = $logicURI . '/tutor/user/' . $uid . '/exercisesheet/' . $sid . (isset($status) ? '/status/' . $status : '');
    $result = http_get($location, true);
    echo $result;
    exit(0);
コード例 #3
0
ファイル: LProcessor.php プロジェクト: sawh/ostepu-system
 /**
  * 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));
     }
 }
コード例 #4
0
ファイル: MarkingTool.php プロジェクト: sawh/ostepu-system
                        $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
ファイル: LMarking.php プロジェクト: sawh/ostepu-system
 /**
  * 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));
     }
 }
コード例 #6
0
ファイル: LTutor.php プロジェクト: sawh/ostepu-system
 public function uploadZip($userid, $courseid)
 {
     // error array of strings
     $errors = array();
     LTutor::generatepath($this->config['DIR']['temp']);
     $tempDir = $this->tempdir($this->config['DIR']['temp'], 'extractZip', $mode = 0775);
     $body = File::decodeFile($this->app->request->getBody());
     //1 file-Object
     $filename = $tempDir . '/' . $courseid . '.zip';
     file_put_contents($filename, $body->getBody(true));
     unset($body);
     $zip = new ZipArchive();
     $zip->open($filename);
     $zip->extractTo($tempDir . '/files');
     $zip->close();
     unlink($filename);
     ///$this->deleteDir(dirname($filename));
     unset($zip);
     $files = $tempDir . '/files';
     // check if csv file exists
     if (file_exists($files . '/Liste.csv')) {
         $csv = fopen($files . '/Liste.csv', "r");
         if (($transactionId = fgetcsv($csv, 0, ';')) === false) {
             fclose($csv);
             $this->deleteDir($tempDir);
             $this->app->response->setStatus(409);
             $errors[] = 'empty .csv file';
             $this->app->response->setBody(json_encode($errors));
             $this->app->stop();
         }
         $result = Request::routeRequest('GET', '/transaction/authentication/TutorCSV_' . $userid . '_' . $courseid . '/transaction/' . $transactionId[0], array(), '', $this->_getTransaction, 'transaction');
         if (isset($result['status']) && $result['status'] == 200 && isset($result['content'])) {
             $transaction = Transaction::decodeTransaction($result['content']);
             $transaction = json_decode($transaction->getContent(), true);
             unset($result);
             $defaultOrder = array('ID', 'NAME', 'USERNAME', 'POINTS', 'MAXPOINTS', 'OUTSTANDING', 'STATUS', 'TUTORCOMMENT', 'STUDENTCOMMENT', 'FILE');
             $currectOrder = $defaultOrder;
             $markings = array();
             while (($row = fgetcsv($csv, 0, ';')) !== false) {
                 if (substr($row[0], 0, 2) == '--') {
                     $row[0] = substr($row[0], 2);
                     if (in_array(strtoupper($row[0]), $defaultOrder)) {
                         $currectOrder = array();
                         foreach ($row as $ro) {
                             $currectOrder[strtoupper($ro)] = count($currectOrder);
                         }
                     }
                 } elseif (implode('', $row) != '' && substr($row[0], 0, 2) != '--') {
                     if (isset($currectOrder['ID']) && !isset($row[$currectOrder['ID']]) || isset($currectOrder['POINTS']) && !isset($row[$currectOrder['POINTS']]) || isset($currectOrder['FILE']) && !isset($row[$currectOrder['FILE']]) || isset($currectOrder['TUTORCOMMENT']) && !isset($row[$currectOrder['TUTORCOMMENT']]) || isset($currectOrder['OUTSTANDING']) && !isset($row[$currectOrder['OUTSTANDING']]) || isset($currectOrder['STATUS']) && !isset($row[$currectOrder['STATUS']])) {
                         $errors[] = 'invalid Liste.csv';
                         fclose($csv);
                         $this->deleteDir($tempDir);
                         $this->app->response->setStatus(409);
                         $this->app->response->setBody(json_encode($errors));
                         $this->app->stop();
                     }
                     $markingId = isset($currectOrder['ID']) ? $row[$currectOrder['ID']] : null;
                     $points = isset($currectOrder['POINTS']) ? $row[$currectOrder['POINTS']] : null;
                     $points = str_replace(',', '.', $points);
                     $markingFile = isset($currectOrder['FILE']) ? $row[$currectOrder['FILE']] : null;
                     // check if markingId exists in transaction
                     if (!isset($transaction['markings'][$markingId])) {
                         // unknown markingId
                         fclose($csv);
                         $this->deleteDir($tempDir);
                         $this->app->response->setStatus(409);
                         $errors[] = "unknown ID: {$markingId}";
                         $this->app->response->setBody(json_encode($errors));
                         $this->app->stop();
                     }
                     ///var_dump($transaction['markings'][$markingId]);
                     $markingData = $transaction['markings'][$markingId];
                     // checks whether the points are less or equal to the maximum points
                     if ($points > $markingData['maxPoints'] || $points < 0) {
                         // too much points
                         ///fclose($csv);
                         ///$this->deleteDir($tempDir);
                         ///$this->app->response->setStatus(409);
                         ///$errors[] = "incorrect points in marking: {$markingId}";
                         ///$this->app->response->setBody(json_encode($errors));
                         ///$this->app->stop();
                     }
                     // checks if file with this markingid exists
                     if ($markingFile == null || $markingFile == '' || file_exists($files . '/' . $markingFile)) {
                         if ($markingFile != '' && $markingFile != null) {
                             $fileAddress = $files . '/' . $markingFile;
                             ///file_get_contents($files.'/'.$markingFile);
                             // file
                             $fileInfo = pathinfo($markingFile);
                             $file = new File();
                             $file->setDisplayName($fileInfo['basename']);
                             $file->setBody(Reference::createReference($fileAddress));
                         } else {
                             $file = null;
                         }
                         if (isset($transaction['markings'][$markingId]['submissionId']) && $transaction['markings'][$markingId]['submissionId'] < 0) {
                             // create new submission object
                             $submissionId = $transaction['markings'][$markingId]['submissionId'];
                             $studentId = $transaction['markings'][$markingId]['studentId'];
                             $exerciseId = $transaction['markings'][$markingId]['exerciseId'];
                             $submission = Submission::createSubmission(null, $studentId, null, $exerciseId, null, 1, time(), null, $leaderId, 1);
                             $submission->setSelectedForGroup('1');
                             ///echo json_encode($submission);return;
                             $result = Request::routeRequest('POST', '/submission', array(), json_encode($submission), $this->_postSubmission, 'submission');
                             if ($result['status'] == 201) {
                                 $transaction['markings'][$markingId]['submissionId'] = json_decode($result['content'], true)['id'];
                             }
                         }
                         // create new marking object
                         $marking = Marking::createMarking($markingId < 0 ? null : $markingId, $userid, null, $transaction['markings'][$markingId]['submissionId'], isset($currectOrder['TUTORCOMMENT']) ? $row[$currectOrder['TUTORCOMMENT']] : null, isset($currectOrder['OUTSTANDING']) ? $row[$currectOrder['OUTSTANDING']] : null, isset($currectOrder['STATUS']) ? $row[$currectOrder['STATUS']] : null, $points, time(), $file == null ? 1 : 0);
                         $marking->setFile($file);
                         /*array(
                           'id' => ($markingId<0 ? null : $markingId),
                           'points' => $points,
                           'outstanding' => isset($currectOrder['OUTSTANDING']) ? $row[$currectOrder['OUTSTANDING']] : null,
                           'tutorId' => $userid,
                           'tutorComment' => isset($currectOrder['TUTORCOMMENT']) ? $row[$currectOrder['TUTORCOMMENT']] : null,
                           'file' => $file,
                           'status' => isset($currectOrder['STATUS']) ? $row[$currectOrder['STATUS']] : null,
                           'date' => time(),
                           'hideFile' => 
                           );*/
                         $markings[] = $marking;
                     } else {
                         //if file with this markingid not exists
                         $errors[] = 'File does not exist: ' . $markingFile;
                         fclose($csv);
                         $this->deleteDir($tempDir);
                         $this->app->response->setStatus(409);
                         $this->app->response->setBody(json_encode($errors));
                         $this->app->stop();
                     }
                 }
             }
             $mark = @json_encode($markings);
             if ($mark !== false) {
                 ///echo json_encode($markings); return;
                 //request to database to edit the markings
                 $result = Request::routeRequest('POST', '/marking', array(), $mark, $this->_postMarking, 'marking');
                 /// TODO: prüfen ob jede hochgeladen wurde
                 if ($result['status'] != 201) {
                     $errors[] = 'send markings failed';
                 }
             } else {
                 $errors[] = 'invalid input';
             }
         } else {
             $errors[] = 'no transaction data';
         }
         fclose($csv);
     } else {
         // if csv file does not exist
         $errors[] = '.csv file does not exist in uploaded zip-Archiv';
     }
     $this->deleteDir($tempDir);
     $this->app->response->setBody(json_encode($errors));
     if (!($errors == array())) {
         $this->app->response->setStatus(409);
     }
 }
コード例 #7
0
ファイル: AssignManually.php プロジェクト: sawh/ostepu-system
                     // move assignment from tutor to tutor
                     $marking = new Marking();
                     $marking->setId($markingId);
                     $marking->setTutorId($selectedTutorID);
                     $markings[] = $marking;
                 }
             }
         }
     }
     // "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);
コード例 #8
0
ファイル: Process.php プロジェクト: sawh/ostepu-system
 /**
  * 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;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #9
0
ファイル: LGetSite.php プロジェクト: sawh/ostepu-system
 /**
  * Function that handles all requests for marking tool.
  * Used by the functions that are called by Slim when data for the marking
  * tool is requested
  *
  * @author Florian Lücke
  */
 public function markingToolBase($userid, $courseid, $sheetid, $tutorid, $statusid, $shouldfilter, $selector)
 {
     $response = array();
     //Get neccessary data
     $URL = "{$this->lURL}/exercisesheet/course/{$courseid}/exercise";
     $handler1 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getMarking->getAddress()}/marking/exercisesheet/{$sheetid}";
     $handler2 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getUser->getAddress()}/user/course/{$courseid}/status/1";
     $handler3 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getGroup->getAddress()}/group/exercisesheet/{$sheetid}";
     $handler4 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getSubmission->getAddress()}/submission/exercisesheet/{$sheetid}/selected";
     $handler5 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = $this->_getExerciseType->getAddress() . '/exercisetype';
     $handler6 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getUser->getAddress()}/user/course/{$courseid}/status/2";
     $handler7 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = "{$this->_getUser->getAddress()}/user/course/{$courseid}/status/3";
     $handler8 = Request_CreateRequest::createGet($URL, array(), '');
     $multiRequestHandle = new Request_MultiRequest();
     $multiRequestHandle->addRequest($handler1);
     $multiRequestHandle->addRequest($handler2);
     $multiRequestHandle->addRequest($handler3);
     $multiRequestHandle->addRequest($handler4);
     $multiRequestHandle->addRequest($handler5);
     $multiRequestHandle->addRequest($handler6);
     $multiRequestHandle->addRequest($handler7);
     $multiRequestHandle->addRequest($handler8);
     $answer = $multiRequestHandle->run();
     $sheets = json_decode($answer[0]['content'], true);
     $markings = json_decode($answer[1]['content'], true);
     $tutors = json_decode($answer[2]['content'], true);
     $groups = json_decode($answer[3]['content'], true);
     $submissions = json_decode($answer[4]['content'], true);
     $possibleExerciseTypes = json_decode($answer[5]['content'], true);
     $tutors = array_merge($tutors, json_decode($answer[6]['content'], true));
     $tutors = array_merge($tutors, json_decode($answer[7]['content'], true));
     // order exercise types by id
     $exerciseTypes = array();
     foreach ($possibleExerciseTypes as $exerciseType) {
         $exerciseTypes[$exerciseType['id']] = $exerciseType;
     }
     $namesOfExercises = array();
     // find the current sheet and it's exercises
     foreach ($sheets as &$sheet) {
         $thisSheetId = $sheet['id'];
         if ($thisSheetId == $sheetid) {
             $thisExerciseSheet = $sheet;
             // create exercise names
             //an array to descripe the subtasks
             $alphabet = range('a', 'z');
             $count = 0;
             $count = null;
             if (isset($sheet['exercises'])) {
                 $exercises = $sheet['exercises'];
                 foreach ($exercises as $key => $exercise) {
                     $exerciseId = $exercise['id'];
                     if ($count === null || $exercises[$count]['link'] != $exercise['link']) {
                         $count = $key;
                         $namesOfExercises[$exerciseId] = $exercise['link'];
                         $subtask = 0;
                     } else {
                         $subtask++;
                         $namesOfExercises[$exerciseId] = $exercise['link'] . $alphabet[$subtask];
                         $namesOfExercises[$exercises[$count]['id']] = $exercises[$count]['link'] . $alphabet[0];
                     }
                 }
             }
         }
         unset($sheet['exercises']);
     }
     if (isset($thisExerciseSheet) == false) {
         $this->app->halt(404, '{"code":404,reason":"invalid sheet id"}');
     }
     // save the index of each exercise and add exercise type name
     $exercises = array();
     $exerciseIndices = array();
     foreach ($thisExerciseSheet['exercises'] as $idx => $exercise) {
         $exerciseId = $exercise['id'];
         $typeId = $exercise['type'];
         if (isset($exerciseTypes[$typeId])) {
             $type = $exerciseTypes[$typeId];
             $exercise['typeName'] = $type['name'];
         } else {
             $exercise['typeName'] = "unknown";
         }
         $exerciseIndices[$exerciseId] = $idx;
         $exercises[] = $exercise;
     }
     // save a reference to each user's group and add exercises to each group
     $userGroups = array();
     foreach ($groups as &$group) {
         $leaderId = $group['leader']['id'];
         $userGroups[$leaderId] =& $group;
         if (isset($group['members'])) {
             foreach ($group['members'] as $member) {
                 $memberId = $member['id'];
                 $userGroups[$memberId] =& $group;
             }
         }
         $group['exercises'] = $exercises;
     }
     foreach ($markings as $key => $marking) {
         $markings[$key]['submissionId'] = $markings[$key]['submission']['id'];
     }
     foreach ($submissions as $submission) {
         $studentId = $submission['studentId'];
         $exerciseId = $submission['exerciseId'];
         $exerciseIndex = $exerciseIndices[$exerciseId];
         $group =& $userGroups[$studentId];
         $group['exercises'][$exerciseIndex]['submission'] = $submission;
     }
     $filteredGroups = array();
     foreach ($submissions as $submission) {
         $marking = LArraySorter::multidimensional_search($markings, array('submissionId' => $submission['id']));
         if ($marking !== false) {
             unset($markings[$marking]['submission']);
             $submission['marking'] = $markings[$marking];
         }
         // filter out markings by the tutor with id $tutorid
         if ($shouldfilter == false || $selector($submission, $tutorid, $statusid)) {
             //echo json_encode($submission);
             $exerciseId = $submission['exerciseId'];
             $exerciseIndex = $exerciseIndices[$exerciseId];
             $studentId = $submission['studentId'];
             // assign the submission to its group
             $group =& $userGroups[$studentId];
             $groupExercises =& $group['exercises'];
             $groupExercises[$exerciseIndex]['submission'] = $submission;
             $leaderId =& $group['leader']['id'];
             $filteredGroups[$leaderId] =& $group;
         } else {
             $exerciseId = $submission['exerciseId'];
             $exerciseIndex = $exerciseIndices[$exerciseId];
             $studentId = $submission['studentId'];
             $group =& $userGroups[$studentId];
             $groupExercises =& $group['exercises'];
             unset($groupExercises[$exerciseIndex]);
         }
     }
     if ($statusid === '0') {
         // remove groups with submissions
         $tempGroups = array();
         foreach ($groups as $key => $group) {
             $temp2Groups = array();
             foreach ($group['exercises'] as $key2 => $exercise) {
                 if (!isset($exercise['submission']) || isset($exercise['submission']['marking']['status']) && $exercise['submission']['marking']['status'] === '0') {
                     $temp2Groups[] = $exercise;
                 }
             }
             if (!empty($temp2Groups)) {
                 $group['exercises'] = $temp2Groups;
                 $tempGroups[] = $group;
             }
         }
         $groups = $tempGroups;
     }
     $response['groups'] = $shouldfilter == true && $statusid !== '0' ? array_values($filteredGroups) : $groups;
     $response['tutors'] = $tutors;
     $response['exerciseSheets'] = $sheets;
     $response['markingStatus'] = Marking::getStatusDefinition();
     $response['namesOfExercises'] = $namesOfExercises;
     $this->flag = 1;
     $response['user'] = $this->userWithCourse($userid, $courseid);
     $this->app->response->setBody(json_encode($response));
 }
コード例 #10
0
ファイル: Marking.php プロジェクト: sawh/ostepu-system
 public static function ExtractMarking($data, $singleResult = false, $FileExtension = '', $File2Extension = '', $SubmissionExtension = '', $MarkingExtension = '', $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 files by using a defined list of
     // its attributes
     $files2 = DBJson::getObjectsByAttributes($data, File::getDBPrimaryKey(), File::getDBConvert(), $File2Extension . '2');
     // generates an assoc array of a submission by using a defined
     // list of its attributes
     $submissions = DBJson::getObjectsByAttributes($data, Submission::getDBPrimaryKey(), Submission::getDBConvert(), $SubmissionExtension . '2');
     // concatenates the submissions and the associated files
     $submissions = DBJson::concatObjectListsSingleResult($data, $submissions, Submission::getDBPrimaryKey(), Submission::getDBConvert()['S_file'], $files2, File::getDBPrimaryKey(), $File2Extension . '2', $SubmissionExtension . '2');
     // 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']);
             }
         }
     }
     // generates an assoc array of markings by using a defined list of
     // its attributes
     $markings = DBJson::getObjectsByAttributes($data, Marking::getDBPrimaryKey(), Marking::getDBConvert(), $MarkingExtension);
     // concatenates the markings and the associated files
     $res = DBJson::concatObjectListsSingleResult($data, $markings, Marking::getDBPrimaryKey(), Marking::getDBConvert()['M_file'], $files, File::getDBPrimaryKey(), $FileExtension, $MarkingExtension);
     // concatenates the markings and the associated submissions
     $res = DBJson::concatObjectListsSingleResult($data, $res, Marking::getDBPrimaryKey(), Marking::getDBConvert()['M_submission'], $submissions, Submission::getDBPrimaryKey(), $SubmissionExtension . '2', $MarkingExtension);
     if ($isResult) {
         // to reindex
         $res = array_values($res);
         $res = Marking::decodeMarking($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
コード例 #11
0
ファイル: Helpers.php プロジェクト: sawh/ostepu-system
/**
 * 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;
        }
    }
}
コード例 #12
0
ファイル: DBMarking.php プロジェクト: sawh/ostepu-system
 public function get($functionName, $linkName, $params = array(), $checkSession = true)
 {
     $positive = function ($input) {
         //$input = $input[count($input)-1];
         $result = Model::isEmpty();
         $result['content'] = array();
         foreach ($input as $inp) {
             if ($inp->getNumRows() > 0) {
                 // extract Marking data from db answer
                 $res = Marking::ExtractMarking($inp->getResponse(), false);
                 $result['content'] = array_merge($result['content'], is_array($res) ? $res : array($res));
                 $result['status'] = 200;
             }
         }
         return $result;
     };
     $params = DBJson::mysql_real_escape_string($params);
     return $this->_component->call($linkName, $params, '', 200, $positive, array(), 'Model::isProblem', array(), 'Query');
 }