本文整理汇总了PHP中Process::decodeProcess方法的典型用法代码示例。如果您正苦于以下问题:PHP Process::decodeProcess方法的具体用法?PHP Process::decodeProcess怎么用?PHP Process::decodeProcess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Process
的用法示例。
在下文中一共展示了Process::decodeProcess方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postProcess
/**
* 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()) {
//.........这里部分代码省略.........
示例2: postProcess
/**
* Processes a process
*
* Called when this component receives an HTTP POST request to
* /process(/).
*/
public function postProcess()
{
$this->app->response->setStatus(201);
$header = $this->app->request->headers->all();
$body = $this->app->request->getBody();
$process = Process::decodeProcess($body);
// always been an array
$arr = true;
if (!is_array($process)) {
$process = array($process);
$arr = false;
}
// this array contains the indices of the inserted objects
$res = array();
foreach ($process as $pro) {
$eid = $pro->getExercise()->getId();
// loads the form from database
$result = Request::routeRequest('GET', '/form/exercise/' . $eid, $this->app->request->headers->all(), '', $this->_formDb, 'form');
// checks the correctness of the query
if ($result['status'] >= 200 && $result['status'] <= 299) {
// only one form as result
$forms = Form::decodeForm($result['content']);
$forms = $forms[0];
$formdata = $pro->getRawSubmission()->getFile();
$timestamp = $formdata->getTimeStamp();
if ($timestamp === null) {
$timestamp = time();
}
if ($formdata !== null && $forms !== null) {
$formdata = Form::decodeForm($formdata->getBody(true));
if (is_array($formdata)) {
$formdata = $formdata[0];
}
if ($formdata !== null) {
// check the submission
$fail = false;
$parameter = explode(' ', strtolower($pro->getParameter()));
$choices = $formdata->getChoices();
if ($forms->getType() == 0) {
foreach ($choices as &$choice) {
$i = 0;
for ($i < 0; $i < count($parameter); $i++) {
$param = $parameter[$i];
if ($param === null || $param === '') {
continue;
}
switch ($param) {
case 'isnumeric':
if (!@preg_match("%^-?([0-9])+([,]([0-9])+)?\$%", DefaultNormalizer::normalizeText($choice->getText()))) {
$fail = true;
$pro->addMessage('"' . $choice->getText() . '" ist keine gültige Zahl. <br>Bsp.: -0,00');
}
break;
case 'isdigit':
if (!ctype_digit(DefaultNormalizer::normalizeText($choice->getText()))) {
$fail = true;
$pro->addMessage('"' . $choice->getText() . '" ist keine gültige Ziffernfolge.');
}
break;
case 'isprintable':
if (!ctype_print(DefaultNormalizer::normalizeText($choice->getText()))) {
$fail = true;
$pro->addMessage('"' . $choice->getText() . '" enthält nicht-druckbare Zeichen.');
}
break;
case 'isalpha':
if (!ctype_alpha(DefaultNormalizer::normalizeText($choice->getText()))) {
$fail = true;
$pro->addMessage('"' . $choice->getText() . '" ist keine gültige Buchstabenfolge.');
}
break;
case 'isalphanum':
if (!ctype_alnum(DefaultNormalizer::normalizeText($choice->getText()))) {
$fail = true;
$pro->addMessage('"' . $choice->getText() . '" ist nicht alphanumerisch.');
}
break;
case 'ishex':
if (!ctype_xdigit(DefaultNormalizer::normalizeText($choice->getText()))) {
$fail = true;
$pro->addMessage('"' . $choice->getText() . '" ist keine gültige Hexadezimalzahl.');
}
break;
default:
$test = $parameter[$i];
$i++;
while ($i < count($parameter)) {
if (@preg_match($test, DefaultNormalizer::normalizeText($choice->getText())) !== false) {
break;
}
$test .= ' ' . $parameter[$i];
$i++;
}
$match = @preg_match($test, DefaultNormalizer::normalizeText($choice->getText()));
//.........这里部分代码省略.........
示例3: postSubmission
/**
* 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) {
//.........这里部分代码省略.........
示例4: postProcess
/**
* Processes a process
*
* Called when this component receives an HTTP POST request to
* /process(/).
*/
public function postProcess()
{
// hier werden Einsendungen verarbeitet
$this->app->response->setStatus(201);
$body = $this->app->request->getBody();
$process = Process::decodeProcess($body);
// always been an array
// es ist einfacher, wenn man sicherstellt, dass die Eingabedaten als Liste für foreach verarbeitet
// werden können, um Abstürze bei übergebenen Einzelobjekten zu vermeiden
$arr = true;
if (!is_array($process)) {
$process = array($process);
$arr = false;
}
$res = array();
// behandelt jede eingehende Einsendung
foreach ($process as $pro) {
$eid = $pro->getExercise()->getId();
$file = $pro->getRawSubmission()->getFile();
// die unverarbeitete Einsendung (Dateiinhalt im body oder Adresse)
$timestamp = $file->getTimeStamp();
// der Eingangsstempel müsste natürlich schon existieren, ansonsten gilt dieser als Eingangszeitpunkt (wird nicht verwendet)
if ($timestamp === null) {
$timestamp = time();
}
// es muss eine Einsendung vorhanden sein, welche bearbeitet werden kann
if ($file !== null) {
$fileName = $file->getDisplayName();
$file = $file->getBody(true);
// gibt den Inhalt der Einsendung an $file
// es muss ein Einsendungsinhalt vorhanden sein
if ($file !== null) {
$fail = false;
// eindeutigen temporären Ordner für diesen Vorgang erstellen und den Inhalt dort platzieren
$fileHash = sha1($file);
$filePath = $this->tempdir('/tmp/', $fileHash);
file_put_contents($filePath . '/' . $fileName, $file);
// der $pro->getParameter() wurden beim Erstellen der Verarbeitung festgelegt und enthält
// sowohl den aufzurufenden Compiler als auch weitere Aufrufparameter
$parameter = explode(' ', strtolower($pro->getParameter()));
if (count($parameter) >= 2) {
$type = array_shift($parameter);
if ($type == 'cx') {
// behandelt Einsendungen für den cx Compiler
$output = array();
$return = '';
// ersetzt $file durch den Dateinamen der Einsendung und generiert
// die zusätzlichen Aufrufparameter für den Compiler
$param = implode(' ', $parameter);
if ($param != '') {
$param = str_replace('$file', $fileName, $param);
} else {
$param = $fileName;
}
// passt das Arbeitsverzeichnis an und führt das Skript für den
// cx Compiler aus
$pathOld = getcwd();
chdir($filePath);
exec('(./start_cx ' . $param . ') 2>&1', $output, $return);
chdir($pathOld);
if (count($output) > 0 && $output[count($output) - 1] === '201') {
// wenn wir als Antwort eine 201 vom Skript erhalten, konnte alles problemlos
// kompiliert werden
$pro->setStatus(201);
} else {
// ansonsten gab es ein Problem, also einen Fehlerstatus zurückgeben
$pro->setStatus(409);
// die Antwort des Compilers wird nun noch für die Ausgabe der Fehlermeldung angepasst
if (count($output) > 0) {
$text = '';
unset($output[count($output) - 1]);
foreach ($output as $out) {
$pos = strpos($out, ',');
$text .= $out . "\n";
}
$pro->addMessage($text);
}
$this->app->response->setStatus(409);
}
} elseif ($type == 'java') {
// behandelt Einsendungen für den Java Compiler
$output = array();
$return = '';
// ersetzt $file durch den Dateinamen der Einsendung und generiert
// die zusätzlichen Aufrufparameter für den Compiler
$param = implode(' ', $parameter);
if ($param != '') {
$param = str_replace('$file', $fileName, $param);
} else {
$param = $fileName;
}
// passt das Arbeitsverzeichnis an und führt das Skript für den
// java Compiler (javac) aus. Die Ausgabe erfolgt dabei in $return
$pathOld = getcwd();
//.........这里部分代码省略.........
示例5: addProcess
/**
* Adds a process.
*
* Called when this component receives an HTTP POST request to
* (/$pre)/process(/).
*
* @param int $pre A optional prefix for the process table.
*/
public function addProcess($pre = '')
{
$this->loadConfig($pre);
$pre = ($pre === '' ? '' : '_') . $pre;
Logger::Log('starts POST AddProcess', LogLevel::DEBUG);
// decode the received choice data, as an object
$insert = Process::decodeProcess($this->_app->request->getBody());
// always been an array
$arr = true;
if (!is_array($insert)) {
$insert = array($insert);
$arr = false;
}
// this array contains the indices of the inserted objects
$res = array();
foreach ($insert as $in) {
// starts a query, by using a given file
$result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/AddProcess.sql', array('object' => $in, 'pre' => $pre));
// checks the correctness of the query
if ($result['status'] >= 200 && $result['status'] <= 299) {
$queryResult = Query::decodeQuery($result['content']);
// sets the new auto-increment id
$obj = new Process();
$course = Course::ExtractCourse($queryResult[count($queryResult) - 1]->getResponse(), true);
$obj->setProcessId($course->getId() . '_' . $queryResult[count($queryResult) - 2]->getInsertId());
$res[] = $obj;
$this->_app->response->setStatus(201);
if (isset($result['headers']['Content-Type'])) {
$this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
}
} else {
Logger::Log('POST AddProcess failed', LogLevel::ERROR);
$this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
$this->_app->response->setBody(Process::encodeProcess($res));
$this->_app->stop();
}
}
if (!$arr && count($res) == 1) {
$this->_app->response->setBody(Process::encodeProcess($res[0]));
} else {
$this->_app->response->setBody(Process::encodeProcess($res));
}
}
示例6: http_get
}
return null;
}
if (!isset($sid)) {
$sid = null;
}
if (!isset($cid)) {
$cid = null;
}
// load user data from the database
$URL = $getSiteURI . "/createsheet/user/{$uid}/course/{$cid}";
$createsheetData = http_get($URL, true);
$createsheetData = json_decode($createsheetData, true);
$noContent = false;
$result = http_get($serverURI . "/DB/DBProcess/processList/process/course/{$cid}", true);
$processorModules = Process::decodeProcess($result);
if (!is_array($processorModules)) {
$processorModules = array($processorModules);
}
$components = array();
foreach ($processorModules as $processor) {
$components[] = $processor->getTarget();
}
$processorModules = array('processors' => $components);
$exerciseTypes = array();
if (isset($createsheetData['exerciseTypes'])) {
$exerciseTypes = array('exerciseTypes' => $createsheetData['exerciseTypes']);
$_SESSION['JSCACHE'] = json_encode($exerciseTypes['exerciseTypes']);
} else {
$_SESSION['JSCACHE'] = "";
$errormsg = Language::Get('main', 'missingExerciseTypes', $langTemplate);
示例7: json_decode
if (isset($_SESSION['JSCACHE'])) {
$cache = json_decode($_SESSION['JSCACHE'], true);
foreach ($cache as $excercisetype) {
$cid = $excercisetype['courseId'];
break;
}
}
}
if (!isset($processors)) {
if ($cid !== null) {
$result = Request::get($serverURI . '/DB/DBProcess/processList/process/course/' . $cid, array(), '');
} else {
$result['status'] = 409;
}
if ($result['status'] >= 200 && $result['status'] <= 299) {
$processors = Process::decodeProcess($result['content']);
if (!is_array($processors)) {
$processors = array($processors);
}
$components = array();
foreach ($processors as $processor) {
$components[] = $processor->getTarget();
}
} else {
}
} else {
if (!is_array($processors)) {
$processors = array($processors);
}
$components = $processors;
}
示例8: ExtractProcess
public static function ExtractProcess($data, $singleResult = false, $ProcessExtension = '', $ComponentExtension = '', $ExerciseExtension = '', $isResult = true)
{
// generates an assoc array of processes by using a defined list of
// its attributes
$process = DBJson::getObjectsByAttributes($data, Process::getDBPrimaryKey(), Process::getDBConvert(), $ProcessExtension);
// generates an assoc array of components by using a defined
// list of its attributes
$component = DBJson::getObjectsByAttributes($data, Component::getDBPrimaryKey(), Component::getDBConvert(), $ComponentExtension);
// generates an assoc array of exercises by using a defined
// list of its attributes
$exercise = DBJson::getObjectsByAttributes($data, Exercise::getDBPrimaryKey(), Exercise::getDBConvert(), $ExerciseExtension);
$attachment = Attachment::extractAttachment($data, false, '_PRO1', '_PRO1', false);
$workFiles = Attachment::extractAttachment($data, false, '_PRO2', '_PRO2', false);
// concatenates the processes and the associated attachments
$process = DBJson::concatObjectListResult($data, $process, Process::getDBPrimaryKey(), Process::getDBConvert()['A_attachment'], $attachment, Attachment::getDBPrimaryKey(), '_PRO1', $ProcessExtension);
// concatenates the processes and the associated attachments
$process = DBJson::concatObjectListResult($data, $process, Process::getDBPrimaryKey(), Process::getDBConvert()['A_workFiles'], $workFiles, Attachment::getDBPrimaryKey(), '_PRO2', $ProcessExtension);
// concatenates the processes and the associated components
$process = DBJson::concatObjectListsSingleResult($data, $process, Process::getDBPrimaryKey(), Process::getDBConvert()['E_exercise'], $exercise, Exercise::getDBPrimaryKey(), $ExerciseExtension, $ProcessExtension);
$res = DBJson::concatObjectListsSingleResult($data, $process, Process::getDBPrimaryKey(), Process::getDBConvert()['CO_target'], $component, Component::getDBPrimaryKey(), $ComponentExtension, $ProcessExtension);
if ($isResult) {
// to reindex
$res = array_values($res);
$res = Process::decodeProcess($res, false);
if ($singleResult == true) {
// only one object as result
if (count($res) > 0) {
$res = $res[0];
}
}
}
return $res;
}