-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #683 from oat-sa/release-5.51.0
Release 5.51.0
- Loading branch information
Showing
33 changed files
with
1,834 additions
and
1,076 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,21 @@ | |
|
||
use oat\taoQtiTest\models\tasks\ImportQtiTest; | ||
use oat\oatbox\task\Task; | ||
use oat\tao\model\TaskQueueActionTrait; | ||
|
||
/** | ||
* | ||
* @author Absar Gilani & Rashid - PCG Team - {[email protected]} | ||
*/ | ||
class taoQtiTest_actions_RestQtiTests extends \tao_actions_TaskQueue | ||
class taoQtiTest_actions_RestQtiTests extends \tao_actions_RestController | ||
{ | ||
use TaskQueueActionTrait { | ||
getTask as parentGetTask; | ||
getTaskData as traitGetTaskData; | ||
} | ||
|
||
const TASK_ID_PARAM = 'id'; | ||
|
||
private static $accepted_types = array( | ||
'application/zip', | ||
'application/x-zip-compressed', | ||
|
@@ -36,12 +44,58 @@ public function index() | |
{ | ||
$this->returnFailure(new \common_exception_NotImplemented('This API does not support this call.')); | ||
} | ||
|
||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
// The service that implements or inherits get/getAll/getRootClass ... for that particular type of resources | ||
$this->service = taoQtiTest_models_classes_CrudQtiTestsService::singleton(); | ||
} | ||
|
||
/** | ||
* Import file entry point by using $this->service | ||
* Check POST method & get valid uploaded file | ||
*/ | ||
public function import() | ||
{ | ||
$fileUploadName = "qtiPackage"; | ||
if ($this->getRequestMethod() != Request::HTTP_POST) { | ||
throw new \common_exception_NotImplemented('Only post method is accepted to import Qti package.'); | ||
} | ||
if(tao_helpers_Http::hasUploadedFile($fileUploadName)) { | ||
$file = tao_helpers_Http::getUploadedFile($fileUploadName); | ||
$mimeType = tao_helpers_File::getMimeType($file['tmp_name']); | ||
if (!in_array($mimeType, self::$accepted_types)) { | ||
$this->returnFailure(new common_exception_BadRequest()); | ||
} else { | ||
$report = $this->service->importQtiTest($file['tmp_name']); | ||
if ($report->getType() === common_report_Report::TYPE_SUCCESS) { | ||
$data = array(); | ||
foreach ($report as $r) { | ||
$values = $r->getData(); | ||
$testid = $values->rdfsResource->getUri(); | ||
foreach ($values->items as $item) { | ||
$itemsid[] = $item->getUri(); | ||
} | ||
$data[] = array( | ||
'testId' => $testid, | ||
'testItems' => $itemsid); | ||
} | ||
return $this->returnSuccess($data); | ||
} else { | ||
return $this->returnFailure(new common_exception_InconsistentData($report->getMessage())); | ||
} | ||
} | ||
} else { | ||
return $this->returnFailure(new common_exception_BadRequest()); | ||
} | ||
} | ||
|
||
/** | ||
* Import test package through the task queue. | ||
* Check POST method & get valid uploaded file | ||
*/ | ||
public function importDeferred() | ||
{ | ||
$fileUploadName = "qtiPackage"; | ||
if ($this->getRequestMethod() != Request::HTTP_POST) { | ||
|
@@ -89,14 +143,32 @@ public function getStatus() | |
} | ||
} | ||
|
||
/** | ||
* @param $taskId | ||
* @return array | ||
*/ | ||
protected function getTaskData($taskId) | ||
{ | ||
$data = $this->traitGetTaskData($taskId); | ||
$task = $this->getTask($taskId); | ||
$report = \common_report_Report::jsonUnserialize($task->getReport()); | ||
$plainReport = $this->getPlainReport($report); | ||
|
||
//the third report is report of import test | ||
if (isset($plainReport[2]) && isset($plainReport[2]->getData()['rdfsResource'])) { | ||
$data['testId'] = $plainReport[2]->getData()['rdfsResource']['uriResource']; | ||
} | ||
return $data; | ||
} | ||
|
||
/** | ||
* @param Task $taskId | ||
* @return Task | ||
* @throws common_exception_BadRequest | ||
*/ | ||
protected function getTask($taskId) | ||
{ | ||
$task = parent::getTask($taskId); | ||
$task = $this->parentGetTask($taskId); | ||
if ($task->getInvocable() !== 'oat\taoQtiTest\models\tasks\ImportQtiTest') { | ||
throw new \common_exception_BadRequest("Wrong task type"); | ||
} | ||
|
@@ -146,20 +218,4 @@ protected function getTaskReport(Task $task) | |
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* @param $report | ||
* @return array | ||
*/ | ||
private function getPlainReport($report) | ||
{ | ||
$result = []; | ||
$result[] = $report; | ||
if ($report->hasChildren()) { | ||
foreach ($report as $r) { | ||
$result = array_merge($result, $this->getPlainReport($r)); | ||
} | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.