本文整理汇总了PHP中Attachment::decodeAttachment方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachment::decodeAttachment方法的具体用法?PHP Attachment::decodeAttachment怎么用?PHP Attachment::decodeAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachment
的用法示例。
在下文中一共展示了Attachment::decodeAttachment方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
}
//.........这里部分代码省略.........
示例2: 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.
*
* @param int $pre A optional prefix for the attachment table.
*/
public function addAttachment($pre = '')
{
$this->loadConfig($pre);
$pre = ($pre === '' ? '' : '_') . $pre;
Logger::Log('starts POST AddAttachment', LogLevel::DEBUG);
// decode the received attachment data, as an object
$insert = Attachment::decodeAttachment($this->_app->request->getBody());
// always been an array
$arr = true;
if (!is_array($insert)) {
$insert = array($insert);
$arr = false;
}
$pre = DBJson::mysql_real_escape_string($pre);
// this array contains the indices of the inserted objects
$res = array();
foreach ($insert as $in) {
// generates the insert data for the object
$data = $in->getInsertData();
// starts a query, by using a given file
$result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/AddAttachment.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 Attachment();
$course = Course::ExtractCourse($queryResult[count($queryResult) - 1]->getResponse(), true);
$obj->setId($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 AddAttachment failed', LogLevel::ERROR);
$this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
$this->_app->response->setBody(Attachment::encodeAttachment($res));
$this->_app->stop();
}
}
if (!$arr && count($res) == 1) {
$this->_app->response->setBody(Attachment::encodeAttachment($res[0]));
} else {
$this->_app->response->setBody(Attachment::encodeAttachment($res));
}
}
示例3: 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()
{
Logger::Log('starts POST AddAttachment', LogLevel::DEBUG);
// decode the received attachment data, as an object
$insert = Attachment::decodeAttachment($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) {
// generates the insert data for the object
$data = $in->getInsertData();
// starts a query, by using a given file
$result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/AddAttachment.sql', array('values' => $data));
// 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 Attachment();
$obj->setId($queryResult->getInsertId());
$obj->setStatus(201);
$res[] = $obj;
if (isset($result['headers']['Content-Type'])) {
$this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
}
} else {
$obj = new Attachment();
$obj->setStatus(409);
$res[] = $obj;
/* Logger::Log(
'POST AddAttachment failed',
LogLevel::ERROR
);*/
/// $this->_app->response->setStatus( isset( $result['status'] ) ? $result['status'] : 409 );
// $this->_app->response->setBody( Attachment::encodeAttachment( $res ) );
// $this->_app->stop( );
}
}
if (!$arr && count($res) == 1) {
$this->_app->response->setBody(Attachment::encodeAttachment($res[0]));
} else {
$this->_app->response->setBody(Attachment::encodeAttachment($res));
}
$this->_app->response->setStatus(201);
}
示例4: ExtractAttachment
public static function ExtractAttachment($data, $singleResult = false, $FileExtension = '', $AttachmentExtension = '', $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 attachments by using a defined list of
// its attributes
$attachments = DBJson::getObjectsByAttributes($data, Attachment::getDBPrimaryKey(), Attachment::getDBConvert(), $AttachmentExtension);
// concatenates the attachments and the associated files
$res = DBJson::concatObjectListsSingleResult($data, $attachments, Attachment::getDBPrimaryKey(), Attachment::getDBConvert()['F_file'], $files, File::getDBPrimaryKey(), $FileExtension, $AttachmentExtension);
if ($isResult) {
// to reindex
$res = array_values($res);
$res = Attachment::decodeAttachment($res, false);
if ($singleResult == true) {
// only one object as result
if (count($res) > 0) {
$res = $res[0];
}
}
}
return $res;
}
示例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);
}
示例6: __construct
/**
* 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;
}
}
}
}
}
}
}
}
}
}
}