ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
24 public $ctrl;
25
29 public $tpl;
30
34 protected $access;
35
39 public $object;
43 protected $locator;
44
48 protected $log;
49
53 public $ilias;
54
58 public $lng;
59
64 protected $ref_id;
65
69 protected $tree;
70
75 protected $modal_id;
76
81
82 /*
83 * @var ilToolbar
84 */
85 public $toolbar;
86
87 public function __construct($a_ref_id) {
88 global $tpl, $ilCtrl, $ilAccess, $ilToolbar, $ilLocator, $tree, $lng, $ilLog, $ilias;
89
90 $this->ref_id = $a_ref_id;
91 $this->tpl = $tpl;
92 $this->ctrl = $ilCtrl;
93 $this->access = $ilAccess;
94 $this->locator = $ilLocator;
95 $this->tree = $tree;
96 $this->toolbar = $ilToolbar;
97 $this->log = $ilLog;
98 $this->ilias = $ilias;
99 $this->lng = $lng;
100 $this->modal_id = "tree_modal";
101 $this->async_output_handler = new ilAsyncOutputHandler();
102
103 $this->initTree();
104
105 $lng->loadLanguageModule("prg");
106 }
107
108
113 protected function initTree() {
114 $this->tree = new ilObjStudyProgrammeTreeExplorerGUI($this->ref_id, $this->modal_id, "prg_tree", $this, 'view');
115
116 $js_url = rawurldecode($this->ctrl->getLinkTarget($this, 'saveTreeOrder', '', true, false));
117 $this->tree->addJsConf('save_tree_url', $js_url);
118 $this->tree->addJsConf('save_button_id', 'save_order_button');
119 $this->tree->addJsConf('cancel_button_id', 'cancel_order_button');
120 }
121
122
129 public function executeCommand() {
130 $cmd = $this->ctrl->getCmd();
131
132 $this->getToolbar();
133
134 if ($cmd == "") {
135 $cmd = "view";
136 }
137
138 // handles tree commands ("openNode", "closeNode", "getNodeAsync")
139 if($this->tree->handleCommand()) {
140 exit();
141 }
142
143 switch ($cmd) {
144 case "view":
145 case "create":
146 case "save":
147 case "cancel":
148 case "delete":
149 case "confirmedDelete":
150 case "cancelDelete":
151 case "getContainerSelectionExplorer":
152 case "saveTreeOrder":
153 case "createNewLeaf":
154
155 $content = $this->$cmd();
156 break;
157 default:
158 throw new ilException("ilObjStudyProgrammeTreeGUI: ".
159 "Command not supported: $cmd");
160 }
161
163 }
164
165
171 protected function view() {
172
173 $output = $this->tree->getHTML();
174 $output .= $this->initAsyncUIElements();
175
176 return $output;
177 }
178
179
185 protected function cancel() {
187 }
188
189
197 protected function saveTreeOrder() {
198 $this->checkAccessOrFail('write');
199
200 if(!isset($_POST['tree']) || is_null(json_decode(stripslashes($_POST['tree'])))) {
201 throw new ilStudyProgrammeTreeException("There is no tree data to save!");
202 }
203
204 // saves order recursive
205 $this->storeTreeOrder(json_decode(stripslashes($_POST['tree'])));
206
207 return ilAsyncOutputHandler::encodeAsyncResponse(array('success'=>true, 'message'=>$this->lng->txt('prg_saved_order_successful')));
208 }
209
210
218 protected function storeTreeOrder($nodes, $container_sorting = null, $parent_ref_id = null) {
219 $sorting_position = array();
220 $position_count = 10;
221
222 $parent_node = ($parent_ref_id === null)? ilObjectFactoryWrapper::getInstanceByRefId($this->ref_id) : ilObjectFactoryWrapper::getInstanceByRefId($parent_ref_id);
223 $container_sorting = ($container_sorting === null) ? ilContainerSorting::_getInstance(ilObject::_lookupObjectId($this->ref_id)) : $container_sorting;
224
225 foreach($nodes as $node) {
226 // get ref_id from json
227 $id = $node->attr->id;
228 $id = substr($id, strrpos($id, "_")+1);
229
230 $sorting_position[$id] = $position_count;
231 $position_count+= 10;
232
234 if($node_obj instanceof ilObjStudyProgramme) {
235 $node_obj->moveTo($parent_node);
236 } else {
237 // TODO: implement a method on ilObjStudyProgramme to move leafs
238 global $tree, $rbacadmin;
239
240 $tree->moveTree($node_obj->getRefId(), $parent_node->getRefId());
241 $rbacadmin->adjustMovedObjectPermissions($node_obj->getRefId(), $parent_node->getRefId());
242 }
243
244 // recursion if there are children
245 if(isset($node->children)) {
247 }
248 }
249 $container_sorting->savePost($sorting_position);
250 }
251
252
260 protected function createNewLeaf() {
261 $this->checkAccessOrFail('create', (int) $_POST['parent_id']);
262
263 if(isset($_POST['target_id'], $_POST['type'], $_POST['parent_id'])) {
264 $target_id = (int) $_POST['target_id'];
265 $parent_id = (int) $_POST['parent_id'];
266
267 // TODO: more generic way for implementing different type of leafs
268 $course_ref = new ilObjCourseReference();
269 $course_ref->setTitleType(ilObjCourseReference::TITLE_TYPE_REUSE);
270 $course_ref->setTargetRefId($target_id);
271
272 $course_ref->create();
273 $course_ref->createReference();
274
275 $course_ref->putInTree($parent_id);
276
277 // This is how its done in ILIAS. If you set the target ID before the creation, it won't work
278 $course_ref->setTargetId(ilObject::_lookupObjectId($target_id));
279 $course_ref->update();
280 }
281
282 return ilAsyncOutputHandler::encodeAsyncResponse(array('success'=>true, 'message'=>$this->lng->txt('prg_added_course_ref_successful')));
283 }
284
285
293 protected function getContainerSelectionExplorer($convert_to_string = true) {
294 $create_leaf_form = new ilAsyncContainerSelectionExplorer(rawurldecode($this->ctrl->getLinkTarget($this, 'createNewLeaf', '', true, false)));
295 $create_leaf_form->setId("select_course_explorer");
296
297 $ref_expand = ROOT_FOLDER_ID;
298 if(isset($_GET['ref_repexpand'])) {
299 $ref_expand = (int) $_GET['ref_repexpand'];
300 }
301
302 $create_leaf_form->setExpand($ref_expand);
303 $create_leaf_form->setExpandTarget($this->ctrl->getLinkTarget($this,'getContainerSelectionExplorer'));
304 $create_leaf_form->setAsynchExpanding(true);
305 $create_leaf_form->setTargetGet('target_id');
306 $create_leaf_form->setFrameTarget("_self");
307 $create_leaf_form->setClickable('crs', true);
308 $create_leaf_form->setTargetType('crs');
309 $create_leaf_form->setOutput(0);
310
311 if($convert_to_string)
312 return $create_leaf_form->getOutput();
313 else
314 return $create_leaf_form;
315 }
316
317
323 protected function getCreationForm() {
324 $tmp_obj = new ilObjStudyProgrammeGUI();
325
326 $create_node_form = $tmp_obj->getAsyncCreationForm();
327 $create_node_form->setTitle("");
328 $this->ctrl->setParameterByClass("ilobjstudyprogrammegui", "new_type", "prg");
329 $create_node_form->setFormAction($this->ctrl->getFormActionByClass("ilobjstudyprogrammegui", "save"));
330
331 return $create_node_form;
332 }
333
334
341 protected function create() {
342 $parent_id = (isset($_GET['ref_id']))? (int) $_GET['ref_id'] : null;
343 $this->checkAccessOrFail('create', $parent_id);
344
345 $parent = ilObjectFactoryWrapper::singleton()->getInstanceByRefId($parent_id);
346 $accordion = new ilAccordionGUI();
347
348 $added_slides = 0;
349 if($parent instanceof ilObjStudyProgramme) {
350 // only allow adding new StudyProgramme-Node if there are no lp-children
351 if(!$parent->hasLPChildren()) {
352 $content_new_node = $this->getCreationForm()->getHTML();
353 $accordion->addItem($this->lng->txt('prg_create_new_node'), $content_new_node);
354 $added_slides++;
355 }
356
357 // only allow adding new LP-Children if there are no other StudyProgrammes
358 if(!$parent->hasChildren()) {
359 $content_new_leaf = $this->tpl->getMessageHTML($this->lng->txt('prg_please_select_a_course_for_creating_a_leaf'));
360 $content_new_leaf .= $this->getContainerSelectionExplorer();
361
362 $accordion->addItem($this->lng->txt('prg_create_new_leaf'), $content_new_leaf);
363 $added_slides++;
364 }
365
366 if($added_slides == 1) {
367 $accordion->setBehaviour(ilAccordionGUI::FIRST_OPEN);
368 }
369
370 $content = $accordion->getHTML();
371 }
372
373 // creating modal window output
374 $this->async_output_handler->setHeading($this->lng->txt("prg_async_".$this->ctrl->getCmd()));
375 $this->async_output_handler->setContent($content);
376 $this->async_output_handler->terminate();
377 }
378
379
385 protected function delete() {
386 global $ilSetting;
387
388 $this->checkAccessOrFail("delete");
389
390 if(!isset($_GET['ref_id'], $_GET['item_ref_id'])) {
391 throw new ilException("Nothing to delete!");
392 }
393
394 $element_ref_id = (int) $_GET['ref_id'];
395
396 $cgui = new ilConfirmationGUI();
397
398 $msg = $this->lng->txt("info_delete_sure");
399
400 if (!$ilSetting->get('enable_trash'))
401 {
402 $msg .= "<br/>".$this->lng->txt("info_delete_warning_no_trash");
403 }
404 $cgui->setFormAction($this->ctrl->getFormAction($this, 'confirmedDelete', '', true));
405 $cgui->setCancel($this->lng->txt("cancel"), "cancelDelete");
406 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedDelete");
407 $cgui->setFormName('async_form');
408
409 $obj_id = ilObject::_lookupObjectId($element_ref_id);
410 $type = ilObject::_lookupType($obj_id);
411 $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'),$obj_id);
412 $alt = $this->lng->txt("icon")." ".$this->lng->txt("obj_".$type);
413
414 $cgui->addItem("id[]", $element_ref_id, $title,
415 ilObject::_getIcon($obj_id, "small", $type),
416 $alt);
417 $cgui->addHiddenItem('item_ref_id', $_GET['item_ref_id']);
418
419 $content = $cgui->getHTML();
420
421 // creating the modal window output
422 $this->async_output_handler->setHeading($msg);
423 $this->async_output_handler->setContent($content);
424 $this->async_output_handler->terminate();
425 }
426
427
434 protected function confirmedDelete() {
435 $this->checkAccessOrFail("delete");
436
437 if(!isset($_POST['id'], $_POST['item_ref_id']) && is_array($_POST['id'])) {
438 throw new ilException("No item select for deletion!");
439 }
440
441 $ids = $_POST['id'];
442 $current_node = (int) $_POST['item_ref_id'];
443 $result = true;
444
445 foreach($ids as $id) {
447
448 $not_parent_of_current = true;
449 $not_root = true;
450
451 // do some additional validation if it is a StudyProgramme
452 if($obj instanceof ilObjStudyProgramme) {
453
454 //check if you are not deleting a parent element of the current element
455 $children_of_node = ilObjStudyProgramme::getAllChildren($obj->getRefId());
456 $get_ref_ids = function ($obj) { return $obj->getRefId(); };
457
458 $children_ref_ids = array_map($get_ref_ids, $children_of_node);
459 $not_parent_of_current = (!in_array($current_node, $children_ref_ids));
460
461 $not_root = ($obj->getRoot() != null);
462 }
463
464 if($current_node != $id && $not_root && $not_parent_of_current && $this->checkAccess('delete', $obj->getRefId())) {
465
466 ilRepUtil::deleteObjects(null, $id);
467
468 // deletes the tree-open-node-session storage
469 if(isset($children_of_node)) {
470 $this->tree->closeCertainNode($id);
471 foreach($children_of_node as $child) {
472 $this->tree->closeCertainNode($child->getRefId());
473 }
474 }
475
476 $msg = $this->lng->txt("prg_deleted_safely");
477
478 } else {
479 $msg = $this->lng->txt("prg_not_allowed_node_to_delete");
480 $result = false;
481 }
482 }
483
484 return ilAsyncOutputHandler::encodeAsyncResponse(array('success'=>$result, 'message'=>$msg));
485 }
486
487
494 protected function cancelDelete() {
496 }
497
498
505 protected function initAsyncUIElements() {
506 // add js files
510
511 // add bootstrap modal
512 $settings_modal = ilModalGUI::getInstance();
513 $settings_modal->setId($this->modal_id);
514 $settings_modal->setType(ilModalGUI::TYPE_LARGE);
515 $this->tpl->addOnLoadCode('$("#'.$this->modal_id.'").study_programme_modal();');
516
517 $content = $settings_modal->getHTML();
518
519 // init js notifications
520 $notifications = new ilAsyncNotifications();
521 $notifications->addJsConfig('events', array('success'=>array('study_programme-show_success')));
522 $notifications->initJs();
523
524 // init tree selection explorer
525 $async_explorer = new ilAsyncContainerSelectionExplorer(rawurldecode($this->ctrl->getLinkTarget($this, 'createNewLeaf', '', true, false)));
526 $async_explorer->initJs();
527
528 return $content;
529 }
530
531
535 protected function getToolbar() {
536 $save_order_btn = ilLinkButton::getInstance();
537 $save_order_btn->setId('save_order_button');
538 $save_order_btn->setUrl("javascript:void(0);");
539 $save_order_btn->setOnClick("$('body').trigger('study_programme-save_order');");
540 $save_order_btn->setCaption('prg_save_tree_order');
541
542 $cancel_order_btn = ilLinkButton::getInstance();
543 $cancel_order_btn->setId('cancel_order_button');
544 $cancel_order_btn->setUrl("javascript:void(0);");
545 $cancel_order_btn->setOnClick("$('body').trigger('study_programme-cancel_order');");
546 $cancel_order_btn->setCaption('prg_cancel_tree_order');
547
548 $this->toolbar->addButtonInstance($save_order_btn);
549 $this->toolbar->addButtonInstance($cancel_order_btn);
550 }
551
552
561 protected function checkAccess($permission, $ref_id = null) {
562 $ref_id = ($ref_id === null)? $this->ref_id : $ref_id;
563 $checker = $this->access->checkAccess($permission, '', $ref_id);
564
565 return $checker;
566 }
567
568
577 protected function checkAccessOrFail($permission, $ref_id = null) {
578 if(!$this->checkAccess($permission, $ref_id)) {
579 throw new ilException("You have no permission for ".$permission." Object with ref_id ".$ref_id."!");
580 }
581 }
582
583}
$result
$_GET["client_id"]
Accordion user interface class.
static addJavaScript()
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()
Confirmation screen class.
static _getInstance($a_obj_id)
get instance by obj_id
Base class for ILIAS Exception 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.
storeTreeOrder($nodes, $container_sorting=null, $parent_ref_id=null)
Recursive function for saving the tree order.
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.
initTree()
Initialize Tree Creates tree instance and set tree configuration.
Class ilObjStudyProgramme.
static getAllChildren($a_ref_id)
Get a list of all ilObjStudyProgrammes in the subtree starting at $a_ref_id.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
static getClassByType($a_obj_type)
Get class by type.
static _lookupObjectId($a_ref_id)
lookup object id
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _lookupType($a_id, $a_reference=false)
lookup object type
static deleteObjects($a_cur_ref_id, $a_ids)
Delete objects.
Exception is thrown when invariants on the program tree would be violated by manipulation of tree.
$_POST['username']
Definition: cron.php:12
$target_id
Definition: goto.php:88
global $ilCtrl
Definition: ilias.php:18
exit
Definition: login.php:54
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:40
$cmd
Definition: sahs_server.php:35