Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ModelHelper | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| getModules | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| getActions | |
0.00% |
0 / 7 |
|
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) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | */ |
| 23 | |
| 24 | namespace oat\funcAcl\helpers; |
| 25 | |
| 26 | use core_kernel_classes_Resource; |
| 27 | use oat\funcAcl\models\AccessService; |
| 28 | use oat\tao\helpers\ControllerHelper; |
| 29 | use ReflectionException; |
| 30 | |
| 31 | /** |
| 32 | * Helper to read/write the action/module model |
| 33 | * of tao from/to the ontology |
| 34 | * |
| 35 | * @access public |
| 36 | * |
| 37 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 38 | * |
| 39 | * @package tao |
| 40 | */ |
| 41 | class ModelHelper |
| 42 | { |
| 43 | /** |
| 44 | * returns the modules of an extension from the ontology |
| 45 | * |
| 46 | * @access public |
| 47 | * |
| 48 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 49 | * |
| 50 | * @param string $extensionID |
| 51 | * @param mixed $extensionId |
| 52 | * |
| 53 | * @return array |
| 54 | */ |
| 55 | public static function getModules($extensionId) |
| 56 | { |
| 57 | $returnValue = []; |
| 58 | |
| 59 | foreach (ControllerHelper::getControllers($extensionId) as $controllerClassName) { |
| 60 | $shortName = strpos($controllerClassName, '\\') !== false |
| 61 | ? substr($controllerClassName, strrpos($controllerClassName, '\\') + 1) |
| 62 | : substr($controllerClassName, strrpos($controllerClassName, '_') + 1) |
| 63 | ; |
| 64 | $uri = AccessService::singleton()->makeEMAUri($extensionId, $shortName); |
| 65 | $returnValue[$uri] = new core_kernel_classes_Resource($uri); |
| 66 | } |
| 67 | |
| 68 | return (array) $returnValue; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * returns the actions of a module from the ontology |
| 73 | * |
| 74 | * @access public |
| 75 | * |
| 76 | * @author Jerome Bogaerts, <jerome.bogaerts@tudor.lu> |
| 77 | * |
| 78 | * @param Resource $module |
| 79 | * |
| 80 | * @return array |
| 81 | */ |
| 82 | public static function getActions(core_kernel_classes_Resource $module) |
| 83 | { |
| 84 | $returnValue = []; |
| 85 | $controllerClassName = MapHelper::getControllerFromUri($module->getUri()); |
| 86 | |
| 87 | try { |
| 88 | foreach (ControllerHelper::getActions($controllerClassName) as $actionName) { |
| 89 | $uri = MapHelper::getUriForAction($controllerClassName, $actionName); |
| 90 | $returnValue[$uri] = new core_kernel_classes_Resource($uri); |
| 91 | } |
| 92 | } catch (ReflectionException $e) { |
| 93 | // unknown controller, no actions returned |
| 94 | } |
| 95 | |
| 96 | return (array) $returnValue; |
| 97 | } |
| 98 | } |