Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_form_elements_Treeview | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| rangeToTree | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
20 | |||
| 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 | |
| 25 | use oat\tao\helpers\form\elements\TreeAware; |
| 26 | |
| 27 | /** |
| 28 | * Short description of class tao_helpers_form_elements_Treeview |
| 29 | * |
| 30 | * @abstract |
| 31 | * @access public |
| 32 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 33 | * @package tao |
| 34 | |
| 35 | */ |
| 36 | abstract class tao_helpers_form_elements_Treeview extends tao_helpers_form_elements_MultipleElement implements TreeAware |
| 37 | { |
| 38 | public const WIDGET_ID = 'http://www.tao.lu/datatypes/WidgetDefinitions.rdf#TreeView'; |
| 39 | |
| 40 | /** |
| 41 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 42 | * @param core_kernel_classes_Class $range |
| 43 | * @param boolean $recursive |
| 44 | * @return array |
| 45 | */ |
| 46 | public function rangeToTree(core_kernel_classes_Class $range, $recursive = false) |
| 47 | { |
| 48 | $data = []; |
| 49 | foreach ($range->getSubClasses(false) as $rangeClass) { |
| 50 | $classData = [ |
| 51 | 'data' => $rangeClass->getLabel(), |
| 52 | 'attributes' => [ |
| 53 | 'id' => tao_helpers_Uri::encode($rangeClass->getUri()), |
| 54 | 'class' => 'node-instance' |
| 55 | ] |
| 56 | ]; |
| 57 | $children = $this->rangeToTree($rangeClass, true); |
| 58 | if (count($children) > 0) { |
| 59 | $classData['state'] = 'closed'; |
| 60 | $classData['children'] = $children; |
| 61 | } |
| 62 | |
| 63 | $data[] = $classData; |
| 64 | } |
| 65 | if (!$recursive) { |
| 66 | $returnValue = [ |
| 67 | 'data' => $range->getLabel(), |
| 68 | 'attributes' => [ |
| 69 | 'id' => tao_helpers_Uri::encode($range->getUri()), |
| 70 | 'class' => 'node-class' |
| 71 | ], |
| 72 | 'children' => $data |
| 73 | ]; |
| 74 | } else { |
| 75 | $returnValue = $data; |
| 76 | } |
| 77 | |
| 78 | return $returnValue; |
| 79 | } |
| 80 | } |