ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $ilAccess, $lng, $tpl, $ilToolbar, $ilCtrl;
88
89 parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd);
90
91 $this->tree_root_id = $a_tree_root_id;
92
93 $this->access = $ilAccess;
94 $this->lng = $lng;
95 $this->tpl = $tpl;
96 $this->toolbar = $ilToolbar;
97 $this->ctrl = $ilCtrl;
98 $this->modal_id = $modal_id;
99 $this->js_conf = array();
100
101 $lng->loadLanguageModule("prg");
102
103 $this->setAjax(true);
104
105 if($this->checkAccess('write', $a_tree_root_id)) {
106 $this->setEnableDnd(true);
107 }
108 }
109
110
118 public function getNodeContent($node) {
119 global $lng, $ilAccess;
120
121 $current_ref_id = (isset($_GET["ref_id"]))? $_GET["ref_id"] : -1;
122
123 $is_current_node = ($node->getRefId() == $current_ref_id);
124 $is_study_programme = ($node instanceof ilObjStudyProgramme);
125 $is_root_node = ($is_study_programme && $node->getRoot() == null);
126
127 // show delete only on not current elements and not root
128 $is_delete_enabled = ($is_study_programme && ($is_current_node || $is_root_node))? false : $this->checkAccess("delete", $current_ref_id);
129
130 $is_creation_enabled = ($this->checkAccess("create", $current_ref_id));
131
132 $node_config = array(
133 'current_ref_id' =>$current_ref_id,
134 'is_current_node' => $is_current_node,
135 'is_delete_enabled' => $is_delete_enabled,
136 'is_creation_enabled' => $is_creation_enabled,
137 'is_study_programme' => $is_study_programme,
138 'is_root_node' => $is_root_node
139 );
140
141 // TODO: find way to remove a-tag around the content, to create valid html
142 $tpl = $this->getNodeTemplateInstance();
143
144 $tpl->setCurrentBlock('node-content-block');
145 $tpl->setVariable('NODE_TITLE_CLASSES', implode(' ', $this->getNodeTitleClasses($node_config)));
146 $tpl->setVariable('NODE_TITLE', $node->getTitle());
147
148 if($is_study_programme) {
149 $tpl->setVariable('NODE_POINT_CLASSES', $this->class_configuration['node']['node_point']);
150 $tpl->setVariable('NODE_POINTS', $this->formatPointValue($node->getPoints()));
151 }
152
153 $tpl->parseCurrentBlock('node-content-block');
154
155 // add the tree buttons
156 if($this->checkAccess('write', $node->getRefId())) {
157 if($is_study_programme) {
158 $this->parseStudyProgrammeNodeButtons($node, $node_config, $tpl);
159 } else {
160 $this->parseLeafNodeButtons($node, $node_config, $tpl);
161 }
162 }
163
164 return $tpl->get();
165 }
166
174 protected function getNodeTitleClasses($node_config) {
175 $node_title_classes = array($this->class_configuration['node']['node_title']);
176 if($node_config['is_study_programme']){
177 if ($node_config['is_current_node']) {
178 array_push($node_title_classes, $this->class_configuration['node']['node_current']);
179 }
180 } else {
181 array_push($node_title_classes, $this->class_configuration['lp_object']);
182 }
183
184 return $node_title_classes;
185 }
186
187
195 protected function parseStudyProgrammeNodeButtons($node, $node_config, $tpl) {
196 $tpl->setCurrentBlock('enable-tree-buttons');
197 $tpl->touchBlock('enable-tree-buttons');
198
199 // show info button only when it not the current node
200 $info_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeSettingsGUI', 'view', array('ref_id'=>$node->getRefId(), 'currentNode'=>$node_config['is_current_node']), ilGlyphGUI::get(ilGlyphGUI::INFO));
201 $tpl->setVariable('NODE_INFO_BUTTON', $info_button);
202
203 // only show add button when create permission is set
204 if($node_config['is_creation_enabled']) {
205 $create_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'create', array('ref_id'=>$node->getRefId()), ilGlyphGUI::get(ilGlyphGUI::ADD));
206 $tpl->setVariable('NODE_CREATE_BUTTON', $create_button);
207 }
208
209 // only show delete button when its not the current node, not the root-node and delete permissions are set
210 if($node_config['is_delete_enabled']) {
211 $delete_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'delete', array('ref_id'=>$node->getRefId(), 'item_ref_id'=>$node_config['current_ref_id']), ilGlyphGUI::get(ilGlyphGUI::REMOVE));
212 $tpl->setVariable('NODE_DELETE_BUTTON', $delete_button);
213 }
214
215 $tpl->parseCurrentBlock('enable-tree-buttons');
216 }
217
225 protected function parseLeafNodeButtons($node, $node_config, $tpl) {
226 $tpl->setCurrentBlock('enable-tree-buttons');
227 $tpl->touchBlock('enable-tree-buttons');
228
229 // only show delete button when its not the current node
230 if($node_config['is_delete_enabled']) {
231 $delete_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'delete', array('ref_id'=>$node->getRefId(), 'item_ref_id'=>$node_config['current_ref_id']), ilGlyphGUI::get(ilGlyphGUI::REMOVE));
232 $tpl->setVariable('NODE_DELETE_BUTTON', $delete_button);
233 }
234
235 $tpl->parseCurrentBlock('enable-tree-buttons');
236 }
237
243 protected function getNodeTemplateInstance() {
244 return new ilTemplate("tpl.tree_node_content.html", true, true, "Modules/StudyProgramme");
245 }
246
254 protected function formatPointValue($points) {
255 return '('. $points ." ".$this->lng->txt('prg_points').')';
256 }
257
269 protected function getNodeButtonActionLink($target_class, $cmd, $params, $content, $async = true) {
270 foreach($params as $param_name=>$param_value) {
271 $this->ctrl->setParameterByClass($target_class, $param_name, $param_value);
272 }
273
274 $tpl = $this->getNodeTemplateInstance();
275 //$tpl->free();
276 $tpl->setCurrentBlock('tree-button-block');
277
278 $classes = array($this->class_configuration['node']['node_buttons']);
279 $classes[] = 'cmd_'.$cmd;
280
281 $tpl->setVariable('LINK_HREF', $this->ctrl->getLinkTargetByClass($target_class, $cmd, '', true, false));
282 $tpl->setVariable('LINK_CLASSES', implode(' ', $classes));
283
284 if($async) {
285 $tpl->touchBlock('enable-async-link');
286 $tpl->setVariable('LINK_DATA_TARGET', '#'.$this->modal_id);
287 }
288
289 $tpl->setVariable('LINK_CONTENT', $content);
290
291 //$tpl->parseCurrentBlock('tree-button-block');
292
293 return $tpl->get();
294 }
295
301 public function getRootNode() {
302 $node = ilObjStudyProgramme::getInstanceByRefId($this->tree_root_id);
303 if($node->getRoot() != NULL) {
304 return $node->getRoot();
305 }
306 return $node;
307 }
308
317 public function getNodeIcon($a_node) {
318 global $ilias;
319
320 $obj_id = ilObject::_lookupObjId($a_node->getRefId());
321 if ($ilias->getSetting('custom_icons')) {
322 //TODO: implement custom icon functionality
323 }
324
325 return ilObject::_getIcon($obj_id, "tiny");
326 }
327
328
336 public function getNodeHref($node) {
337 global $ilCtrl;
338
339 if ($ilCtrl->getCmd() == "performPaste") {
340 $ilCtrl->setParameterByClass("ilObjStudyProgrammeGUI", "target_node", $node->getRefId());
341 }
342
343 $ilCtrl->setParameterByClass("ilObjStudyProgrammeGUI", "ref_id", $node->getRefId());
344
345 return '#';
346 }
347
357 public function getChildsOfNode($a_parent_node_id) {
358 global $ilAccess;
359
360 $parent_obj = ilObjectFactoryWrapper::singleton()->getInstanceByRefId($a_parent_node_id);
361
362 $children_with_permission = array();
363
364 // its currently only possible to have children on StudyProgrammes
365 if($parent_obj instanceof ilObjStudyProgramme) {
366 $children = ($parent_obj->hasChildren())? $parent_obj->getChildren() : $parent_obj->getLPChildren();
367
368 if(is_array($children)) {
369 foreach($children as $node) {
370 if($this->checkAccess('visible', $node->getRefId())) {
371 $children_with_permission[] = $node;
372 }
373 }
374 }
375 }
376
377 return $children_with_permission;
378 }
379
388 public function isNodeClickable($a_node) {
389 return true;
390 }
391
392
400 public function getNodeId($a_node) {
401 if(!is_null($a_node)) {
402 return $a_node->getRefId();
403 }
404 return null;
405 }
406
413 public function listItemStart($tpl, $a_node)
414 {
415 $tpl->setCurrentBlock("list_item_start");
416
417 if ($this->getAjax() && $this->nodeHasVisibleChilds($a_node) || ($a_node instanceof ilStudyProgramme && $a_node->getParent() === null))
418 {
419 $tpl->touchBlock("li_closed");
420 }
421 $tpl->setVariable("DOM_NODE_ID",
422 $this->getDomNodeIdForNodeId($this->getNodeId($a_node)));
423 $tpl->parseCurrentBlock();
424 $tpl->touchBlock("tag");
425 }
426
427
434 public function getHTML() {
435 $this->tpl->addJavascript($this->js_study_programme_path);
436 $this->tpl->addCss($this->css_study_programme_path);
437
438 $this->tpl->addOnLoadCode('$("#'.$this->getContainerId().'").study_programme_tree('.json_encode($this->js_conf).');');
439
440 return parent::getHTML();
441 }
442
443
450 public function closeCertainNode($node_id) {
451 if (in_array($node_id, $this->open_nodes))
452 {
453 $k = array_search($node_id, $this->open_nodes);
454 unset($this->open_nodes[$k]);
455 }
456 $this->store->set("on_".$this->id, serialize($this->open_nodes));
457 }
458
465 public function openCertainNode($node_id) {
466 $id = $this->getNodeIdForDomNodeId($node_id);
467 if (!in_array($id, $this->open_nodes))
468 {
469 $this->open_nodes[] = $id;
470 }
471 $this->store->set("on_".$this->id, serialize($this->open_nodes));
472 }
473
474
483 protected function checkAccess($permission, $ref_id) {
484 $checker = $this->access->checkAccess($permission, '', $ref_id);
485
486 return $checker;
487 }
488
489
498 protected function checkAccessOrFail($permission, $ref_id) {
499 if(!$this->checkAccess($permission, $ref_id)) {
500 throw new ilException("You have no permission for ".$permission." Object with ref_id ".$ref_id."!");
501 }
502 }
503
509 public function addJsConf($key, $value) {
510 $this->js_conf[$key] = $value;
511 }
512
518 public function getJsConf($key) {
519 return $this->js_conf[$key];
520 }
521
522}
523
524?>
$_GET["client_id"]
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