Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 58 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| DiagnosticDataTable | |
0.00% |
0 / 58 |
|
0.00% |
0 / 5 |
182 | |
0.00% |
0 / 1 |
| getDiagnostic | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDiagnostics | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
20 | |||
| removeDiagnostic | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| paginate | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getStorage | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| 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-2023 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoClientDiagnostic\model\diagnostic; |
| 22 | |
| 23 | use common_exception_NoImplementation; |
| 24 | use DateTime; |
| 25 | use oat\taoClientDiagnostic\exception\StorageException; |
| 26 | use oat\taoClientDiagnostic\model\storage\PaginatedStorage; |
| 27 | use tao_helpers_Date as DateHelper; |
| 28 | use oat\taoClientDiagnostic\model\storage\Storage; |
| 29 | use oat\taoClientDiagnostic\model\storage\PaginatedSqlStorage; |
| 30 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 31 | use Zend\ServiceManager\ServiceLocatorAwareTrait; |
| 32 | |
| 33 | /** |
| 34 | * This temporary helpers is a temporary way to return data to the controller. |
| 35 | * This helps to isolate the mock code from the real controller one. |
| 36 | * It will be replaced by a real service afterward. |
| 37 | */ |
| 38 | class DiagnosticDataTable implements ServiceLocatorAwareInterface |
| 39 | { |
| 40 | use ServiceLocatorAwareTrait; |
| 41 | |
| 42 | protected $storage; |
| 43 | |
| 44 | /** |
| 45 | * Gets the results for a particular id |
| 46 | * |
| 47 | * @param $id |
| 48 | * @return mixed |
| 49 | * @throws common_exception_NoImplementation |
| 50 | */ |
| 51 | public function getDiagnostic($id) |
| 52 | { |
| 53 | return $this->getStorage()->find($id); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Gets the list of readiness checks related to a test site |
| 58 | * |
| 59 | * @param array [$options] |
| 60 | * @return array |
| 61 | * @throws common_exception_NoImplementation |
| 62 | */ |
| 63 | public function getDiagnostics($options = array()) |
| 64 | { |
| 65 | return $this->paginate($this->getStorage(), $options, function ($data) { |
| 66 | foreach ($data as $idx => $row) { |
| 67 | $rowData = [ |
| 68 | 'id' => $row[PaginatedSqlStorage::DIAGNOSTIC_ID], |
| 69 | 'school_name' => $row[PaginatedSqlStorage::DIAGNOSTIC_SCHOOL_NAME], |
| 70 | 'school_id' => $row[PaginatedSqlStorage::DIAGNOSTIC_SCHOOL_ID], |
| 71 | 'school_number' => $row[PaginatedSqlStorage::DIAGNOSTIC_SCHOOL_NUMBER], |
| 72 | 'fingerprint' => [ |
| 73 | 'uuid' => $row[PaginatedSqlStorage::DIAGNOSTIC_FINGERPRINT_UUID], |
| 74 | 'value' => $row[PaginatedSqlStorage::DIAGNOSTIC_FINGERPRINT_VALUE], |
| 75 | 'details' => json_decode( |
| 76 | html_entity_decode($row[PaginatedSqlStorage::DIAGNOSTIC_FINGERPRINT_DETAILS]), |
| 77 | true |
| 78 | ), |
| 79 | 'errors' => $row[PaginatedSqlStorage::DIAGNOSTIC_FINGERPRINT_ERRORS], |
| 80 | 'changed' => $row[PaginatedSqlStorage::DIAGNOSTIC_FINGERPRINT_CHANGED], |
| 81 | ], |
| 82 | 'screen' => [ |
| 83 | 'width' => $row[PaginatedSqlStorage::DIAGNOSTIC_SCREEN_WIDTH], |
| 84 | 'height' => $row[PaginatedSqlStorage::DIAGNOSTIC_SCREEN_HEIGHT] |
| 85 | ], |
| 86 | 'os' => $row[PaginatedSqlStorage::DIAGNOSTIC_OS] |
| 87 | . " ({$row[PaginatedSqlStorage::DIAGNOSTIC_OSVERSION]})", |
| 88 | 'browser' => $row[PaginatedSqlStorage::DIAGNOSTIC_BROWSER] |
| 89 | . " ({$row[PaginatedSqlStorage::DIAGNOSTIC_BROWSERVERSION]})", |
| 90 | 'performance' => $row[PaginatedSqlStorage::DIAGNOSTIC_PERFORMANCE_AVERAGE], |
| 91 | 'bandwidth' => $row[PaginatedSqlStorage::DIAGNOSTIC_BANDWIDTH_MAX], |
| 92 | 'intensive_bandwidth' => $row[PaginatedSqlStorage::DIAGNOSTIC_INTENSIVE_BANDWIDTH_MAX], |
| 93 | 'upload' => $row[PaginatedSqlStorage::DIAGNOSTIC_UPLOAD_MAX], |
| 94 | ]; |
| 95 | |
| 96 | if (isset($row[PaginatedSqlStorage::DIAGNOSTIC_WORKSTATION])) { |
| 97 | $rowData['workstation'] = $row[PaginatedSqlStorage::DIAGNOSTIC_WORKSTATION] |
| 98 | . " ({$row[PaginatedSqlStorage::DIAGNOSTIC_IP]})"; |
| 99 | } else { |
| 100 | $rowData['workstation'] = '(' . $row[PaginatedSqlStorage::DIAGNOSTIC_IP] . ')'; |
| 101 | } |
| 102 | |
| 103 | if (isset($row[PaginatedSqlStorage::DIAGNOSTIC_CREATED_AT])) { |
| 104 | $dt = new DateTime($row[PaginatedSqlStorage::DIAGNOSTIC_CREATED_AT]); |
| 105 | $rowData['date'] = $dt->getTimestamp(); |
| 106 | } |
| 107 | |
| 108 | $data[$idx] = $rowData; |
| 109 | } |
| 110 | return $data; |
| 111 | }); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Gets the list of readiness checks related to a test site |
| 116 | * |
| 117 | * @param $id |
| 118 | * @return bool |
| 119 | * @throws common_exception_NoImplementation |
| 120 | */ |
| 121 | public function removeDiagnostic($id) |
| 122 | { |
| 123 | $ids = $id ? $id : []; |
| 124 | if (! is_array($ids)) { |
| 125 | $ids = [$ids]; |
| 126 | } |
| 127 | |
| 128 | foreach ($ids as $id) { |
| 129 | $this->getStorage()->delete($id); |
| 130 | } |
| 131 | |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Wrap a datatable action to paginator to have subset of data |
| 137 | * |
| 138 | * @param $collection |
| 139 | * @param array $options |
| 140 | * @param null $dataRenderer |
| 141 | * @return array |
| 142 | */ |
| 143 | protected function paginate($collection, $options = array(), $dataRenderer = null) |
| 144 | { |
| 145 | return (new Paginator())->paginate($collection, $options, $dataRenderer); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Get diangostic storage |
| 150 | * |
| 151 | * @return PaginatedStorage |
| 152 | * @throws StorageException |
| 153 | */ |
| 154 | protected function getStorage() |
| 155 | { |
| 156 | if (! $this->storage) { |
| 157 | $storage = $this->getServiceLocator()->get(Storage::SERVICE_ID); |
| 158 | |
| 159 | if (! $storage instanceof PaginatedStorage) { |
| 160 | //phpcs:disable |
| 161 | throw new StorageException( |
| 162 | __('The storage service provided to store the diagnostic results must be upgraded to support reads!') |
| 163 | ); |
| 164 | //phpcs:enable |
| 165 | } |
| 166 | |
| 167 | $this->storage = $storage; |
| 168 | } |
| 169 | return $this->storage; |
| 170 | } |
| 171 | } |