ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 */
3 require_once("./Services/UIComponent/Explorer2/classes/class.ilTreeExplorerGUI.php");
4 require_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
5 require_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
6 require_once("./Services/UIComponent/Button/classes/class.ilLinkButton.php");
7 require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeSettingsGUI.php");
17 {
18  protected $js_study_programme_path = "./Modules/StudyProgramme/templates/js/ilStudyProgramme.js";
19  protected $css_study_programme_path = "./Modules/StudyProgramme/templates/css/ilStudyProgrammeTree.css";
20 
24  //protected $stay_with_command = array( "", "render", "view", "infoScreen", "performPaste", "cut", "tree_view");
25 
29  protected $tree_root_id;
30 
34  protected $access;
38  protected $lng;
39 
43  protected $tpl;
44 
48  protected $toolbar;
49 
53  protected $ctrl;
54 
58  protected $modal_id;
59 
63  protected $js_conf;
64 
70  'node' => array(
71  'node_title' => 'title',
72  'node_point' => 'points',
73  'node_current' => 'ilHighlighted current_node',
74  'node_buttons' => 'tree_button'
75  ),
76  'lp_object' => 'lp-object',
77  );
78 
79  protected $node_template;
80 
87  public function __construct($a_tree_root_id, $modal_id, $a_expl_id, $a_parent_obj, $a_parent_cmd)
88  {
89  global $DIC;
90  $ilAccess = $DIC['ilAccess'];
91  $lng = $DIC['lng'];
92  $tpl = $DIC['tpl'];
93  $ilToolbar = $DIC['ilToolbar'];
94  $ilCtrl = $DIC['ilCtrl'];
95 
96  parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd);
97 
98  $this->tree_root_id = $a_tree_root_id;
99 
100  $this->access = $ilAccess;
101  $this->lng = $lng;
102  $this->tpl = $tpl;
103  $this->toolbar = $ilToolbar;
104  $this->ctrl = $ilCtrl;
105  $this->modal_id = $modal_id;
106  $this->js_conf = array();
107 
108  $lng->loadLanguageModule("prg");
109 
110  $this->setAjax(true);
111 
112  if ($this->checkAccess('write', $a_tree_root_id)) {
113  $this->setEnableDnd(true);
114  }
115  }
116 
117 
125  public function getNodeContent($node)
126  {
127  global $DIC;
128  $lng = $DIC['lng'];
129  $ilAccess = $DIC['ilAccess'];
130 
131  $current_ref_id = (isset($_GET["ref_id"]))? $_GET["ref_id"] : -1;
132 
133  $is_current_node = ($node->getRefId() == $current_ref_id);
134  $is_study_programme = ($node instanceof ilObjStudyProgramme);
135  $is_root_node = ($is_study_programme && $node->getRoot() == null);
136 
137  // show delete only on not current elements and not root
138  $is_delete_enabled = ($is_study_programme && ($is_current_node || $is_root_node))? false : $this->checkAccess("delete", $current_ref_id);
139 
140  $is_creation_enabled = ($this->checkAccess("create", $current_ref_id));
141 
142  $node_config = array(
143  'current_ref_id' =>$current_ref_id,
144  'is_current_node' => $is_current_node,
145  'is_delete_enabled' => $is_delete_enabled,
146  'is_creation_enabled' => $is_creation_enabled,
147  'is_study_programme' => $is_study_programme,
148  'is_root_node' => $is_root_node
149  );
150 
151  // TODO: find way to remove a-tag around the content, to create valid html
152  $tpl = $this->getNodeTemplateInstance();
153 
154  $tpl->setCurrentBlock('node-content-block');
155  $tpl->setVariable('NODE_TITLE_CLASSES', implode(' ', $this->getNodeTitleClasses($node_config)));
156  $tpl->setVariable('NODE_TITLE', $node->getTitle());
157 
158  if ($is_study_programme) {
159  $tpl->setVariable('NODE_POINT_CLASSES', $this->class_configuration['node']['node_point']);
160  $tpl->setVariable('NODE_POINTS', $this->formatPointValue($node->getPoints()));
161  }
162 
163  $tpl->parseCurrentBlock('node-content-block');
164 
165  // add the tree buttons
166  if ($this->checkAccess('write', $node->getRefId())) {
167  if ($is_study_programme) {
168  $this->parseStudyProgrammeNodeButtons($node, $node_config, $tpl);
169  } else {
170  $this->parseLeafNodeButtons($node, $node_config, $tpl);
171  }
172  }
173 
174  return $tpl->get();
175  }
176 
184  protected function getNodeTitleClasses($node_config)
185  {
186  $node_title_classes = array($this->class_configuration['node']['node_title']);
187  if ($node_config['is_study_programme']) {
188  if ($node_config['is_current_node']) {
189  array_push($node_title_classes, $this->class_configuration['node']['node_current']);
190  }
191  } else {
192  array_push($node_title_classes, $this->class_configuration['lp_object']);
193  }
194 
195  return $node_title_classes;
196  }
197 
198 
206  protected function parseStudyProgrammeNodeButtons($node, $node_config, $tpl)
207  {
208  $tpl->setCurrentBlock('enable-tree-buttons');
209  $tpl->touchBlock('enable-tree-buttons');
210 
211  // show info button only when it not the current node
212  $info_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeSettingsGUI', 'view', array('ref_id'=>$node->getRefId(), 'currentNode'=>$node_config['is_current_node']), ilGlyphGUI::get(ilGlyphGUI::INFO));
213  $tpl->setVariable('NODE_INFO_BUTTON', $info_button);
214 
215  // only show add button when create permission is set
216  if ($node_config['is_creation_enabled']) {
217  $create_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'create', array('ref_id'=>$node->getRefId()), ilGlyphGUI::get(ilGlyphGUI::ADD));
218  $tpl->setVariable('NODE_CREATE_BUTTON', $create_button);
219  }
220 
221  // only show delete button when its not the current node, not the root-node and delete permissions are set
222  if ($node_config['is_delete_enabled']) {
223  $delete_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'delete', array('ref_id'=>$node->getRefId(), 'item_ref_id'=>$node_config['current_ref_id']), ilGlyphGUI::get(ilGlyphGUI::REMOVE));
224  $tpl->setVariable('NODE_DELETE_BUTTON', $delete_button);
225  }
226 
227  $tpl->parseCurrentBlock('enable-tree-buttons');
228  }
229 
237  protected function parseLeafNodeButtons($node, $node_config, $tpl)
238  {
239  $tpl->setCurrentBlock('enable-tree-buttons');
240  $tpl->touchBlock('enable-tree-buttons');
241 
242  // only show delete button when its not the current node
243  if ($node_config['is_delete_enabled']) {
244  $delete_button = $this->getNodeButtonActionLink('ilObjStudyProgrammeTreeGUI', 'delete', array('ref_id'=>$node->getRefId(), 'item_ref_id'=>$node_config['current_ref_id']), ilGlyphGUI::get(ilGlyphGUI::REMOVE));
245  $tpl->setVariable('NODE_DELETE_BUTTON', $delete_button);
246  }
247 
248  $tpl->parseCurrentBlock('enable-tree-buttons');
249  }
250 
256  protected function getNodeTemplateInstance()
257  {
258  return new ilTemplate("tpl.tree_node_content.html", true, true, "Modules/StudyProgramme");
259  }
260 
268  protected function formatPointValue($points)
269  {
270  return '(' . $points . " " . $this->lng->txt('prg_points') . ')';
271  }
272 
284  protected function getNodeButtonActionLink($target_class, $cmd, $params, $content, $async = true)
285  {
286  foreach ($params as $param_name=>$param_value) {
287  $this->ctrl->setParameterByClass($target_class, $param_name, $param_value);
288  }
289 
290  $tpl = $this->getNodeTemplateInstance();
291  //$tpl->free();
292  $tpl->setCurrentBlock('tree-button-block');
293 
294  $classes = array($this->class_configuration['node']['node_buttons']);
295  $classes[] = 'cmd_' . $cmd;
296 
297  $tpl->setVariable('LINK_HREF', $this->ctrl->getLinkTargetByClass($target_class, $cmd, '', true, false));
298  $tpl->setVariable('LINK_CLASSES', implode(' ', $classes));
299 
300  if ($async) {
301  $tpl->touchBlock('enable-async-link');
302  $tpl->setVariable('LINK_DATA_TARGET', '#' . $this->modal_id);
303  }
304 
305  $tpl->setVariable('LINK_CONTENT', $content);
306 
307  //$tpl->parseCurrentBlock('tree-button-block');
308 
309  return $tpl->get();
310  }
311 
317  public function getRootNode()
318  {
319  $node = ilObjStudyProgramme::getInstanceByRefId($this->tree_root_id);
320  if ($node->getRoot() != null) {
321  return $node->getRoot();
322  }
323  return $node;
324  }
325 
334  public function getNodeIcon($a_node)
335  {
336  global $DIC;
337  $ilias = $DIC['ilias'];
338 
339  $obj_id = ilObject::_lookupObjId($a_node->getRefId());
340  if ($ilias->getSetting('custom_icons')) {
341  //TODO: implement custom icon functionality
342  }
343 
344  return ilObject::_getIcon($obj_id, "tiny");
345  }
346 
347 
355  public function getNodeHref($node)
356  {
357  global $DIC;
358  $ilCtrl = $DIC['ilCtrl'];
359 
360  if ($ilCtrl->getCmd() == "performPaste") {
361  $ilCtrl->setParameterByClass("ilObjStudyProgrammeGUI", "target_node", $node->getRefId());
362  }
363 
364  $ilCtrl->setParameterByClass("ilObjStudyProgrammeGUI", "ref_id", $node->getRefId());
365 
366  return '#';
367  }
368 
378  public function getChildsOfNode($a_parent_node_id)
379  {
380  global $DIC;
381  $ilAccess = $DIC['ilAccess'];
382 
383  $parent_obj = ilObjectFactoryWrapper::singleton()->getInstanceByRefId($a_parent_node_id);
384 
385  $children_with_permission = array();
386 
387  // its currently only possible to have children on StudyProgrammes
388  if ($parent_obj instanceof ilObjStudyProgramme) {
389  $children = ($parent_obj->hasChildren())? $parent_obj->getChildren() : $parent_obj->getLPChildren();
390 
391  if (is_array($children)) {
392  foreach ($children as $node) {
393  if ($this->checkAccess('visible', $node->getRefId())) {
394  $children_with_permission[] = $node;
395  }
396  }
397  }
398  }
399 
400  return $children_with_permission;
401  }
402 
411  public function isNodeClickable($a_node)
412  {
413  return true;
414  }
415 
416 
424  public function getNodeId($a_node)
425  {
426  if (!is_null($a_node)) {
427  return $a_node->getRefId();
428  }
429  return null;
430  }
431 
438  public function listItemStart($tpl, $a_node)
439  {
440  $tpl->setCurrentBlock("list_item_start");
441 
442  if ($this->getAjax() && $this->nodeHasVisibleChilds($a_node) || ($a_node instanceof ilStudyProgramme && $a_node->getParent() === null)) {
443  $tpl->touchBlock("li_closed");
444  }
445  $tpl->setVariable(
446  "DOM_NODE_ID",
447  $this->getDomNodeIdForNodeId($this->getNodeId($a_node))
448  );
449  $tpl->parseCurrentBlock();
450  $tpl->touchBlock("tag");
451  }
452 
453 
460  public function getHTML()
461  {
462  $this->tpl->addJavascript($this->js_study_programme_path);
463  $this->tpl->addCss($this->css_study_programme_path);
464 
465  $this->tpl->addOnLoadCode('$("#' . $this->getContainerId() . '").study_programme_tree(' . json_encode($this->js_conf) . ');');
466 
467  return parent::getHTML();
468  }
469 
470 
477  public function closeCertainNode($node_id)
478  {
479  if (in_array($node_id, $this->open_nodes)) {
480  $k = array_search($node_id, $this->open_nodes);
481  unset($this->open_nodes[$k]);
482  }
483  $this->store->set("on_" . $this->id, serialize($this->open_nodes));
484  }
485 
492  public function openCertainNode($node_id)
493  {
494  $id = $this->getNodeIdForDomNodeId($node_id);
495  if (!in_array($id, $this->open_nodes)) {
496  $this->open_nodes[] = $id;
497  }
498  $this->store->set("on_" . $this->id, serialize($this->open_nodes));
499  }
500 
501 
510  protected function checkAccess($permission, $ref_id)
511  {
512  $checker = $this->access->checkAccess($permission, '', $ref_id);
513 
514  return $checker;
515  }
516 
517 
526  protected function checkAccessOrFail($permission, $ref_id)
527  {
528  if (!$this->checkAccess($permission, $ref_id)) {
529  throw new ilException("You have no permission for " . $permission . " Object with ref_id " . $ref_id . "!");
530  }
531  }
532 
538  public function addJsConf($key, $value)
539  {
540  $this->js_conf[$key] = $value;
541  }
542 
548  public function getJsConf($key)
549  {
550  return $this->js_conf[$key];
551  }
552 }
$params
Definition: disable.php:11
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
checkAccess($permission, $ref_id)
Checks permission of current tree or certain child of it.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
Class ilStudyProgramme.
if(!array_key_exists('StateId', $_REQUEST)) $id
static get($a_glyph, $a_text="")
Get glyph html.
getJsConf($key)
Returns setting of the study-programme-tree.
getNodeIcon($a_node)
Get node icon Return custom icon of OrgUnit type if existing.
global $ilCtrl
Definition: ilias.php:18
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
setEnableDnd($enable_dnd)
Enable Drag & Drop functionality.
getNodeTemplateInstance()
Factory method for a new instance of a node template.
Explorer base GUI class.
getHTML()
Returns the output of the complete tree There are added some additional javascripts before output the...
Class ilObjStudyProgramme.
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
openCertainNode($node_id)
Open certain node in the tree session The open nodes of a tree are stored in a session.
formatPointValue($points)
Returns formatted point value.
closeCertainNode($node_id)
Closes 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.
getNodeButtonActionLink($target_class, $cmd, $params, $content, $async=true)
Generate link-element.
Create styles array
The data for the language used.
getChildsOfNode($a_parent_node_id)
Get childs of node.
addJsConf($key, $value)
Adds configuration to the study-programme-tree jquery plugin.
__construct($a_tree_root_id, $modal_id, $a_expl_id, $a_parent_obj, $a_parent_cmd)
Class ilStudyProgrammeTreeGUI ilObjStudyProgrammeTreeExplorerGUI generates the tree output for StudyP...
getDomNodeIdForNodeId($a_node_id)
Get DOM node id for node id.
nodeHasVisibleChilds($a_node)
Node has childs?
$key
Definition: croninfo.php:18
getNodeIdForDomNodeId($a_dom_node_id)
Get node id for dom node id.
parseLeafNodeButtons($node, $node_config, $tpl)
Generates the buttons for a study programme leaf.
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.
getContainerId()
Get container id.