Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| DeliveriesMonitorDatatable | |
0.00% |
0 / 41 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getPayload | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
56 | |||
| doPostProcessing | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDeliveryHelperService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017-2022 (original work) Open Assessment Technologies SA ; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoProctoring\model\datatable; |
| 23 | |
| 24 | use oat\tao\model\datatable\implementation\DatatableRequest; |
| 25 | use oat\tao\model\datatable\DatatablePayload; |
| 26 | use oat\taoProctoring\model\execution\DeliveryExecutionList; |
| 27 | use oat\taoProctoring\model\execution\DeliveryExecutionListInterface; |
| 28 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 29 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 30 | use oat\taoProctoring\model\ProctorService; |
| 31 | use oat\taoProctoring\helpers\DeliveryHelper; |
| 32 | |
| 33 | /** |
| 34 | * Class DeliveriesMonitorDatatable |
| 35 | * @package oat\taoProctoring\model\datatable |
| 36 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
| 37 | */ |
| 38 | class DeliveriesMonitorDatatable implements DatatablePayload, ServiceLocatorAwareInterface |
| 39 | { |
| 40 | use ServiceLocatorAwareTrait; |
| 41 | |
| 42 | /** |
| 43 | * @var DatatableRequest |
| 44 | */ |
| 45 | protected $request; |
| 46 | |
| 47 | /** |
| 48 | * @var DatatableRequest |
| 49 | */ |
| 50 | protected $datatableRequest; |
| 51 | |
| 52 | /** |
| 53 | * @var \core_kernel_classes_Resource |
| 54 | */ |
| 55 | protected $delivery; |
| 56 | |
| 57 | /** |
| 58 | * DeliveriesMonitorDatatable constructor. |
| 59 | * @param \core_kernel_classes_Resource $delivery |
| 60 | * @param \Request $request |
| 61 | */ |
| 62 | public function __construct(\core_kernel_classes_Resource $delivery = null, $request) |
| 63 | { |
| 64 | $this->datatableRequest = DatatableRequest::fromGlobals(); |
| 65 | $this->request = $request; |
| 66 | $this->delivery = $delivery; |
| 67 | } |
| 68 | |
| 69 | public function getPayload() |
| 70 | { |
| 71 | $context = $this->request->hasParameter('context') ? $this->request->getParameter('context') : null; |
| 72 | $filters = []; |
| 73 | foreach ($this->datatableRequest->getFilters() as $filterKey => $filterValue) { |
| 74 | if ($filterKey === 'start_time') { |
| 75 | $times = explode(' - ', $filterValue); |
| 76 | $filters[] = ['start_time' => '>' . $times[0]]; |
| 77 | if (isset($times[1])) { |
| 78 | $filters[] = ['start_time' => '<' . $times[1]]; |
| 79 | } |
| 80 | } elseif ($filterKey === 'tag') { |
| 81 | $filters[] = [$filterKey => $filterValue]; |
| 82 | } else { |
| 83 | $filters[] = [$filterKey => 'LIKE %' . $filterValue . '%']; |
| 84 | } |
| 85 | } |
| 86 | $options = []; |
| 87 | $options['filters'] = $filters; |
| 88 | $orderCol = DeliveryHelper::adjustColumnName($this->datatableRequest->getSortBy()); |
| 89 | if ($orderCol) { |
| 90 | $options['order'] = join(' ', [ |
| 91 | $orderCol, |
| 92 | $this->datatableRequest->getSortOrder(), |
| 93 | $this->datatableRequest->getSortType() |
| 94 | ]); |
| 95 | } |
| 96 | $options['limit'] = $this->datatableRequest->getRows(); |
| 97 | $options['offset'] = ($this->datatableRequest->getPage() - 1) * $this->datatableRequest->getRows(); |
| 98 | |
| 99 | $service = $this->getServiceLocator()->get(ProctorService::SERVICE_ID); |
| 100 | $proctor = \common_session_SessionManager::getSession()->getUser(); |
| 101 | $executions = $service->getProctorableDeliveryExecutions($proctor, $this->delivery, $context, $options); |
| 102 | $total = $service->countProctorableDeliveryExecutions($proctor, $this->delivery, $context, $options); |
| 103 | $totalPages = ceil($total / $this->datatableRequest->getRows()); |
| 104 | |
| 105 | return $this->doPostProcessing($executions, $total, $totalPages); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * @param array $executionsData |
| 110 | * @param integer $amount |
| 111 | * @param integer $pages |
| 112 | * @return array |
| 113 | * @throws \common_ext_ExtensionException |
| 114 | */ |
| 115 | protected function doPostProcessing(array $executionsData, $amount, $pages) |
| 116 | { |
| 117 | return [ |
| 118 | 'success' => true, |
| 119 | 'amount' => $amount, |
| 120 | 'total' => $pages, |
| 121 | 'page' => $this->datatableRequest->getPage(), |
| 122 | 'rows' => $this->datatableRequest->getRows(), |
| 123 | 'data' => $this->getDeliveryHelperService()->adjustDeliveryExecutions($executionsData), |
| 124 | ]; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * @return array |
| 129 | */ |
| 130 | public function jsonSerialize() |
| 131 | { |
| 132 | return $this->getPayload(); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @return DeliveryExecutionList |
| 137 | */ |
| 138 | private function getDeliveryHelperService() |
| 139 | { |
| 140 | return $this->getServiceLocator()->get(DeliveryExecutionListInterface::class); |
| 141 | } |
| 142 | } |