ILIAS  release_8 Revision v8.24
class.ilObjStudyProgrammeReferenceGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
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 }
36
37 public static function _goto(int $target): void
38 {
40 ilObjStudyProgrammeGUI::_goto($target_ref_id . "_");
41 }
42
43 public function saveObject(): void
44 {
45 $ilAccess = $this->access;
46
47 if (!(int) $_REQUEST['target_id']) {
48 $this->createObject();
49 }
50 if (!$ilAccess->checkAccess('visible', '', (int) $_REQUEST['target_id'])) {
51 $this->tpl->setOnScreenMessage("failure", $this->lng->txt('permission_denied'));
52 $this->createObject();
53 }
54 if ($this->tryingToCreateCircularReference((int) $_REQUEST['target_id'], (int) $_REQUEST['ref_id'])) {
55 $this->tpl->setOnScreenMessage("failure", $this->lng->txt('prgr_may_not_create_circular_reference'));
56 $this->createObject();
57 }
58 parent::saveObject();
59 }
60
61 public function putObjectInTree(ilObject $obj, $parent_node_id = null): void
62 {
63 // when this is called, the target already should be defined...
64 $target_obj_id = ilObject::_lookupObjId((int) $this->form->getInput('target_id'));
65 $obj->setTargetId($target_obj_id);
66 $obj->update();
67 parent::putObjectInTree($obj, $parent_node_id);
68 }
69
70 protected function tryingToCreateCircularReference(int $obj_to_be_referenced, int $reference_position): bool
71 {
72 if ($reference_position === $obj_to_be_referenced) {
73 return true;
74 }
75 $queque = [$reference_position];
76 while ($parent = array_shift($queque)) {
77 $p_parent = (int) $this->tree->getParentId($parent);
78 if ($p_parent === $obj_to_be_referenced) {
79 return true;
80 }
81 if (ilObject::_lookupType($p_parent, true) === 'prg') {
82 $queque[] = $p_parent;
83 }
84 foreach (ilContainerReference::_lookupSourceIds(ilObject::_lookupObjId($parent)) as $parent_ref_obj_id) {
85 $ref_ids = ilObject::_getAllReferences($parent_ref_obj_id);
86 $parent_ref_ref_id = (int) array_shift($ref_ids);
87 $parent_ref_loc = (int) $this->tree->getParentId($parent_ref_ref_id);
88 if ($parent_ref_loc === $obj_to_be_referenced) {
89 return true;
90 }
91 if (ilObject::_lookupType($parent_ref_loc, true) === 'prg') {
92 $queque[] = $parent_ref_loc;
93 }
94 }
95 }
96 return false;
97 }
98}
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
ilAccessHandler $access
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupObjId(int $ref_id)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
form( $class_path, string $cmd)