Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       0.00%  | 
       0 / 80  | 
               | 
       0.00%  | 
       0 / 8  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| Diagnostic |         | 
       0.00%  | 
       0 / 80  | 
               | 
       0.00%  | 
       0 / 8  | 
       506 |         | 
       0.00%  | 
       0 / 1  | 
      
| index |         | 
       0.00%  | 
       0 / 16  | 
               | 
       0.00%  | 
       0 / 1  | 
       6 | |||
| diagnostic |         | 
       0.00%  | 
       0 / 17  | 
               | 
       0.00%  | 
       0 / 1  | 
       6 | |||
| diagnosticData |         | 
       0.00%  | 
       0 / 4  | 
               | 
       0.00%  | 
       0 / 1  | 
       6 | |||
| remove |         | 
       0.00%  | 
       0 / 4  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getRequestOptions |         | 
       0.00%  | 
       0 / 22  | 
               | 
       0.00%  | 
       0 / 1  | 
       132 | |||
| getDefaultOptions |         | 
       0.00%  | 
       0 / 10  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| loadConfig |         | 
       0.00%  | 
       0 / 2  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getDiagnosticDataTable |         | 
       0.00%  | 
       0 / 5  | 
               | 
       0.00%  | 
       0 / 1  | 
       6 | |||
| 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-2019 (original work) Open Assessment Technologies SA ; | 
| 19 | * | 
| 20 | */ | 
| 21 | |
| 22 | namespace oat\taoClientDiagnostic\controller; | 
| 23 | |
| 24 | use oat\generis\model\OntologyAwareTrait; | 
| 25 | use oat\oatbox\service\ServiceNotFoundException; | 
| 26 | use oat\tao\model\theme\ThemeService; | 
| 27 | use oat\taoClientDiagnostic\model\diagnostic\Paginator; | 
| 28 | use DateTime; | 
| 29 | use common_session_SessionManager as SessionManager; | 
| 30 | use oat\taoClientDiagnostic\model\diagnostic\DiagnosticServiceInterface; | 
| 31 | use oat\taoClientDiagnostic\model\diagnostic\DiagnosticDataTable; | 
| 32 | |
| 33 | /** | 
| 34 | * Diagnostic controller for the readiness check list screen | 
| 35 | * | 
| 36 | * @author Open Assessment Technologies SA | 
| 37 | * @package taoProctoring | 
| 38 | * @license GPL-2.0 | 
| 39 | * | 
| 40 | */ | 
| 41 | class Diagnostic extends \tao_actions_CommonModule | 
| 42 | { | 
| 43 | use OntologyAwareTrait; | 
| 44 | |
| 45 | public const DEFAULT_SORT_COLUMN = 'firstname'; | 
| 46 | public const DEFAULT_SORT_ORDER = 'asc'; | 
| 47 | |
| 48 | protected $currentTestCenter = null; | 
| 49 | protected $currentDelivery = null; | 
| 50 | protected $dataTable; | 
| 51 | |
| 52 | /** | 
| 53 | * Display the list of all readiness checks performed on the given test center. | 
| 54 | * It also allows launching new ones. | 
| 55 | */ | 
| 56 | public function index() | 
| 57 | { | 
| 58 | $diagnostics = $this->getDiagnosticDataTable()->getDiagnostics($this->getRequestOptions()); | 
| 59 | |
| 60 | $config = $this->loadConfig(); | 
| 61 | $data = array( | 
| 62 | 'title' => __('Readiness diagnostics'), | 
| 63 | 'set' => json_encode($diagnostics), | 
| 64 | 'config' => json_encode($config['diagnostic']), | 
| 65 | ); | 
| 66 | |
| 67 | $userLabel = SessionManager::getSession()->getUserLabel(); | 
| 68 | |
| 69 | $this->defaultData(); | 
| 70 | |
| 71 | if (!empty($config['diagnostic']['pageTitle'])) { | 
| 72 | $this->setData('title', $config['diagnostic']['pageTitle']); | 
| 73 | } | 
| 74 | |
| 75 | $this->setData('cls', 'diagnostic-index'); | 
| 76 | $this->setData('userLabel', $userLabel); | 
| 77 | $this->setData('data', $data); | 
| 78 | $this->setData('content-template', 'pages/index.tpl'); | 
| 79 | $this->setView('layout.tpl'); | 
| 80 | } | 
| 81 | |
| 82 | /** | 
| 83 | * Display the diagnostic runner | 
| 84 | */ | 
| 85 | public function diagnostic() | 
| 86 | { | 
| 87 | $config = $this->loadConfig(); | 
| 88 | $data = array( | 
| 89 | 'title' => __('Readiness Check'), | 
| 90 | 'config' => json_encode($config['diagnostic']), | 
| 91 | ); | 
| 92 | |
| 93 | $this->defaultData(); | 
| 94 | $this->setData('userLabel', SessionManager::getSession()->getUserLabel()); | 
| 95 | $this->setData('cls', 'diagnostic-runner'); | 
| 96 | $this->setData('data', $data); | 
| 97 | $this->setData('content-template', 'pages/index.tpl'); | 
| 98 | |
| 99 | if (!empty($config['diagnostic']['pageTitle'])) { | 
| 100 | $this->setData('title', $config['diagnostic']['pageTitle']); | 
| 101 | } | 
| 102 | |
| 103 | /** @var \oat\tao\model\theme\ThemeService $themeService */ | 
| 104 | $themeService = $this->getServiceLocator()->get(ThemeService::SERVICE_ID); | 
| 105 | $theme = $themeService->getTheme(); | 
| 106 | $configurableText = $theme->getAllTexts(); | 
| 107 | $this->setData('configurableText', json_encode($configurableText)); | 
| 108 | |
| 109 | $this->setView('layout.tpl'); | 
| 110 | } | 
| 111 | |
| 112 | /** | 
| 113 | * Gets the list of diagnostic results | 
| 114 | * | 
| 115 | * @throws \common_Exception | 
| 116 | */ | 
| 117 | public function diagnosticData() | 
| 118 | { | 
| 119 | try { | 
| 120 | $this->returnJson($this->getDiagnosticDataTable()->getDiagnostics($this->getRequestOptions())); | 
| 121 | } catch (ServiceNotFoundException $e) { | 
| 122 | \common_Logger::w(__('No diagnostic service defined')); | 
| 123 | $this->returnError(__('Interface not available')); | 
| 124 | } | 
| 125 | } | 
| 126 | |
| 127 | /** | 
| 128 | * Removes diagnostic results | 
| 129 | * | 
| 130 | * @throws \common_Exception | 
| 131 | */ | 
| 132 | public function remove() | 
| 133 | { | 
| 134 | $id = $this->getRequestParameter('id'); | 
| 135 | $this->returnJson([ | 
| 136 | 'success' => $this->getDiagnosticDataTable()->removeDiagnostic($id) | 
| 137 | ]); | 
| 138 | } | 
| 139 | |
| 140 | /** | 
| 141 | * Gets the data table request options | 
| 142 | * | 
| 143 | * @param array $defaults | 
| 144 | * @return array | 
| 145 | */ | 
| 146 | protected function getRequestOptions(array $defaults = []) | 
| 147 | { | 
| 148 | $defaults = array_merge($this->getDefaultOptions(), $defaults); | 
| 149 | |
| 150 | // phpcs:disable | 
| 151 | $page = $this->hasRequestParameter('page') ? $this->getRequestParameter('page') : $defaults['page']; | 
| 152 | $rows = $this->hasRequestParameter('rows') ? $this->getRequestParameter('rows') : $defaults['rows']; | 
| 153 | $sortBy = $this->hasRequestParameter('sortby') ? $this->getRequestParameter('sortby') : $defaults['sortby']; | 
| 154 | $sortOrder = $this->hasRequestParameter('sortorder') ? $this->getRequestParameter('sortorder') : $defaults['sortorder']; | 
| 155 | $filter = $this->hasRequestParameter('filter') ? $this->getRequestParameter('filter') : $defaults['filter']; | 
| 156 | $filterquery = $this->hasRequestParameter('filterquery') ? $this->getRequestParameter('filterquery') : $defaults['filter']; | 
| 157 | $periodStart = $this->hasRequestParameter('periodStart') ? $this->getRequestParameter('periodStart') : $defaults['periodStart']; | 
| 158 | $periodEnd = $this->hasRequestParameter('periodEnd') ? $this->getRequestParameter('periodEnd') : $defaults['periodEnd']; | 
| 159 | $detailed = $this->hasRequestParameter('detailed') ? $this->getRequestParameter('detailed') : 'false'; | 
| 160 | $detailed = filter_var($detailed, FILTER_VALIDATE_BOOLEAN); | 
| 161 | // phpcs:enable | 
| 162 | |
| 163 | return array( | 
| 164 | 'page' => $page, | 
| 165 | 'rows' => $rows, | 
| 166 | 'sortBy' => $sortBy, | 
| 167 | 'sortOrder' => $sortOrder, | 
| 168 | 'filter' => $filter ? $filter : $filterquery, | 
| 169 | 'periodStart' => $periodStart, | 
| 170 | 'detailed' => $detailed, | 
| 171 | 'periodEnd' => $periodEnd | 
| 172 | ); | 
| 173 | } | 
| 174 | |
| 175 | /** | 
| 176 | * @return array | 
| 177 | */ | 
| 178 | private function getDefaultOptions() | 
| 179 | { | 
| 180 | $today = new DateTime(); | 
| 181 | return [ | 
| 182 | 'page' => Paginator::DEFAULT_PAGE, | 
| 183 | 'rows' => Paginator::DEFAULT_ROWS, | 
| 184 | 'sortby' => self::DEFAULT_SORT_COLUMN, | 
| 185 | 'sortorder' => self::DEFAULT_SORT_ORDER, | 
| 186 | 'filter' => null, | 
| 187 | 'periodStart' => $today->format('Y-m-d'), | 
| 188 | 'periodEnd' => $today->format('Y-m-d') | 
| 189 | ]; | 
| 190 | } | 
| 191 | |
| 192 | /** | 
| 193 | * Get config parameters for compatibility check | 
| 194 | * | 
| 195 | * @return mixed | 
| 196 | */ | 
| 197 | protected function loadConfig() | 
| 198 | { | 
| 199 | /** @var DiagnosticServiceInterface $service */ | 
| 200 | $service = $this->getServiceLocator()->get(DiagnosticServiceInterface::SERVICE_ID); | 
| 201 | return $service->getDiagnosticJsConfig(); | 
| 202 | } | 
| 203 | |
| 204 | /** | 
| 205 | * Get the model to access diagnostic storage through dataTable | 
| 206 | * | 
| 207 | * @return DiagnosticDataTable | 
| 208 | */ | 
| 209 | protected function getDiagnosticDataTable() | 
| 210 | { | 
| 211 | if (! $this->dataTable) { | 
| 212 | $diagnosticDatatable = new DiagnosticDataTable(); | 
| 213 | $diagnosticDatatable->setServiceLocator($this->getServiceLocator()); | 
| 214 | $this->dataTable = $diagnosticDatatable; | 
| 215 | } | 
| 216 | return $this->dataTable; | 
| 217 | } | 
| 218 | } |