Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       0.00%  | 
       0 / 16  | 
               | 
       0.00%  | 
       0 / 4  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| DiagnosticService |         | 
       0.00%  | 
       0 / 16  | 
               | 
       0.00%  | 
       0 / 4  | 
       56 |         | 
       0.00%  | 
       0 / 1  | 
      
| getDiagnosticJsConfig |         | 
       0.00%  | 
       0 / 6  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getRawConfig |         | 
       0.00%  | 
       0 / 1  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getConfigByTheme |         | 
       0.00%  | 
       0 / 8  | 
               | 
       0.00%  | 
       0 / 1  | 
       20 | |||
| getTesters |         | 
       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-2023 (original work) Open Assessment Technologies SA. | 
| 19 | */ | 
| 20 | |
| 21 | namespace oat\taoClientDiagnostic\model\diagnostic; | 
| 22 | |
| 23 | use oat\oatbox\service\ConfigurableService; | 
| 24 | use oat\tao\model\theme\ThemeService; | 
| 25 | |
| 26 | /** | 
| 27 | * Class DiagnosticService | 
| 28 | * @package oat\taoClientDiagnostic\model\diagnostic | 
| 29 | * @author Aleh Hutnikau, <hutnikau@apt.com> | 
| 30 | */ | 
| 31 | class DiagnosticService extends ConfigurableService implements DiagnosticServiceInterface | 
| 32 | { | 
| 33 | /** | 
| 34 | * (non-PHPdoc) | 
| 35 | * @see \oat\taoClientDiagnostic\model\diagnostic\DiagnosticServiceInterface::getDiagnosticJsConfig() | 
| 36 | */ | 
| 37 | public function getDiagnosticJsConfig() | 
| 38 | { | 
| 39 | $config = $this->getRawConfig(); | 
| 40 | // override samples based on graphical theme, why not | 
| 41 | $config['diagnostic']['testers']['performance']['samples'] | 
| 42 | = $this->getConfigByTheme($config['diagnostic']['testers']['performance']['samples']); | 
| 43 | $config['diagnostic']['testers']['screen']['threshold'] | 
| 44 | = $this->getConfigByTheme($config['diagnostic']['testers']['screen']['threshold']); | 
| 45 | |
| 46 | return $config; | 
| 47 | } | 
| 48 | |
| 49 | /** | 
| 50 | * Returns the raw configuration of the diagtool | 
| 51 | * @return array | 
| 52 | */ | 
| 53 | protected function getRawConfig() | 
| 54 | { | 
| 55 | return $this->getServiceLocator()->get('taoClientDiagnostic/clientDiag')->getConfig(); | 
| 56 | } | 
| 57 | |
| 58 | /** | 
| 59 | * Returns the current theme's related config | 
| 60 | * @param array $config | 
| 61 | * @param string $themeId | 
| 62 | * @return array|mixed | 
| 63 | */ | 
| 64 | protected function getConfigByTheme(array $config, $themeId = null) | 
| 65 | { | 
| 66 | if (null === $themeId) { | 
| 67 | $themeService = $this->getServiceLocator()->get(ThemeService::SERVICE_ID); | 
| 68 | $themeId = $themeService->getCurrentThemeId(); | 
| 69 | } | 
| 70 | if (is_array(reset($config))) { | 
| 71 | if (array_key_exists($themeId, $config)) { | 
| 72 | $config = $config[$themeId]; | 
| 73 | } else { | 
| 74 | $config = array_shift($config); | 
| 75 | } | 
| 76 | } | 
| 77 | return $config; | 
| 78 | } | 
| 79 | |
| 80 | /** | 
| 81 | * @deprecated please use getDiagnosticJsConfig() | 
| 82 | */ | 
| 83 | public function getTesters() | 
| 84 | { | 
| 85 | return $this->getDiagnosticJsConfig(); | 
| 86 | } | 
| 87 | } |