本文整理汇总了PHP中Exercise::encodeExercise方法的典型用法代码示例。如果您正苦于以下问题:PHP Exercise::encodeExercise方法的具体用法?PHP Exercise::encodeExercise怎么用?PHP Exercise::encodeExercise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exercise
的用法示例。
在下文中一共展示了Exercise::encodeExercise方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: isset
}
}
}
$sheetId = isset($_POST['sheetId']) ? $_POST['sheetId'] : (isset($sid) ? $sid : null);
$URL = $databaseURI . "/exercisefiletype/exercisesheet/{$sheetId}";
$removed = http_delete($URL, true);
$exerciseMap = array();
foreach ($exercises as $key => &$exercise) {
$exercise->setSheetId($sheetId);
$exerciseMap[$key] = array($key, $exercise->getId());
if ($exercise->getId() < 0) {
$exercise->setId(null);
}
}
// Post Excercise to logic Controller to create it
$exercisesJSON = Exercise::encodeExercise($exercises);
///echo $exercisesJSON;
$output2 = http_post_data($logicURI . "/exercise", $exercisesJSON, true, $message);
if ($message == 201) {
$exercises2 = Exercise::decodeExercise($output2);
foreach ($exercises2 as $key => &$exercise2) {
if ($exercises[$key]->getId() !== null) {
$exerciseMap[$key][] = $exercises[$key]->getId();
} else {
$exerciseMap[$key][] = $exercise2->getId();
}
if ($exercise2->getId() !== null) {
$exercises[$key]->setId($exercise2->getId());
}
}
#region create_forms