ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjStudyProgrammeTreeGUI.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("./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeTreeExplorerGUI.php");
4require_once("./Services/UIComponent/Modal/classes/class.ilModalGUI.php");
5require_once("./Services/Accordion/classes/class.ilAccordionGUI.php");
6require_once("./Modules/StudyProgramme/classes/helpers/class.ilAsyncContainerSelectionExplorer.php");
7require_once("./Modules/StudyProgramme/classes/helpers/class.ilAsyncPropertyFormGUI.php");
8require_once('./Services/Container/classes/class.ilContainerSorting.php');
9require_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
10require_once("./Modules/StudyProgramme/classes/helpers/class.ilAsyncNotifications.php");
11require_once("./Modules/CourseReference/classes/class.ilObjCourseReference.php");
12
21{
25 public $ctrl;
26
30 public $tpl;
31
35 protected $access;
36
40 public $object;
41
45 protected $log;
46
50 public $ilias;
51
55 public $lng;
56
61 protected $ref_id;
62
66 protected $tree;
67
72 protected $modal_id;
73
78
79 /*
80 * @var ilToolbar
81 */
82 public $toolbar;
83
84 public function __construct(
87 \ilAccess $ilAccess,
88 \ilToolbarGUI $ilToolbar,
93 ) {
94 $this->tpl = $tpl;
95 $this->ctrl = $ilCtrl;
96 $this->access = $ilAccess;
97 $this->toolbar = $ilToolbar;
98 $this->log = $ilLog;
99 $this->ilias = $ilias;
100 $this->lng = $lng;
101 $this->ilSetting = $ilSetting;
102
103 $this->modal_id = "tree_modal";
104 $this->async_output_handler = new ilAsyncOutputHandler();
105
106 $lng->loadLanguageModule("prg");
107 }
108
109
110 public function setRefId($a_ref_id)
111 {
112 $this->ref_id = $a_ref_id;
113 }
114
119 protected function initTree()
120 {
121 $this->tree = new ilObjStudyProgrammeTreeExplorerGUI($this->ref_id, $this->modal_id, "prg_tree", $this, 'view');
122
123 $js_url = rawurldecode($this->ctrl->getLinkTarget($this, 'saveTreeOrder', '', true, false));
124 $this->tree->addJsConf('save_tree_url', $js_url);
125 $this->tree->addJsConf('save_button_id', 'save_order_button');
126 $this->tree->addJsConf('cancel_button_id', 'cancel_order_button');
127 }
128
129
136 public function executeCommand()
137 {
138 $this->initTree();
139 $cmd = $this->ctrl->getCmd();
140
141 $this->getToolbar();
142
143 if ($cmd == "") {
144 $cmd = "view";
145 }
146
147 // handles tree commands ("openNode", "closeNode", "getNodeAsync")
148 if ($this->tree->handleCommand()) {
149 exit();
150 }
151
152 switch ($cmd) {
153 case "view":
154 case "create":
155 case "save":
156 case "cancel":
157 case "delete":
158 case "confirmedDelete":
159 case "cancelDelete":
160 case "getContainerSelectionExplorer":
161 case "saveTreeOrder":
162 case "createNewLeaf":
163
164 $content = $this->$cmd();
165 break;
166 default:
167 throw new ilException("ilObjStudyProgrammeTreeGUI: " .
168 "Command not supported: $cmd");
169 }
170
172 }
173
174
180 protected function view()
181 {
182 $output = $this->tree->getHTML();
183 $output .= $this->initAsyncUIElements();
184
185 return $output;
186 }
187
188
194 protected function cancel()
195 {
197 }
198
199
207 protected function saveTreeOrder()
208 {
209 $this->checkAccessOrFail('write');
210
211 $treeAsJson = ilUtil::stripSlashes($_POST['tree'] ?? '');
212 $treeData = json_decode($treeAsJson);
213
214 if (!is_array($treeData) || [] === $treeData) {
215 throw new ilStudyProgrammeTreeException("There is no tree data to save!");
216 }
217
218 // saves order recursive
219 $this->storeTreeOrder($treeData);
220
221 return ilAsyncOutputHandler::encodeAsyncResponse(array('success' => true, 'message' => $this->lng->txt('prg_saved_order_successful')));
222 }
223
224
232 protected function storeTreeOrder(array $nodes, $container_sorting = null, int $parent_ref_id = null)
233 {
234 $sorting_position = array();
235 $position_count = 10;
236
237 $parent_node = ($parent_ref_id === null)? ilObjectFactoryWrapper::singleton()->getInstanceByRefId($this->ref_id) : ilObjectFactoryWrapper::singleton()->getInstanceByRefId($parent_ref_id);
238 $container_sorting = ($container_sorting === null) ? ilContainerSorting::_getInstance(ilObject::_lookupObjectId($this->ref_id)) : $container_sorting;
239
240 foreach ($nodes as $node) {
241 // get ref_id from json
242 $id = $node->id;
243 $id = substr($id, strrpos($id, "_") + 1);
244
245 $sorting_position[$id] = $position_count;
246 $position_count += 10;
247
248 $node_obj = ilObjectFactoryWrapper::singleton()->getInstanceByRefId($id);
249 if ($node_obj instanceof ilObjStudyProgramme) {
250 $node_obj->moveTo($parent_node);
251 } else {
252 // TODO: implement a method on ilObjStudyProgramme to move leafs
253 global $DIC;
254 $tree = $DIC['tree'];
255 $rbacadmin = $DIC['rbacadmin'];
256
257 $tree->moveTree($node_obj->getRefId(), $parent_node->getRefId());
258 $rbacadmin->adjustMovedObjectPermissions($node_obj->getRefId(), $parent_node->getRefId());
259 }
260
261 // recursion if there are children
262 if (isset($node->children)) {
264 }
265 }
266 $container_sorting->savePost($sorting_position);
267 }
268
269
277 protected function createNewLeaf()
278 {
279 $this->checkAccessOrFail('create', (int) $_POST['parent_id']);
280
281 if (isset($_POST['target_id'], $_POST['type'], $_POST['parent_id'])) {
282 $target_id = (int) $_POST['target_id'];
283 $parent_id = (int) $_POST['parent_id'];
284
285 // TODO: more generic way for implementing different type of leafs
286 $course_ref = new ilObjCourseReference();
287 $course_ref->setTitleType(ilObjCourseReference::TITLE_TYPE_REUSE);
288 $course_ref->setTargetRefId($target_id);
289
290 $course_ref->create();
291 $course_ref->createReference();
292
293 $course_ref->putInTree($parent_id);
294
295 // This is how its done in ILIAS. If you set the target ID before the creation, it won't work
296 $course_ref->setTargetId(ilObject::_lookupObjectId($target_id));
297 $course_ref->update();
298 }
299
300 return ilAsyncOutputHandler::encodeAsyncResponse(array('success' => true, 'message' => $this->lng->txt('prg_added_course_ref_successful')));
301 }
302
303
311 protected function getContainerSelectionExplorer($convert_to_string = true)
312 {
313 $create_leaf_form = new ilAsyncContainerSelectionExplorer(rawurldecode($this->ctrl->getLinkTarget($this, 'createNewLeaf', '', true, false)));
314 $create_leaf_form->setId("select_course_explorer");
315
316 $ref_expand = ROOT_FOLDER_ID;
317 if (isset($_GET['ref_repexpand'])) {
318 $ref_expand = (int) $_GET['ref_repexpand'];
319 }
320
321 $create_leaf_form->setExpand($ref_expand);
322 $create_leaf_form->setExpandTarget($this->ctrl->getLinkTarget($this, 'getContainerSelectionExplorer'));
323 $create_leaf_form->setAsynchExpanding(true);
324 $create_leaf_form->setTargetGet('target_id');
325 $create_leaf_form->setFrameTarget("_self");
326 $create_leaf_form->setClickable('crs', true);
327 $create_leaf_form->setTargetType('crs');
328 $create_leaf_form->setOutput(0);
329
330 if ($convert_to_string) {
331 return $create_leaf_form->getOutput();
332 } else {
333 return $create_leaf_form;
334 }
335 }
336
337
343 protected function getCreationForm()
344 {
345 $tmp_obj = new ilObjStudyProgrammeGUI();
346
347 $create_node_form = $tmp_obj->getAsyncCreationForm();
348 $create_node_form->setTitle("");
349 $this->ctrl->setParameterByClass("ilobjstudyprogrammegui", "new_type", "prg");
350 $create_node_form->setFormAction($this->ctrl->getFormActionByClass("ilobjstudyprogrammegui", "save"));
351
352 return $create_node_form;
353 }
354
355
362 protected function create()
363 {
364 $parent_id = (isset($_GET['ref_id']))? (int) $_GET['ref_id'] : null;
365 $this->checkAccessOrFail('create', $parent_id);
366
367 $parent = ilObjectFactoryWrapper::singleton()->getInstanceByRefId($parent_id);
368 $accordion = new ilAccordionGUI();
369
370 $added_slides = 0;
371 if ($parent instanceof ilObjStudyProgramme) {
372 // only allow adding new StudyProgramme-Node if there are no lp-children
373 if (!$parent->hasLPChildren()) {
374 $content_new_node = $this->getCreationForm()->getHTML();
375 $accordion->addItem($this->lng->txt('prg_create_new_node'), $content_new_node);
376 $added_slides++;
377 }
378
379 /* only allow adding new LP-Children if there are no other StudyProgrammes
380 * AND creating crs references is activated in administration
381 */
382 if (!$parent->hasChildren() && $this->ilSetting->get("obj_dis_creation_crsr") === "") {
383 $content_new_leaf = ilUtil::getSystemMessageHTML($this->lng->txt('prg_please_select_a_course_for_creating_a_leaf'));
384 $content_new_leaf .= $this->getContainerSelectionExplorer();
385
386 $accordion->addItem($this->lng->txt('prg_create_new_leaf'), $content_new_leaf);
387 $added_slides++;
388 }
389
390 if ($added_slides == 1) {
391 $accordion->setBehaviour(ilAccordionGUI::FIRST_OPEN);
392 }
393
394 $content = $accordion->getHTML();
395 }
396
397 // creating modal window output
398 $this->async_output_handler->setHeading($this->lng->txt("prg_async_" . $this->ctrl->getCmd()));
399 $this->async_output_handler->setContent($content);
400 $this->async_output_handler->terminate();
401 }
402
403
409 protected function delete()
410 {
411 $this->checkAccessOrFail("delete");
412
413 if (!isset($_GET['ref_id'], $_GET['item_ref_id'])) {
414 throw new ilException("Nothing to delete!");
415 }
416
417 $element_ref_id = (int) $_GET['ref_id'];
418
419 $cgui = new ilConfirmationGUI();
420
421 $msg = $this->lng->txt("info_delete_sure");
422
423 if (!$this->ilSetting->get('enable_trash')) {
424 $msg .= "<br/>" . $this->lng->txt("info_delete_warning_no_trash");
425 }
426 $cgui->setFormAction($this->ctrl->getFormAction($this, 'confirmedDelete', '', true));
427 $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
428 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
429 $cgui->setFormName('async_form');
430
431 $obj_id = ilObject::_lookupObjectId($element_ref_id);
432 $type = ilObject::_lookupType($obj_id);
433 $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'), $obj_id);
434 $alt = $this->lng->txt("icon") . " " . $this->lng->txt("obj_" . $type);
435
436 $cgui->addItem(
437 "id[]",
438 $element_ref_id,
439 $title,
440 ilObject::_getIcon($obj_id, "small", $type),
441 $alt
442 );
443 $cgui->addHiddenItem('item_ref_id', $_GET['item_ref_id']);
444
445 $content = $cgui->getHTML();
446
447 // creating the modal window output
448 $this->async_output_handler->setHeading($msg);
449 $this->async_output_handler->setContent($content);
450 $this->async_output_handler->terminate();
451 }
452
453
460 protected function confirmedDelete()
461 {
462 $this->checkAccessOrFail("delete");
463
464 if (!isset($_POST['id'], $_POST['item_ref_id']) && is_array($_POST['id'])) {
465 throw new ilException("No item select for deletion!");
466 }
467
468 $ids = $_POST['id'];
469 $current_node = (int) $_POST['item_ref_id'];
470 $result = true;
471
472 foreach ($ids as $id) {
473 $obj = ilObjectFactoryWrapper::singleton()->getInstanceByRefId($id);
474
475 $not_parent_of_current = true;
476 $not_root = true;
477
478 // do some additional validation if it is a StudyProgramme
479 if ($obj instanceof ilObjStudyProgramme) {
480
481 //check if you are not deleting a parent element of the current element
482 $children_of_node = ilObjStudyProgramme::getAllChildren($obj->getRefId());
483 $get_ref_ids = function ($obj) {
484 return $obj->getRefId();
485 };
486
487 $children_ref_ids = array_map($get_ref_ids, $children_of_node);
488 $not_parent_of_current = (!in_array($current_node, $children_ref_ids));
489
490 $not_root = ($obj->getRoot() != null);
491 }
492
493 if ($current_node != $id && $not_root && $not_parent_of_current && $this->checkAccess('delete', $obj->getRefId())) {
494 ilRepUtil::deleteObjects(null, $id);
495
496 // deletes the tree-open-node-session storage
497 if (isset($children_of_node)) {
498 $this->tree->closeCertainNode($id);
499 foreach ($children_of_node as $child) {
500 $this->tree->closeCertainNode($child->getRefId());
501 }
502 }
503
504 $msg = $this->lng->txt("prg_deleted_safely");
505 } else {
506 $msg = $this->lng->txt("prg_not_allowed_node_to_delete");
507 $result = false;
508 }
509 }
510
511 return ilAsyncOutputHandler::encodeAsyncResponse(array('success' => $result, 'message' => $msg));
512 }
513
514
521 protected function cancelDelete()
522 {
524 }
525
526
533 protected function initAsyncUIElements()
534 {
535 // add js files
539
540 // add bootstrap modal
541 $settings_modal = ilModalGUI::getInstance();
542 $settings_modal->setId($this->modal_id);
543 $settings_modal->setType(ilModalGUI::TYPE_LARGE);
544 $this->tpl->addOnLoadCode('$("#' . $this->modal_id . '").study_programme_modal();');
545
546 $content = $settings_modal->getHTML();
547
548 // init js notifications
549 $notifications = new ilAsyncNotifications();
550 $notifications->addJsConfig('events', array('success' => array('study_programme-show_success')));
551 $notifications->initJs();
552
553 // init tree selection explorer
554 $async_explorer = new ilAsyncContainerSelectionExplorer(rawurldecode($this->ctrl->getLinkTarget($this, 'createNewLeaf', '', true, false)));
555 $async_explorer->initJs();
556
557 return $content;
558 }
559
560
564 protected function getToolbar()
565 {
566 $save_order_btn = ilLinkButton::getInstance();
567 $save_order_btn->setId('save_order_button');
568 $save_order_btn->setUrl("javascript:void(0);");
569 $save_order_btn->setOnClick("$('body').trigger('study_programme-save_order');");
570 $save_order_btn->setCaption('prg_save_tree_order');
571
572 $cancel_order_btn = ilLinkButton::getInstance();
573 $cancel_order_btn->setId('cancel_order_button');
574 $cancel_order_btn->setUrl("javascript:void(0);");
575 $cancel_order_btn->setOnClick("$('body').trigger('study_programme-cancel_order');");
576 $cancel_order_btn->setCaption('prg_cancel_tree_order');
577
578 $this->toolbar->addButtonInstance($save_order_btn);
579 $this->toolbar->addButtonInstance($cancel_order_btn);
580 }
581
582
591 protected function checkAccess($permission, $ref_id = null)
592 {
593 $ref_id = ($ref_id === null)? $this->ref_id : $ref_id;
594 $checker = $this->access->checkAccess($permission, '', $ref_id);
595
596 return $checker;
597 }
598
599
608 protected function checkAccessOrFail($permission, $ref_id = null)
609 {
610 if (!$this->checkAccess($permission, $ref_id)) {
611 throw new ilException("You have no permission for " . $permission . " Object with ref_id " . $ref_id . "!");
612 }
613 }
614}
$result
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class ilAccessHandler.
Accordion user interface class.
static addJavaScript(ilGlobalTemplate $main_tpl=null)
Add javascript files that are necessary to run accordion.
Class ilAsyncContainerSelectionExplorer A class for a async ilContainerSelectionExplorer which trigge...
static addJavascript()
Adds the javascript to template.
Class ilAsyncNotifications Allows to display async notifications on a page.
Class ilAsyncOutputHandler Handles the output for async-requests.
static handleAsyncOutput($normal_content, $async_content=null, $apply_to_tpl=true)
Handles async output.
static encodeAsyncResponse(array $data=array())
Encode data as json for async output.
static addJavaScript($add_form_loader=false, $js_base_path=null)
Adds all needed js By default is called by ilAsyncPropertyFormGUI::getHTML()
Component logger with individual log levels by component id.
Confirmation screen class.
static _getInstance($a_obj_id)
get instance by obj_id
This class provides processing control methods.
Base class for ILIAS Exception handling.
language handling
static getInstance()
Factory.
static getInstance()
Get instance.
Class ilObjStudyProgrammeGUI class.
Class ilStudyProgrammeTreeGUI ilObjStudyProgrammeTreeExplorerGUI generates the tree output for StudyP...
Class ilObjStudyProgrammeTreeGUI Generates the manage view for ilTrainingProgramme-Repository objects...
checkAccessOrFail($permission, $ref_id=null)
Checks permission of a object and throws an exception if they are not granted.
createNewLeaf()
Creates a new leaf Currently only course references can be created.
saveTreeOrder()
Saves tree node order Data is json encoded from the jstree component.
initAsyncUIElements()
Initializes all elements used for async-interaction Adds HTML-skeleton for the bootstrap modal dialog...
getCreationForm()
Returns the async creation form for StudyProgrammes.
executeCommand()
Execute GUI-commands If there is a async request the response is sent as a json string.
getContainerSelectionExplorer($convert_to_string=true)
Initialize the Course Explorer for creating a leaf.
create()
Generates the modal window content for the creation form of nodes or leafs If there are already Study...
cancelDelete()
Cancel deletion Return a json string for the async handling.
checkAccess($permission, $ref_id=null)
Checks permission of current tree or certain child of it.
confirmedDelete()
Deletes a node or a leaf in the tree.
storeTreeOrder(array $nodes, $container_sorting=null, int $parent_ref_id=null)
Recursive function for saving the tree order.
initTree()
Initialize Tree Creates tree instance and set tree configuration.
__construct(\ilGlobalTemplateInterface $tpl, \ilCtrl $ilCtrl, \ilAccess $ilAccess, \ilToolbarGUI $ilToolbar, \ilLanguage $lng, \ilComponentLogger $ilLog, \ILIAS $ilias, \ilSetting $ilSetting)
static getAllChildren(int $a_ref_id, bool $include_references=false)
Get a list of all ilObjStudyProgrammes in the subtree starting at $a_ref_id.
static getClassByType($a_obj_type)
Get class by type.
static _lookupObjectId($a_ref_id)
lookup object id
static _lookupType($a_id, $a_reference=false)
lookup object type
static deleteObjects($a_cur_ref_id, $a_ids)
Delete objects.
ILIAS Setting Class.
get($a_keyword, $a_default_value=false)
get setting
Exception is thrown when invariants on the program tree would be violated by manipulation of tree.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static getSystemMessageHTML($a_txt, $a_type="info")
Get HTML for a system message.
$target_id
Definition: goto.php:49
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:29
Class ChatMainBarProvider \MainMenu\Provider.
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
$type
$DIC
Definition: xapitoken.php:46