ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilObjStudyProgrammeTreeExplorerGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3require_once("./Services/UIComponent/Explorer2/classes/class.ilTreeExplorerGUI.php");
4require_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
5require_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
6require_once("./Services/UIComponent/Button/classes/class.ilLinkButton.php");
7require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php");
17 protected $js_study_programme_path = "./Modules/StudyProgramme/templates/js/ilStudyProgramme.js";
18 protected $css_study_programme_path = "./Modules/StudyProgramme/templates/css/ilStudyProgrammeTree.css";
19
23 //protected $stay_with_command = array( "", "render", "view", "infoScreen", "performPaste", "cut", "tree_view");
24
28 protected $tree_root_id;
29
33 protected $access;
37 protected $lng;
38
42 protected $tpl;
43
47 protected $toolbar;
48
52 protected $ctrl;
53
57 protected $modal_id;
58
62 protected $js_conf;
63
68 protected $class_configuration = array(
69 'node' => array(
70 'node_title' => 'title',
71 'node_point' => 'points',
72 'node_current' => 'ilHighlighted current_node',
73 'node_buttons' => 'tree_button'
74 ),
75 'lp_object' => 'lp-object',
76 );
77
78 protected $node_template;
79
86 public function __construct($a_tree_root_id, $modal_id, $a_expl_id, $a_parent_obj, $a_parent_cmd) {
87 global $DIC;
88 $ilAccess = $DIC['ilAccess'];
89 $lng = $DIC['lng'];
90 $tpl = $DIC['tpl'];
91 $ilToolbar = $DIC['ilToolbar'];
92 $ilCtrl = $DIC['ilCtrl'];
93
94 parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd);
95
96 $this->tree_root_id = $a_tree_root_id;
97
98 $this->access = $ilAccess;
99 $this->lng = $lng;
100 $this->tpl = $tpl;
101 $this->toolbar = $ilToolbar;
102 $this->ctrl = $ilCtrl;
103 $this->modal_id = $modal_id;
104 $this->js_conf = array();
105
106 $lng->loadLanguageModule("prg");
107
108 $this->setAjax(true);
109
110 if($this->checkAccess('write', $a_tree_root_id)) {
111 $this->setEnableDnd(true);
112 }
113 }
114
115
123 public function getNodeContent($node) {
124 global $DIC;
125 $lng = $DIC['lng'];
126 $ilAccess = $DIC['ilAccess'];
127
128 $current_ref_id = (isset($_GET["ref_id"]))? $_GET["ref_id"] : -1;
129
130 $is_current_node = ($node->getRefId() == $current_ref_id);
131 $is_study_programme = ($node instanceof ilObjStudyProgramme);
132 $is_root_node = ($is_study_programme && $node->getRoot() == null);
133
134 // show delete only on not current elements and not root
135 $is_delete_enabled = ($is_study_programme && ($is_current_node || $is_root_node))? false : $this->checkAccess("delete", $current_ref_id);
136
137 $is_creation_enabled = ($this->checkAccess("create", $current_ref_id));
138
139 $node_config = array(
140 'current_ref_id' =>$current_ref_id,
141 'is_current_node' => $is_current_node,
142 'is_delete_enabled' => $is_delete_enabled,
143 'is_creation_enabled' => $is_creation_enabled,
144 'is_study_programme' => $is_study_programme,
145 'is_root_node' => $is_root_node
146 );
147
148 // TODO: find way to remove a-tag around the content, to create valid html
149 $tpl = $this->getNodeTemplateInstance();
150
151 $tpl->setCurrentBlock('node-content-block');
152 $tpl->setVariable('NODE_TITLE_CLASSES', implode(' ', $this->getNodeTitleClasses($node_config)));
153 $tpl->setVariable('NODE_TITLE', $node->getTitle());
154
155 if($is_study_programme) {
156 $tpl->setVariable('NODE_POINT_CLASSES', $this->class_configuration['node']['node_point']);
157 $tpl->setVariable('NODE_POINTS', $this->formatPointValue($node->getPoints()));
158 }
159
160 $tpl->parseCurrentBlock('node-content-block');
161
162 // add the tree buttons
163 if($this->checkAccess('write', $node->getRefId())) {
164 if($is_study_programme) {
165 $this->parseStudyProgrammeNodeButtons($node, $node_config, $tpl);
166 } else {
167 $this->parseLeafNodeButtons($node, $node_config, $tpl);
168 }
169 }
170
171 return $tpl->get();
172 }
173
181 protected function getNodeTitleClasses($node_config) {
182 $node_title_classes = array($this->class_configuration['node']['node_title']);
183 if($node_config['is_study_programme']){
184 if ($node_config['is_current_node']) {
185 array_push($node_title_classes, $this->class_configuration['node']['node_current']);
186 }
187 } else {
188 array_push($node_title_classes, $this->class_configuration['lp_object']);
189 }
190
191 return $node_title_classes;
192 }
193
194
202 protected function parseStudyProgrammeNodeButtons($node, $node_config, $tpl) {
203 $tpl->setCurrentBlock('enable-tree-buttons');
204 $tpl->touchBlock('enable-tree-buttons');
205
206 // show info button only when it not the current node
207 $info_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeSettingsGUI', 'view', array('ref_id'=>$node->getRefId(), 'currentNode'=>$node_config['is_current_node']), ilGlyphGUI::get(ilGlyphGUI::INFO));
208 $tpl->setVariable('NODE_INFO_BUTTON', $info_button);
209
210 // only show add button when create permission is set
211 if($node_config['is_creation_enabled']) {
212 $create_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'create', array('ref_id'=>$node->getRefId()), ilGlyphGUI::get(ilGlyphGUI::ADD));
213 $tpl->setVariable('NODE_CREATE_BUTTON', $create_button);
214 }
215
216 // only show delete button when its not the current node, not the root-node and delete permissions are set
217 if($node_config['is_delete_enabled']) {
218 $delete_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'delete', array('ref_id'=>$node->getRefId(), 'item_ref_id'=>$node_config['current_ref_id']), ilGlyphGUI::get(ilGlyphGUI::REMOVE));
219 $tpl->setVariable('NODE_DELETE_BUTTON', $delete_button);
220 }
221
222 $tpl->parseCurrentBlock('enable-tree-buttons');
223 }
224
232 protected function parseLeafNodeButtons($node, $node_config, $tpl) {
233 $tpl->setCurrentBlock('enable-tree-buttons');
234 $tpl->touchBlock('enable-tree-buttons');
235
236 // only show delete button when its not the current node
237 if($node_config['is_delete_enabled']) {
238 $delete_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'delete', array('ref_id'=>$node->getRefId(), 'item_ref_id'=>$node_config['current_ref_id']), ilGlyphGUI::get(ilGlyphGUI::REMOVE));
239 $tpl->setVariable('NODE_DELETE_BUTTON', $delete_button);
240 }
241
242 $tpl->parseCurrentBlock('enable-tree-buttons');
243 }
244
250 protected function getNodeTemplateInstance() {
251 return new ilTemplate("tpl.tree_node_content.html", true, true, "Modules/StudyProgramme");
252 }
253
261 protected function formatPointValue($points) {
262 return '('. $points ." ".$this->lng->txt('prg_points').')';
263 }
264
276 protected function getNodeButtonActionLink($target_class, $cmd, $params, $content, $async = true) {
277 foreach($params as $param_name=>$param_value) {
278 $this->ctrl->setParameterByClass($target_class, $param_name, $param_value);
279 }
280
281 $tpl = $this->getNodeTemplateInstance();
282 //$tpl->free();
283 $tpl->setCurrentBlock('tree-button-block');
284
285 $classes = array($this->class_configuration['node']['node_buttons']);
286 $classes[] = 'cmd_'.$cmd;
287
288 $tpl->setVariable('LINK_HREF', $this->ctrl->getLinkTargetByClass($target_class, $cmd, '', true, false));
289 $tpl->setVariable('LINK_CLASSES', implode(' ', $classes));
290
291 if($async) {
292 $tpl->touchBlock('enable-async-link');
293 $tpl->setVariable('LINK_DATA_TARGET', '#'.$this->modal_id);
294 }
295
296 $tpl->setVariable('LINK_CONTENT', $content);
297
298 //$tpl->parseCurrentBlock('tree-button-block');
299
300 return $tpl->get();
301 }
302
308 public function getRootNode() {
309 $node = ilObjStudyProgramme::getInstanceByRefId($this->tree_root_id);
310 if($node->getRoot() != NULL) {
311 return $node->getRoot();
312 }
313 return $node;
314 }
315
324 public function getNodeIcon($a_node) {
325 global $DIC;
326 $ilias = $DIC['ilias'];
327
328 $obj_id = ilObject::_lookupObjId($a_node->getRefId());
329 if ($ilias->getSetting('custom_icons')) {
330 //TODO: implement custom icon functionality
331 }
332
333 return ilObject::_getIcon($obj_id, "tiny");
334 }
335
336
344 public function getNodeHref($node) {
345 global $DIC;
346 $ilCtrl = $DIC['ilCtrl'];
347
348 if ($ilCtrl->getCmd() == "performPaste") {
349 $ilCtrl->setParameterByClass("ilObjStudyProgrammeGUI", "target_node", $node->getRefId());
350 }
351
352 $ilCtrl->setParameterByClass("ilObjStudyProgrammeGUI", "ref_id", $node->getRefId());
353
354 return '#';
355 }
356
366 public function getChildsOfNode($a_parent_node_id) {
367 global $DIC;
368 $ilAccess = $DIC['ilAccess'];
369
370 $parent_obj = ilObjectFactoryWrapper::singleton()->getInstanceByRefId($a_parent_node_id);
371
372 $children_with_permission = array();
373
374 // its currently only possible to have children on StudyProgrammes
375 if($parent_obj instanceof ilObjStudyProgramme) {
376 $children = ($parent_obj->hasChildren())? $parent_obj->getChildren() : $parent_obj->getLPChildren();
377
378 if(is_array($children)) {
379 foreach($children as $node) {
380 if($this->checkAccess('visible', $node->getRefId())) {
381 $children_with_permission[] = $node;
382 }
383 }
384 }
385 }
386
387 return $children_with_permission;
388 }
389
398 public function isNodeClickable($a_node) {
399 return true;
400 }
401
402
410 public function getNodeId($a_node) {
411 if(!is_null($a_node)) {
412 return $a_node->getRefId();
413 }
414 return null;
415 }
416
423 public function listItemStart($tpl, $a_node)
424 {
425 $tpl->setCurrentBlock("list_item_start");
426
427 if ($this->getAjax() && $this->nodeHasVisibleChilds($a_node) || ($a_node instanceof ilStudyProgramme && $a_node->getParent() === null))
428 {
429 $tpl->touchBlock("li_closed");
430 }
431 $tpl->setVariable("DOM_NODE_ID",
432 $this->getDomNodeIdForNodeId($this->getNodeId($a_node)));
433 $tpl->parseCurrentBlock();
434 $tpl->touchBlock("tag");
435 }
436
437
444 public function getHTML() {
445 $this->tpl->addJavascript($this->js_study_programme_path);
446 $this->tpl->addCss($this->css_study_programme_path);
447
448 $this->tpl->addOnLoadCode('$("#'.$this->getContainerId().'").study_programme_tree('.json_encode($this->js_conf).');');
449
450 return parent::getHTML();
451 }
452
453
460 public function closeCertainNode($node_id) {
461 if (in_array($node_id, $this->open_nodes))
462 {
463 $k = array_search($node_id, $this->open_nodes);
464 unset($this->open_nodes[$k]);
465 }
466 $this->store->set("on_".$this->id, serialize($this->open_nodes));
467 }
468
475 public function openCertainNode($node_id) {
476 $id = $this->getNodeIdForDomNodeId($node_id);
477 if (!in_array($id, $this->open_nodes))
478 {
479 $this->open_nodes[] = $id;
480 }
481 $this->store->set("on_".$this->id, serialize($this->open_nodes));
482 }
483
484
493 protected function checkAccess($permission, $ref_id) {
494 $checker = $this->access->checkAccess($permission, '', $ref_id);
495
496 return $checker;
497 }
498
499
508 protected function checkAccessOrFail($permission, $ref_id) {
509 if(!$this->checkAccess($permission, $ref_id)) {
510 throw new ilException("You have no permission for ".$permission." Object with ref_id ".$ref_id."!");
511 }
512 }
513
519 public function addJsConf($key, $value) {
520 $this->js_conf[$key] = $value;
521 }
522
528 public function getJsConf($key) {
529 return $this->js_conf[$key];
530 }
531
532}
533
534?>
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Base class for ILIAS Exception handling.
Explorer base GUI class.
getContainerId()
Get container id.
setEnableDnd($enable_dnd)
Enable Drag & Drop functionality.
getDomNodeIdForNodeId($a_node_id)
Get DOM node id for node id.
getNodeIdForDomNodeId($a_dom_node_id)
Get node id for dom node id.
nodeHasVisibleChilds($a_node)
Node has childs?
static get($a_glyph, $a_text="")
Get glyph html.
Class ilStudyProgrammeTreeGUI ilObjStudyProgrammeTreeExplorerGUI generates the tree output for StudyP...
checkAccess($permission, $ref_id)
Checks permission of current tree or certain child of it.
openCertainNode($node_id)
Open certain node in the tree session The open nodes of a tree are stored in a session.
parseStudyProgrammeNodeButtons($node, $node_config, $tpl)
Generates the buttons for a study-programme node.
formatPointValue($points)
Returns formatted point value.
getJsConf($key)
Returns setting of the study-programme-tree.
closeCertainNode($node_id)
Closes certain node in the tree session The open nodes of a tree are stored in a session.
getNodeButtonActionLink($target_class, $cmd, $params, $content, $async=true)
Generate link-element.
getHTML()
Returns the output of the complete tree There are added some additional javascripts before output the...
getNodeTitleClasses($node_config)
Returns array with all css classes of the title node element.
checkAccessOrFail($permission, $ref_id)
Checks permission of a object and throws an exception if they are not granted.
parseLeafNodeButtons($node, $node_config, $tpl)
Generates the buttons for a study programme leaf.
addJsConf($key, $value)
Adds configuration to the study-programme-tree jquery plugin.
getNodeTemplateInstance()
Factory method for a new instance of a node template.
__construct($a_tree_root_id, $modal_id, $a_expl_id, $a_parent_obj, $a_parent_cmd)
getNodeIcon($a_node)
Get node icon Return custom icon of OrgUnit type if existing.
Class ilObjStudyProgramme.
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
static _lookupObjId($a_id)
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
Class ilStudyProgramme.
special template class to simplify handling of ITX/PEAR
$params
Definition: example_049.php:96
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
global $DIC