ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjStudyProgrammeReferenceGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public function __construct(
27 $data,
28 int $id,
29 bool $call_by_reference = true,
30 bool $prepare_output = false
31 ) {
32 $this->target_type = 'prg';
33 $this->reference_type = 'prgr';
35 $this->lng->loadLanguageModule('prg');
36 }
37
38 public static function _goto(string $target): void
39 {
40 global $DIC;
41 $access = $DIC['ilAccess'];
42 if ($access->checkAccess('write', '', (int) $target)) {
43 $ilCtrl = $DIC['ilCtrl'];
44 $ilCtrl->setTargetScript('ilias.php');
45 $ilCtrl->setParameterByClass(self::class, "ref_id", $target);
46 $ilCtrl->redirectByClass([ilRepositoryGUI::class, self::class], "view");
47 } else {
49 ilObjStudyProgrammeGUI::_goto((string) $target_ref_id);
50 }
51 }
52
53 public function saveObject(): void
54 {
55 $ilAccess = $this->access;
56 $target_id = $this->cont_request->getTargetId();
57 $create = true;
58
59 if ($target_id === 0) {
60 $this->tpl->setOnScreenMessage("failure", $this->lng->txt('select_object_to_link'));
61 $this->createObject();
62 $create = false;
63 }
64 if ($create && !$ilAccess->checkAccess('visible', '', $target_id)) {
65 $this->tpl->setOnScreenMessage("failure", $this->lng->txt('permission_denied'));
66 $this->createObject();
67 $create = false;
68 }
69 if ($create && $this->tryingToCreateCircularReference($target_id, $this->cont_request->getRefId())) {
70 $this->tpl->setOnScreenMessage("failure", $this->lng->txt('prgr_may_not_create_circular_reference'));
71 $this->createObject();
72 $create = false;
73 }
74 if ($create) {
75 parent::saveObject();
76 }
77 }
78
79 public function updateObject(): void
80 {
81 $form = $this->initForm();
83 $target_id = (int) $form->getInput('target_id');
84 $self_id = (int) $this->object->getRefId();
85 $container_id = $this->tree->getParentId($self_id);
86 $do_update = true;
87
88 if (!$this->access->checkAccess('visible', '', $target_id)) {
89 $this->tpl->setOnScreenMessage("failure", $this->lng->txt('permission_denied'), true);
90 $this->editObject($form);
91 $do_update = false;
92 }
93
94 if ($do_update && $this->tryingToCreateCircularReference($target_id, $container_id)) {
95 $this->tpl->setOnScreenMessage("failure", $this->lng->txt('prgr_may_not_create_circular_reference'));
96 $this->editObject($form);
97 $do_update = false;
98 }
99
100 if ($do_update) {
101 parent::updateObject();
102 }
103 }
104
105 public function putObjectInTree(ilObject $obj, $parent_node_id = null): void
106 {
107 // when this is called, the target already should be defined...
108 $target_obj_id = ilObject::_lookupObjId((int) $this->form->getInput('target_id'));
109 $obj->setTargetId($target_obj_id);
110 $obj->update();
111 parent::putObjectInTree($obj, $parent_node_id);
112 }
113
114 protected function tryingToCreateCircularReference(int $obj_to_be_referenced, int $reference_position): bool
115 {
116 if ($reference_position === $obj_to_be_referenced) {
117 return true;
118 }
119 $queque = [$reference_position];
120 while ($parent = array_shift($queque)) {
121 $p_parent = (int) $this->tree->getParentId($parent);
122 if ($p_parent === $obj_to_be_referenced) {
123 return true;
124 }
125 if (ilObject::_lookupType($p_parent, true) === 'prg') {
126 $queque[] = $p_parent;
127 }
128 foreach (ilContainerReference::_lookupSourceIds(ilObject::_lookupObjId($parent)) as $parent_ref_obj_id) {
129 $ref_ids = ilObject::_getAllReferences($parent_ref_obj_id);
130 $parent_ref_ref_id = (int) array_shift($ref_ids);
131 $parent_ref_loc = (int) $this->tree->getParentId($parent_ref_ref_id);
132 if ($parent_ref_loc === $obj_to_be_referenced) {
133 return true;
134 }
135 if (ilObject::_lookupType($parent_ref_loc, true) === 'prg') {
136 $queque[] = $parent_ref_loc;
137 }
138 }
139 }
140 return false;
141 }
142}
initForm(int $a_mode=self::MODE_EDIT)
static _lookupSourceIds(int $a_target_id)
Get ids of all container references that target the object with the given id.
static _lookupTargetRefId(int $a_obj_id)
@ilCtrl_Calls ilObjStudyProgrammeReferenceGUI: ilPermissionGUI, ilInfoScreenGUI, ilPropertyFormGUI
tryingToCreateCircularReference(int $obj_to_be_referenced, int $reference_position)
putObjectInTree(ilObject $obj, $parent_node_id=null)
__construct( $data, int $id, bool $call_by_reference=true, bool $prepare_output=false)
updateObject()
updates object entry in object_data
ilAccessHandler $access
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
checkAccess(string $a_permission, string $a_cmd, int $a_ref_id, string $a_type="", ?int $a_obj_id=null, ?int $a_tree_id=null)
check access for an object (provide $a_type and $a_obj_id if available for better performance)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd, string $submit_caption="")
global $DIC
Definition: shib_login.php:26