当前位置: 首页>>代码示例>>PHP>>正文


PHP Attachment::encodeAttachment方法代码示例

本文整理汇总了PHP中Attachment::encodeAttachment方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachment::encodeAttachment方法的具体用法?PHP Attachment::encodeAttachment怎么用?PHP Attachment::encodeAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Attachment的用法示例。


在下文中一共展示了Attachment::encodeAttachment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addExercise

 /**
  * Adds an exercise.
  *
  * Called when this component receives an HTTP POST request to
  * /exercise(/).
  * The request body should contain a JSON object representing an array of exercises
  */
 public function addExercise()
 {
     $header = $this->app->request->headers->all();
     $body = json_decode($this->app->request->getBody(), true);
     $allright = true;
     $result = array();
     if (isset($body) == true && empty($body) == false) {
         foreach ($body as $subexercise) {
             // create exercise in DB
             $FileTypesArrayTemp = null;
             if (isset($subexercise['fileTypes'])) {
                 $FileTypesArrayTemp = $subexercise['fileTypes'];
                 unset($subexercise['fileTypes']);
             }
             $subexerciseJSON = json_encode($subexercise);
             $URL = $this->lURL . '/DB/exercise';
             $method = 'POST';
             if (isset($subexercise['id']) && $subexercise['id'] !== null) {
                 $method = 'PUT';
                 $URL = $this->lURL . '/DB/exercise/' . $subexercise['id'];
             }
             $subexerciseAnswer = Request::custom($method, $URL, $header, $subexerciseJSON);
             if ($subexerciseAnswer['status'] == 201) {
                 $subexerciseOutput = json_decode($subexerciseAnswer['content'], true);
                 if (isset($subexercise['id'])) {
                     $result[] = $subexercise;
                     $subexerciseOutput = $subexercise;
                 } else {
                     $result[] = Exercise::decodeExercise($subexerciseAnswer['content']);
                 }
                 if (isset($subexerciseOutput['id'])) {
                     $linkid = $subexerciseOutput['id'];
                 }
                 // create attachement in DB and FS
                 if (isset($subexercise['attachments']) && !empty($subexercise['attachments'])) {
                     foreach ($subexercise['attachments'] as &$attachment) {
                         $attachment['exerciseId'] = $linkid;
                     }
                     $attachments = $subexercise['attachments'];
                     $tempAttachments = array();
                     foreach ($attachments as $attachment) {
                         $temp = Attachment::createAttachment(null, $attachment['exerciseId'], null, null);
                         $temp->setFile($attachment);
                         $tempAttachments[] = $temp;
                     }
                     $res = Request::routeRequest('POST', '/attachment', $header, Attachment::encodeAttachment($tempAttachments), $this->_postAttachment, 'attachment');
                     // checks the correctness of the query
                     if ($res['status'] >= 200 && $res['status'] <= 299) {
                         // ...
                     } else {
                         $allright = false;
                         break;
                     }
                 }
                 // create ExerciseFileTypes
                 if (isset($FileTypesArrayTemp) && !empty($FileTypesArrayTemp)) {
                     foreach ($FileTypesArrayTemp as $fileType) {
                         $myExerciseFileType = ExerciseFileType::createExerciseFileType(NULL, $fileType['text'], $linkid);
                         $myExerciseFileTypeJSON = ExerciseFileType::encodeExerciseFileType($myExerciseFileType);
                         $URL = $this->lURL . "/DB/exercisefiletype";
                         $FileTypesAnswer = Request::custom('POST', $URL, $header, $myExerciseFileTypeJSON);
                         if ($FileTypesAnswer['status'] != 201) {
                             $allright = false;
                             break;
                         }
                     }
                 }
                 if ($allright == false) {
                     break;
                 }
             } else {
                 $allright = false;
                 break;
             }
         }
     }
     if ($allright == true) {
         $this->app->response->setBody(Exercise::encodeExercise($result));
         $this->app->response->setStatus(201);
     } else {
         $this->app->response->setStatus(409);
     }
 }
开发者ID:sawh,项目名称:ostepu-system,代码行数:90,代码来源:LExercise.php

示例2: AddProcess

 /**
  * Adds a process.
  *
  * Called when this component receives an HTTP POST request to
  * /process(/).
  */
 public function AddProcess()
 {
     $this->app->response->setStatus(201);
     $body = $this->app->request->getBody();
     $processes = Process::decodeProcess($body);
     // always been an array
     $arr = true;
     if (!is_array($processes)) {
         $processes = array($processes);
         $arr = false;
     }
     $res = array();
     foreach ($processes as $process) {
         // create process
         $method = 'POST';
         $URL = '/process';
         if ($process->getProcessId() !== null) {
             $method = 'PUT';
             $URL = '/process/' . $process->getProcessId();
         }
         $result = Request::routeRequest($method, $URL, array(), Process::encodeProcess($process), $this->_processorDb, 'process');
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $queryResult = Process::decodeProcess($result['content']);
             if ($process->getProcessId() === null) {
                 $process->setProcessId($queryResult->getProcessId());
             }
             $res[] = $process;
         } else {
             $res[] = null;
             $this->app->response->setStatus(409);
             continue;
         }
         // create attachment
         $attachments = $process->getAttachment();
         $process->setAttachment(array());
         foreach ($attachments as $attachment) {
             if ($attachment->getId() === null) {
                 $attachment->setExerciseId($process->getExercise()->getId());
                 $attachment->setProcessId($process->getProcessId());
                 // upload file
                 $result = Request::routeRequest('POST', '/file', array(), File::encodeFile($attachment->getFile()), $this->_file, 'file');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $queryResult = File::decodeFile($result['content']);
                     $attachment->setFile($queryResult);
                 } else {
                     $attachment->setFile(null);
                     $this->app->response->setStatus(409);
                     continue;
                 }
                 // upload attachment
                 $attachment->setProcessId($process->getProcessId());
                 $result = Request::routeRequest('POST', '/attachment', array(), Attachment::encodeAttachment($attachment), $this->_attachment, 'attachment');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $queryResult = Attachment::decodeAttachment($result['content']);
                     $attachment->setId($queryResult->getId());
                     $process->getAttachment()[] = $attachment;
                 } else {
                     $process->getAttachment()[] = null;
                     $this->app->response->setStatus(409);
                     continue;
                 }
             }
         }
         // create workFiles
         $workFiles = $process->getWorkFiles();
         $process->setWorkFiles(array());
         foreach ($workFiles as $workFile) {
             if ($workFile->getId() === null) {
                 $workFile->setExerciseId($process->getExercise()->getId());
                 $workFile->setProcessId($process->getProcessId());
                 // upload file
                 $result = Request::routeRequest('POST', '/file', array(), File::encodeFile($workFile->getFile()), $this->_file, 'file');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $queryResult = File::decodeFile($result['content']);
                     $workFile->setFile($queryResult);
                 } else {
                     $workFile->setFile(null);
                     $this->app->response->setStatus(409);
                     continue;
                 }
                 // upload attachment
                 $workFile->setProcessId($process->getProcessId());
                 $result = Request::routeRequest('POST', '/attachment', array(), Attachment::encodeAttachment($workFile), $this->_workFiles, 'attachment');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $queryResult = Attachment::decodeAttachment($result['content']);
                     $workFile->setId($queryResult->getId());
                     $process->getWorkFiles()[] = $workFile;
                 } else {
                     $process->getWorkFiles()[] = null;
                     $this->app->response->setStatus(409);
                     continue;
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:sawh,项目名称:ostepu-system,代码行数:101,代码来源:LProcessor.php

示例3: get

 public function get($functionName, $sqlFile, $userid, $courseid, $esid, $eid, $suid, $aid, $singleResult = false, $checkSession = true)
 {
     Logger::Log('starts GET ' . $functionName, LogLevel::DEBUG);
     // checks whether incoming data has the correct data type
     DBJson::checkInput($this->_app, $userid == '' ? true : ctype_digit($userid), $courseid == '' ? true : ctype_digit($courseid), $esid == '' ? true : ctype_digit($esid), $eid == '' ? true : ctype_digit($eid), $suid == '' ? true : ctype_digit($suid), $aid == '' ? true : ctype_digit($aid));
     // starts a query, by using a given file
     $result = DBRequest::getRoutedSqlFile($this->query, $sqlFile, array('userid' => $userid, 'courseid' => $courseid, 'esid' => $esid, 'eid' => $eid, 'suid' => $suid, 'aid' => $aid), $checkSession);
     // checks the correctness of the query
     if ($result['status'] >= 200 && $result['status'] <= 299) {
         $query = Query::decodeQuery($result['content']);
         if ($query->getNumRows() > 0) {
             $res = Attachment::ExtractAttachment($query->getResponse(), $singleResult);
             $this->_app->response->setBody(Attachment::encodeAttachment($res));
             $this->_app->response->setStatus(200);
             if (isset($result['headers']['Content-Type'])) {
                 $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
             $this->_app->stop();
         } else {
             $result['status'] = 404;
         }
     }
     Logger::Log('GET ' . $functionName . ' failed', LogLevel::ERROR);
     $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
     $this->_app->response->setBody(Attachment::encodeAttachment(new Attachment()));
     $this->_app->stop();
 }
开发者ID:sawh,项目名称:ostepu-system,代码行数:27,代码来源:DBAttachment.php

示例4: get

 public function get($functionName, $sqlFile, $pre = '', $userid, $courseid, $esid, $eid, $suid, $aid, $singleResult = false)
 {
     $this->loadConfig($pre);
     $pre = ($pre === '' ? '' : '_') . $pre;
     Logger::Log('starts GET ' . $functionName, LogLevel::DEBUG);
     $pre = DBJson::mysql_real_escape_string($pre);
     $userid = DBJson::mysql_real_escape_string($userid);
     $courseid = DBJson::mysql_real_escape_string($courseid);
     $esid = DBJson::mysql_real_escape_string($esid);
     $eid = DBJson::mysql_real_escape_string($eid);
     $suid = DBJson::mysql_real_escape_string($suid);
     $aid = DBJson::mysql_real_escape_string($aid);
     // starts a query, by using a given file
     $result = DBRequest::getRoutedSqlFile($this->query, $sqlFile, array('pre' => $pre, 'userid' => $userid, 'courseid' => $courseid, 'esid' => $esid, 'eid' => $eid, 'suid' => $suid, 'aid' => $aid));
     // checks the correctness of the query
     if ($result['status'] >= 200 && $result['status'] <= 299) {
         $query = Query::decodeQuery($result['content']);
         if (is_array($query)) {
             $query = $query[count($query) - 1];
         }
         if ($query->getNumRows() > 0) {
             $res = Attachment::ExtractAttachment($query->getResponse(), $singleResult);
             $this->_app->response->setBody(Attachment::encodeAttachment($res));
             $this->_app->response->setStatus(200);
             if (isset($result['headers']['Content-Type'])) {
                 $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
             $this->_app->stop();
         } else {
             $result['status'] = 404;
         }
     }
     Logger::Log('GET ' . $functionName . ' failed', LogLevel::ERROR);
     $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
     $this->_app->response->setBody(Attachment::encodeAttachment(new Attachment()));
     $this->_app->stop();
 }
开发者ID:sawh,项目名称:ostepu-system,代码行数:37,代码来源:DBAttachment2.php

示例5: addAttachment

 /**
  * Adds an attachment.
  *
  * Called when this component receives an HTTP POST request to
  * /attachment(/).
  * The request body should contain a JSON object representing the
  * attachment's attributes.
  */
 public function addAttachment()
 {
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $fileObjects = Attachment::decodeAttachment($body);
     // always been an array
     $arr = true;
     if (!is_array($fileObjects)) {
         $fileObjects = array($fileObjects);
         $arr = false;
     }
     $res = array();
     $files = array();
     foreach ($fileObjects as $fileObject) {
         $files[] = $fileObject->getFile();
     }
     //add the Files
     $result = Request::routeRequest('POST', '/file', array(), File::encodeFile($files), $this->_postFile, 'file');
     $tempFiles = File::decodeFile($result['content']);
     // checks the correctness of the query
     if ($result['status'] === 201 && isset($result['content'])) {
         // upload files
         $countObjects = count($fileObjects);
         for ($i = 0; $i < $countObjects; $i++) {
             if ($tempFiles[$i]->getStatus() === 201) {
                 $fileObjects[$i]->setFile($tempFiles[$i]);
                 if ($files[$i] !== null) {
                     $files[$i]->setStatus(201);
                 }
             } else {
                 $fileObjects[$i]->setStatus(409);
                 $fileObjects[$i]->addMessage("Die Datei konnte nicht gespeichert werden.");
                 if ($files[$i] !== null) {
                     $files[$i]->setBody();
                 }
             }
         }
     } else {
         $this->app->response->setStatus(409);
         $this->app->response->setBody(Attachment::encodeAttachment(new Attachment()));
         $this->app->stop();
     }
     // upload attachments
     $result = Request::routeRequest('POST', '/attachment', array(), Attachment::encodeAttachment($fileObjects), $this->_postAttachment, 'attachment');
     if ($result['status'] === 201 && isset($result['content'])) {
         $tempAttachments = Attachment::decodeAttachment($result['content']);
         $countObjects = count($fileObjects);
         for ($i = 0; $i < $countObjects; $i++) {
             $fileObjects[$i]->setStatus($tempAttachments[$i]->getStatus());
             $fileObjects[$i]->addMessages($tempAttachments[$i]->getMessages());
             if ($tempAttachments[$i]->getStatus() !== 201) {
                 $fileObjects[$i]->addMessage('Anhang konnte nicht erstellt werden.');
                 $fileObjects[$i]->getFile()->setBody();
             } else {
                 $fileObjects[$i]->setId($tempAttachments[$i]->getId());
             }
             $res[] = $fileObjects[$i];
         }
     } else {
         $this->app->response->setStatus(409);
         $this->app->response->setBody(Attachment::encodeAttachment(new Attachment()));
         $this->app->stop();
     }
     if (!$arr && count($res) == 1) {
         $res = $res[0];
     }
     $this->app->response->setBody(Attachment::encodeAttachment($res));
     $this->app->response->setStatus(201);
 }
开发者ID:sawh,项目名称:ostepu-system,代码行数:77,代码来源:LAttachment.php


注:本文中的Attachment::encodeAttachment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。