Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Home | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| splash | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
12 | |||
| hasAccessForAtLeastOneChild | |
0.00% |
0 / 9 |
|
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) 2014-2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoCe\actions; |
| 24 | |
| 25 | use oat\tao\helpers\TaoCe; |
| 26 | use oat\tao\model\menu\MenuService; |
| 27 | use oat\tao\model\menu\Perspective; |
| 28 | use tao_actions_CommonModule; |
| 29 | use tao_models_classes_accessControl_AclProxy; |
| 30 | |
| 31 | /** @author Bertrand Chevrier <bertrand@taotesting.com> */ |
| 32 | class Home extends tao_actions_CommonModule |
| 33 | { |
| 34 | /** This action renders the template used by the splash screen popup */ |
| 35 | public function splash(): void |
| 36 | { |
| 37 | // The list of extensions the splash provides an explanation for. |
| 38 | $defaultExtIds = ['items', 'tests', 'TestTaker', 'groups', 'delivery', 'results']; |
| 39 | |
| 40 | // Check if the user is a noob |
| 41 | $this->setData('firstTime', TaoCe::isFirstTimeInTao()); |
| 42 | |
| 43 | // Load the extension data |
| 44 | $defaultExtensions = []; |
| 45 | $additionalExtensions = []; |
| 46 | |
| 47 | /** @var Perspective $perspective */ |
| 48 | foreach (MenuService::getPerspectivesByGroup(Perspective::GROUP_DEFAULT) as $perspective) { |
| 49 | $perspectiveId = (string) $perspective->getId(); |
| 50 | |
| 51 | $extensionInfo = [ |
| 52 | 'id' => $perspectiveId, |
| 53 | 'name' => $perspective->getName(), |
| 54 | 'extension' => $perspective->getExtension(), |
| 55 | 'enabled' => $this->hasAccessForAtLeastOneChild($perspective), |
| 56 | ]; |
| 57 | |
| 58 | if (in_array($perspectiveId, $defaultExtIds, true)) { |
| 59 | $extensionInfo['description'] = $perspective->getDescription(); |
| 60 | $defaultExtensions[$perspectiveId] = $extensionInfo; |
| 61 | } else { |
| 62 | $additionalExtensions[$perspectiveId] = $extensionInfo; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | $this->setData('extensions', array_merge($defaultExtensions, $additionalExtensions)); |
| 67 | $this->setData('defaultExtensions', $defaultExtensions); |
| 68 | $this->setData('additionalExtensions', $additionalExtensions); |
| 69 | |
| 70 | $this->setView('splash.tpl'); |
| 71 | } |
| 72 | |
| 73 | private function hasAccessForAtLeastOneChild(Perspective $perspective): bool |
| 74 | { |
| 75 | foreach ($perspective->getChildren() as $section) { |
| 76 | $hasAccess = tao_models_classes_accessControl_AclProxy::hasAccess( |
| 77 | $section->getAction(), |
| 78 | $section->getController(), |
| 79 | $section->getExtensionId() |
| 80 | ); |
| 81 | |
| 82 | if ($hasAccess) { |
| 83 | return true; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return false; |
| 88 | } |
| 89 | } |