Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| DeliveriesActivityDatatable | |
0.00% |
0 / 27 |
|
0.00% |
0 / 5 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getPayload | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| doPostProcessing | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| doSorting | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| jsonSerialize | |
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 (original work) Open Assessment Technologies SA ; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoProctoring\model\datatable; |
| 23 | |
| 24 | use oat\generis\model\OntologyRdfs; |
| 25 | use oat\tao\model\datatable\implementation\DatatableRequest; |
| 26 | use oat\tao\model\datatable\DatatablePayload; |
| 27 | use oat\oatbox\service\ServiceManager; |
| 28 | use oat\taoDeliveryRdf\model\DeliveryAssemblyService; |
| 29 | use oat\taoProctoring\model\ActivityMonitoringService; |
| 30 | use oat\taoProctoring\model\monitorCache\DeliveryMonitoringService; |
| 31 | use oat\taoProctoring\model\monitorCache\implementation\MonitoringStorage; |
| 32 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 33 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 34 | |
| 35 | /** |
| 36 | * Class DeliveriesActivityDatatable |
| 37 | * @package oat\taoProctoring\model\datatable |
| 38 | * @author Aleh Hutnikau, <hutnikau@1pt.com> |
| 39 | */ |
| 40 | class DeliveriesActivityDatatable implements DatatablePayload, ServiceLocatorAwareInterface |
| 41 | { |
| 42 | use ServiceLocatorAwareTrait; |
| 43 | |
| 44 | /** |
| 45 | * @var DatatableRequest |
| 46 | */ |
| 47 | protected $request; |
| 48 | |
| 49 | /** |
| 50 | * @var DeliveryAssemblyService |
| 51 | */ |
| 52 | protected $deliveryService; |
| 53 | |
| 54 | /** |
| 55 | * DeliveriesActivityDatatable constructor. |
| 56 | */ |
| 57 | public function __construct() |
| 58 | { |
| 59 | $this->setServiceLocator(ServiceManager::getServiceManager()); |
| 60 | $this->request = DatatableRequest::fromGlobals(); |
| 61 | $this->deliveryService = DeliveryAssemblyService::singleton(); |
| 62 | } |
| 63 | |
| 64 | public function getPayload() |
| 65 | { |
| 66 | /** @var DeliveryMonitoringService $service */ |
| 67 | $service = $this->getServiceLocator()->get(DeliveryMonitoringService::SERVICE_ID); |
| 68 | |
| 69 | $offset = ($this->request->getPage() - 1) * $this->request->getRows() ?: 0; |
| 70 | $limit = $this->request->getRows() ?: 0; |
| 71 | |
| 72 | $sortBy = $this->request->getSortBy(); |
| 73 | $sortOrder = strcasecmp($this->request->getSortOrder(), 'asc') === 0 ? 'asc' : 'desc'; |
| 74 | |
| 75 | $data = $service->getStatusesStatistic($limit, $offset, $sortBy, $sortOrder); |
| 76 | $result = $this->doPostProcessing($data); |
| 77 | |
| 78 | return $result; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @param array $result |
| 83 | * @return array |
| 84 | */ |
| 85 | protected function doPostProcessing(array $result) |
| 86 | { |
| 87 | /** @var DeliveryMonitoringService $service */ |
| 88 | $service = $this->getServiceLocator()->get(DeliveryMonitoringService::SERVICE_ID); |
| 89 | $rows = $this->request->getRows(); |
| 90 | $rows = $rows ?: 1; |
| 91 | $total = $service->getCountOfStatistics(); |
| 92 | $payload = [ |
| 93 | 'data' => $result, |
| 94 | 'page' => (int) $this->request->getPage(), |
| 95 | 'records' => (int) count($result), |
| 96 | 'total' => ceil($total / $rows), |
| 97 | ]; |
| 98 | return $payload; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @param array $result |
| 103 | */ |
| 104 | protected function doSorting(array &$result) |
| 105 | { |
| 106 | $sortBy = $this->request->getSortBy(); |
| 107 | $sortOrder = strcasecmp($this->request->getSortOrder(), 'asc') === 0 ? SORT_ASC : SORT_DESC; |
| 108 | $flag = ($sortBy === 'label') ? SORT_STRING | SORT_FLAG_CASE : SORT_NUMERIC; |
| 109 | array_multisort(array_column($result, $sortBy), $sortOrder, $flag, $result); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * @return array |
| 114 | */ |
| 115 | public function jsonSerialize() |
| 116 | { |
| 117 | return $this->getPayload(); |
| 118 | } |
| 119 | } |