19 declare(strict_types=1);
50 protected ILIAS $ilias,
54 protected ILIAS\
HTTP\Wrapper\WrapperFactory $http_wrapper,
58 $this->modal_id =
"tree_modal";
60 $this->
lng->loadLanguageModule(
"prg");
76 $js_url = rawurldecode($this->
ctrl->getLinkTarget($this,
'saveTreeOrder',
'',
true));
77 $this->tree->addJsConf(
'save_tree_url', $js_url);
78 $this->tree->addJsConf(
'save_button_id',
'save_order_button');
79 $this->tree->addJsConf(
'cancel_button_id',
'cancel_order_button');
91 $cmd = $this->
ctrl->getCmd();
95 if ($cmd ===
"" || $cmd === null) {
100 if ($this->tree->handleCommand()) {
110 case "confirmedDelete":
112 case "getContainerSelectionExplorer":
113 case "saveTreeOrder":
114 case "createNewLeaf":
116 $content = $this->$cmd();
119 throw new ilException(
"ilObjStudyProgrammeTreeGUI: " .
120 "Command not supported: $cmd");
129 protected function view(): string
131 $output = $this->tree->getHTML();
156 if ($this->http_wrapper->post()->has(
"tree")) {
157 $tree = $this->http_wrapper->post()->retrieve(
"tree", $this->
refinery->kindlyTo()->string());
160 $treeData = json_decode($treeAsJson,
false, 512, JSON_THROW_ON_ERROR);
162 if (!is_array($treeData) || [] === $treeData) {
167 $this->storeTreeOrder($treeData);
170 [
'success' =>
true,
'message' => $this->
lng->txt(
'prg_saved_order_successful')]
177 protected function storeTreeOrder(
180 int $parent_ref_id = null
182 $sorting_position = array();
183 $position_count = 10;
185 $ref_id = $parent_ref_id;
186 if (is_null($ref_id)) {
193 if (is_null($container_sorting)) {
197 foreach ($nodes as $node) {
200 $id = substr(
$id, strrpos(
$id,
"_") + 1);
202 $sorting_position[
$id] = $position_count;
203 $position_count += 10;
207 $node_obj->moveTo($parent_node);
210 $this->
ilTree->moveTree($node_obj->getRefId(), $parent_node->getRefId());
211 $this->rbacadmin->adjustMovedObjectPermissions($node_obj->getRefId(), $parent_node->getRefId());
215 if (isset($node->children)) {
216 $this->storeTreeOrder(
223 $container_sorting->savePost($sorting_position);
234 $this->
checkAccessOrFail(
'create', $this->http_wrapper->post()->retrieve(
"parent_id", $this->
refinery->kindlyTo()->int()));
237 $this->http_wrapper->post()->has(
"target_id") &&
238 $this->http_wrapper->post()->has(
"type") &&
239 $this->http_wrapper->post()->has(
"parent_id")
241 $target_id = $this->http_wrapper->post()->retrieve(
"target_id", $this->
refinery->kindlyTo()->int());
242 $parent_id = $this->http_wrapper->post()->retrieve(
"parent_id", $this->
refinery->kindlyTo()->int());
247 $course_ref->setTargetRefId($target_id);
249 $course_ref->create();
250 $course_ref->createReference();
252 $course_ref->putInTree($parent_id);
256 $course_ref->update();
260 [
'success' =>
true,
'message' => $this->
lng->txt(
'prg_added_course_ref_successful')]
274 rawurldecode($this->
ctrl->getLinkTarget($this,
'createNewLeaf',
'',
true)),
276 $this->http_wrapper->query()
278 $create_leaf_form->
setId(
"select_course_explorer");
281 if ($this->http_wrapper->query()->has(
"ref_repexpand")) {
282 $ref_expand = $this->http_wrapper->query()->retrieve(
"ref_repexpand", $this->
refinery->kindlyTo()->int());
285 $create_leaf_form->setExpand($ref_expand);
286 $create_leaf_form->setExpandTarget($this->
ctrl->getLinkTarget($this,
'getContainerSelectionExplorer'));
287 $create_leaf_form->setAsynchExpanding(
true);
288 $create_leaf_form->setTargetGet(
'target_id');
289 $create_leaf_form->setFrameTarget(
"_self");
290 $create_leaf_form->setClickable(
'crs',
true);
291 $create_leaf_form->setTargetType(
'crs');
292 $create_leaf_form->setOutput(0);
294 if ($convert_to_string) {
295 return $create_leaf_form->getOutput();
298 return $create_leaf_form;
308 $create_node_form = $tmp_obj->getAsyncCreationForm();
309 $create_node_form->setTitle(
"");
310 $this->
ctrl->setParameterByClass(
"ilobjstudyprogrammegui",
"new_type",
"prg");
311 $create_node_form->setFormAction($this->
ctrl->getFormActionByClass(
"ilobjstudyprogrammegui",
"save"));
313 return $create_node_form;
325 if ($this->http_wrapper->query()->has(
"ref_id")) {
326 $parent_id = $this->http_wrapper->query()->retrieve(
"ref_id", $this->
refinery->kindlyTo()->int());
337 if (!$parent->hasLPChildren()) {
339 $accordion->addItem($this->
lng->txt(
'prg_create_new_node'), $content_new_node);
346 if (!$parent->hasChildren() && $this->
ilSetting->get(
"obj_dis_creation_crsr") ===
"") {
348 $this->
lng->txt(
'prg_please_select_a_course_for_creating_a_leaf')
352 $accordion->addItem($this->
lng->txt(
'prg_create_new_leaf'), $content_new_leaf);
356 if ($added_slides === 1) {
360 $content = $accordion->getHTML(
true);
364 $this->async_output_handler->setHeading($this->
lng->txt(
"prg_async_" . $this->ctrl->getCmd()));
365 $this->async_output_handler->setContent($content);
366 $this->async_output_handler->terminate();
374 protected function delete():
void 378 if (!$this->http_wrapper->query()->has(
"ref_id") || !$this->http_wrapper->query()->has(
"item_ref_id")) {
382 $element_ref_id = $this->http_wrapper->query()->retrieve(
"ref_id", $this->
refinery->kindlyTo()->int());
386 $msg = $this->
lng->txt(
"info_delete_sure");
387 if (!$this->
ilSetting->get(
'enable_trash')) {
388 $msg .=
"<br/>" . $this->
lng->txt(
"info_delete_warning_no_trash");
390 $cgui->setHeaderText($msg);
391 $cgui->setFormAction($this->
ctrl->getFormAction($this,
'confirmedDelete',
'',
true));
392 $cgui->setCancel($this->
lng->txt(
"cancel"),
"cancelDelete");
393 $cgui->setConfirm($this->
lng->txt(
"confirm"),
"confirmedDelete");
394 $cgui->setFormName(
'async_form');
399 $alt = $this->
lng->txt(
"icon") .
" " . $this->
lng->txt(
"obj_" . $type);
403 (
string)$element_ref_id,
408 $cgui->addHiddenItem(
410 $this->http_wrapper->query()->retrieve(
"item_ref_id", $this->
refinery->kindlyTo()->string())
413 $content = $cgui->getHTML();
416 $this->async_output_handler->setHeading($msg);
417 $this->async_output_handler->setContent($content);
418 $this->async_output_handler->terminate();
431 (!$this->http_wrapper->post()->has(
"id") || !$this->http_wrapper->post()->has(
"item_ref_id")) &&
432 is_array($this->http_wrapper->post()->retrieve(
437 throw new ilException(
"No item select for deletion!");
440 $ids = $this->http_wrapper->post()->retrieve(
444 $current_node = $this->http_wrapper->post()->retrieve(
"item_ref_id", $this->
refinery->kindlyTo()->int());
448 foreach ($ids as
$id) {
451 $not_parent_of_current =
true;
458 $get_ref_ids =
static function (ilObjStudyProgramme $obj):
int {
459 return $obj->getRefId();
462 $children_ref_ids = array_map($get_ref_ids, $children_of_node);
463 $not_parent_of_current = (!in_array($current_node, $children_ref_ids));
465 $not_root = ($obj->getRoot() != null);
469 $current_node != $id &&
471 $not_parent_of_current &&
477 if (isset($children_of_node)) {
478 $this->tree->closeCertainNode($id);
479 foreach ($children_of_node as $child) {
480 $this->tree->closeCertainNode($child->getRefId());
484 $msg = $this->
lng->txt(
"prg_deleted_safely");
486 $msg = $this->
lng->txt(
"prg_not_allowed_node_to_delete");
516 $settings_modal->setId($this->modal_id);
518 $this->tpl->addOnLoadCode(
'$("#' . $this->modal_id .
'").study_programme_modal();');
520 $content = $settings_modal->getHTML();
524 $notifications->addJsConfig(
'events', array(
'success' => array(
'study_programme-show_success')));
525 $notifications->initJs();
529 rawurldecode($this->
ctrl->getLinkTarget($this,
'createNewLeaf',
'',
true)),
531 $this->http_wrapper->query()
533 $async_explorer->
initJs();
543 $save_order_btn = $this->ui_factory->button()->standard($this->
lng->txt(
'prg_save_tree_order'),
'')
544 ->
withOnLoadCode(fn (
$id) =>
"$(\"#$id\").click( () => $('body').trigger('study_programme-save_order'));");
545 $cancel_order_btn = $this->ui_factory->button()->standard($this->
lng->txt(
'prg_cancel_tree_order'),
'')
546 ->
withOnLoadCode(fn (
$id) =>
"$(\"#$id\").click( () => $('body').trigger('study_programme-cancel_order'));");
548 $this->
toolbar->addComponent($save_order_btn);
549 $this->
toolbar->addComponent($cancel_order_btn);
555 protected function checkAccess(
string $permission,
int $ref_id = null): bool
557 if (is_null($ref_id)) {
560 return $this->
access->checkAccess($permission,
'', $ref_id);
571 throw new ilException(
"You have no permission for " . $permission .
" Object with ref_id " . $ref_id .
"!");
createNewLeaf()
Creates a new leaf Currently only course references can be created.
cancel()
Cancel operation.
Class ilAsyncOutputHandler Handles the output for async-requests.
static getSystemMessageHTML(string $a_txt, string $a_type="info")
Get HTML for a system message.
Class ilObjStudyProgrammeGUI class ilObjStudyProgrammeGUI: ilPermissionGUI ilObjStudyProgrammeGUI: ...
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
confirmedDelete()
Deletes a node or a leaf in the tree.
checkAccessOrFail(string $permission, int $ref_id=null)
Checks permission of a object and throws an exception if they are not granted.
static handleAsyncOutput(string $normal_content, string $async_content=null, bool $apply_to_tpl=true)
Handles async output.
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkAccess(string $permission, int $ref_id=null)
Checks permission of current tree or certain child of it.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static deleteObjects(int $a_cur_ref_id, array $a_ids)
Delete objects.
getContainerSelectionExplorer(bool $convert_to_string=true)
Initialize the Course Explorer for creating a leaf.
getToolbar()
Setup the toolbar.
string $modal_id
CSS-ID of the modal windows.
Component logger with individual log levels by component id.
initTree()
Initialize Tree Creates tree instance and set tree configuration.
withOnLoadCode(Closure $binder)
int $ref_id
Ref-ID of the object.
static addJavaScript(ilGlobalTemplate $main_tpl=null)
Add javascript files that are necessary to run accordion.
ilObjStudyProgramme $object
static encodeAsyncResponse(array $data=array())
Encode data as json for async output.
view()
Display the tree view.
saveTreeOrder()
Saves tree node order Data is json encoded from the jstree component.
static _lookupObjectId(int $ref_id)
cancelDelete()
Cancel deletion Return a json string for the async handling.
executeCommand()
Execute GUI-commands If there is a async request the response is sent as a json string.
static addJavascript()
Adds the javascript to template.
static getClassByType(string $obj_type)
getCreationForm()
Returns the async creation form for StudyProgrammes.
__construct(protected ilGlobalTemplateInterface $tpl, protected ilCtrl $ctrl, protected ilAccess $access, protected ilToolbarGUI $toolbar, protected ilLanguage $lng, protected ilComponentLogger $log, protected ILIAS $ilias, protected ilSetting $ilSetting, protected ilTree $ilTree, protected ilRbacAdmin $rbacadmin, protected ILIAS\HTTP\Wrapper\WrapperFactory $http_wrapper, protected ILIAS\Refinery\Factory $refinery, protected ILIAS\UI\Factory $ui_factory)
ilAsyncOutputHandler $async_output_handler
static getAllChildren(int $a_ref_id, bool $include_references=false)
Get a list of all ilObjStudyProgrammes in the subtree starting at $a_ref_id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getInstance(int $a_obj_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class ilAsyncContainerSelectionExplorer A class for async ilContainerSelectionExplorer which triggers...
Class ilRbacAdmin Core functions for role based access control.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initAsyncUIElements()
Initializes all elements used for async-interaction Adds HTML-skeleton for the bootstrap modal dialog...
Class ilObjStudyProgrammeTreeGUI Generates the manage view for ilTrainingProgramme-Repository objects...
create()
Generates the modal window content for the creation form of nodes or leafs If there are already Study...
ilObjStudyProgrammeTreeExplorerGUI $tree
Refinery Factory $refinery