Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 38 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| TaskQueuePayload | |
0.00% |
0 / 38 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
| getPayload | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
12 | |||
| count | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| __construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Created by PhpStorm. |
| 5 | * User: christophe |
| 6 | * Date: 02/06/17 |
| 7 | * Time: 09:40 |
| 8 | */ |
| 9 | |
| 10 | namespace oat\oatbox\task\implementation; |
| 11 | |
| 12 | use oat\oatbox\task\Task; |
| 13 | use oat\oatbox\task\TaskInterface\TaskPayLoad; |
| 14 | use oat\oatbox\task\TaskInterface\TaskPersistenceInterface; |
| 15 | use oat\tao\model\datatable\DatatableRequest as DatatableRequestInterface; |
| 16 | use oat\tao\model\datatable\implementation\DatatableRequest; |
| 17 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 18 | |
| 19 | /** |
| 20 | * @deprecated since version 7.10.0, to be removed in 8.0. Use \oat\tao\model\taskQueue\TaskLog\DataTablePayload |
| 21 | * instead. |
| 22 | */ |
| 23 | class TaskQueuePayload implements TaskPayLoad |
| 24 | { |
| 25 | use ServiceLocatorAwareTrait; |
| 26 | |
| 27 | /** |
| 28 | * @var DatatableRequest |
| 29 | */ |
| 30 | protected $request; |
| 31 | |
| 32 | /** |
| 33 | * @var TaskPersistenceInterface |
| 34 | */ |
| 35 | protected $persistence; |
| 36 | |
| 37 | protected $currentUserId; |
| 38 | |
| 39 | public function getPayload() |
| 40 | { |
| 41 | |
| 42 | $params = $this->request->getFilters(); |
| 43 | |
| 44 | if (!empty($this->currentUserId)) { |
| 45 | $params['owner'] = $this->currentUserId; |
| 46 | } |
| 47 | |
| 48 | $page = $this->request->getPage(); |
| 49 | $rows = $this->request->getRows(); |
| 50 | |
| 51 | $sortBy = $this->request->getSortBy(); |
| 52 | $sortOrder = $this->request->getSortOrder(); |
| 53 | |
| 54 | $iterator = $this->persistence->search($params, $rows, $page, $sortBy, $sortOrder); |
| 55 | |
| 56 | $taskList = []; |
| 57 | |
| 58 | /** |
| 59 | * @var $taskData Task |
| 60 | */ |
| 61 | foreach ($iterator as $taskData) { |
| 62 | $taskList[] = |
| 63 | [ |
| 64 | "id" => $taskData->getId(), |
| 65 | "label" => $taskData->getLabel(), |
| 66 | "creationDate" => strtotime($taskData->getCreationDate()), |
| 67 | "status" => $taskData->getStatus(), |
| 68 | "report" => $taskData->getReport(), |
| 69 | ]; |
| 70 | } |
| 71 | $countTotal = $this->count(); |
| 72 | $rows = $this->request->getRows(); |
| 73 | $data = [ |
| 74 | 'rows' => $rows, |
| 75 | 'page' => $page, |
| 76 | 'amount' => count($taskList), |
| 77 | 'total' => ceil($countTotal / $rows), |
| 78 | 'data' => $taskList, |
| 79 | ]; |
| 80 | |
| 81 | return $data; |
| 82 | } |
| 83 | |
| 84 | public function count() |
| 85 | { |
| 86 | $params = $this->request->getFilters(); |
| 87 | |
| 88 | if (!empty($this->currentUserId)) { |
| 89 | $params['owner'] = $this->currentUserId; |
| 90 | } |
| 91 | |
| 92 | return $this->persistence->count($params); |
| 93 | } |
| 94 | |
| 95 | public function __construct( |
| 96 | TaskPersistenceInterface $persistence, |
| 97 | $currentUserId = null, |
| 98 | DatatableRequestInterface $request = null |
| 99 | ) { |
| 100 | $this->persistence = $persistence; |
| 101 | $this->currentUserId = $currentUserId; |
| 102 | |
| 103 | if ($request === null) { |
| 104 | $request = DatatableRequest::fromGlobals(); |
| 105 | } |
| 106 | |
| 107 | $this->request = $request; |
| 108 | } |
| 109 | |
| 110 | public function jsonSerialize() |
| 111 | { |
| 112 | return $this->getPayload(); |
| 113 | } |
| 114 | } |