Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Trees
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 6
72
0.00% covered (danger)
0.00%
0 / 1
 getClassService
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getRootClass
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTree
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 viewTree
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 dummy
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTreeData
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
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) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg
19 *                                         (under the project TAO & TAO2);
20 *               2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung
21 *                                                   (under the project TAO-TRANSFER);
22 *               2009-2012 (update and modification) Public Research Centre Henri Tudor
23 *                                                   (under the project TAO-SUSTAIN & TAO-DEV);
24 *               2015-2023 (update and modification) Open Assessment Technologies SA;
25 */
26
27namespace oat\taoBackOffice\controller;
28
29use core_kernel_classes_Class;
30use oat\taoBackOffice\model\tree\TreeService;
31
32/**
33 * This controller provide the actions to manage the lists of data
34 *
35 * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu}
36 * @license GPLv2  http://www.opensource.org/licenses/gpl-2.0.php
37 * @package taoBackOffice
38 *
39 *
40 */
41class Trees extends \tao_actions_RdfController
42{
43    /**
44     * @return TreeService
45     */
46    protected function getClassService()
47    {
48        return TreeService::singleton();
49    }
50
51    /**
52     *
53     * @return \core_kernel_classes_Class
54     */
55    protected function getRootClass()
56    {
57        return $this->getClassService()->getRootClass();
58    }
59
60    /**
61     * Visualises the tree
62     */
63    public function getTree()
64    {
65        $tree = $this->getClass($this->getRequestParameter('uri'));
66        $struct = $this->getClassService()->getFlatStructure(
67            $tree,
68            function ($label) {
69                return wordwrap($label, 30, "\n");
70            }
71        );
72        $this->returnJson($struct);
73    }
74
75    /**
76     * Renders a tree
77     * @requiresRight id READ
78     */
79    public function viewTree()
80    {
81
82        $this->setData('id', $this->getRequestParameter('id'));
83
84        $this->setView('Trees/viewTree.tpl');
85    }
86
87    /**
88     * Returns an empty view
89     */
90    public function dummy()
91    {
92    }
93
94    /**
95     * Populates the Tree of Trees
96     *
97     * @requiresRight classUri READ
98     */
99    public function getTreeData()
100    {
101        $data = [
102            'data' => __("Trees"),
103            'type' => 'class',
104            'attributes' => [
105                'id' => \tao_helpers_Uri::encode($this->getRootClass()->getUri()),
106                'class' => 'node-class',
107                'data-uri' => $this->getRootClass()->getUri()
108            ],
109
110        ];
111
112        $sublasses = $this->getRootClass()->getSubClasses(false);
113
114        if (count($sublasses)) {
115            $data['children'] = [];
116        }
117
118        foreach ($sublasses as $class) {
119            $data['children'][] = [
120                'data' => $class->getLabel(),
121                'type' => 'instance',
122                'attributes' => [
123                    'id' => \tao_helpers_Uri::encode($class->getUri()),
124                    'class' => 'node-instance',
125                    'data-uri' => $class->getUri()
126                ]
127            ];
128        }
129
130        //retrieve resources permissions
131        $user = $this->getSession()->getUser();
132        $permissions = $this->getResourceService()->getResourcesPermissions($user, $data);
133
134        //expose the tree
135        $this->returnJson([
136            'tree' => $data,
137            'permissions' => $permissions
138        ]);
139    }
140}