Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| Tree | |
0.00% |
0 / 17 |
|
0.00% |
0 / 7 |
132 | |
0.00% |
0 / 1 |
| fromSimpleXMLElement | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| getAttributes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getActions | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __toPhpCode | |
0.00% |
0 / 4 |
|
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 | i * |
| 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 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\tao\model\menu; |
| 24 | |
| 25 | use oat\oatbox\PhpSerializable; |
| 26 | |
| 27 | class Tree implements PhpSerializable |
| 28 | { |
| 29 | public const SERIAL_VERSION = 1392821334; |
| 30 | |
| 31 | private $data = []; |
| 32 | |
| 33 | /** |
| 34 | * @param \SimpleXMLElement $node |
| 35 | * @param $structureExtensionId Note that this is currently not used, but it will be for SVG icons in the tree. Also |
| 36 | * it makes sure that all instances of fromSimpleXMLElement() use the same interface. |
| 37 | * @return static |
| 38 | */ |
| 39 | public static function fromSimpleXMLElement(\SimpleXMLElement $node, $structureExtensionId) |
| 40 | { |
| 41 | $data = []; |
| 42 | foreach ($node->attributes() as $attrName => $attrValue) { |
| 43 | $data[$attrName] = (string)$attrValue; |
| 44 | } |
| 45 | return new static($data); |
| 46 | } |
| 47 | |
| 48 | public function __construct($data, $version = self::SERIAL_VERSION) |
| 49 | { |
| 50 | $this->data = $data; |
| 51 | } |
| 52 | |
| 53 | public function get($attribute) |
| 54 | { |
| 55 | return isset($this->data[$attribute]) ? $this->data[$attribute] : null; |
| 56 | } |
| 57 | |
| 58 | public function getAttributes() |
| 59 | { |
| 60 | return array_keys($this->data); |
| 61 | } |
| 62 | |
| 63 | public function getActions() |
| 64 | { |
| 65 | $actions = []; |
| 66 | foreach ($this->data as $key => $value) { |
| 67 | if (!in_array($key, ['rootNode', 'searchNode', 'dataUrl', 'className', 'name'])) { |
| 68 | $actions[$key] = $value; |
| 69 | } |
| 70 | } |
| 71 | return $actions; |
| 72 | } |
| 73 | |
| 74 | public function getName() |
| 75 | { |
| 76 | return $this->data['name']; |
| 77 | } |
| 78 | |
| 79 | public function __toPhpCode() |
| 80 | { |
| 81 | return "new " . __CLASS__ . "(" |
| 82 | . \common_Utils::toPHPVariableString($this->data) . ',' |
| 83 | . \common_Utils::toPHPVariableString(self::SERIAL_VERSION) |
| 84 | . ")"; |
| 85 | } |
| 86 | } |