ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLSEventHandler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 protected ilTree $tree;
27
28 public function __construct(ilTree $tree)
29 {
30 $this->tree = $tree;
31 }
32
37 public function handleObjectDeletion(array $parameter): void
38 {
39 $obj_deleted = $parameter['object'];
40 $obj_ref_id = (int) $obj_deleted->getRefId();
41
42 if (!$this->isExistingObject($obj_ref_id)) {
43 return;
44 }
45
46 $parent_lso = $this->getParentLSOInfo($obj_ref_id);
47 if (!is_null($parent_lso)) {
48 $this->deleteLSOItem($obj_ref_id, (int) $parent_lso['ref_id']);
49 }
50 }
51
55 public function handleObjectToTrash(array $parameter): void
56 {
57 $obj_ref_id = (int) $parameter['ref_id'];
58 $old_parent_ref_id = (int) $parameter['old_parent_ref_id'];
59 $parent_lso = $this->getParentLSOInfo($obj_ref_id);
60
61 if (!$this->isExistingObject($obj_ref_id) || is_null($parent_lso)) {
62 return;
63 }
64
65 if ($old_parent_ref_id) {
66 $this->deleteLSOItem($obj_ref_id, $old_parent_ref_id);
67 }
68 }
69
70 protected function isExistingObject(int $ref_id): bool
71 {
72 if (empty($ref_id) || !$this->tree->isInTree($ref_id)) {
73 return false;
74 }
75 return true;
76 }
77
78 protected function deleteLSOItem(int $obj_ref_id, int $parent_lso_ref_id): void
79 {
80 $lso = $this->getInstanceByRefId($parent_lso_ref_id);
81 $lso->getStateDB()->deleteForItem(
82 $parent_lso_ref_id,
83 $obj_ref_id
84 );
85 }
86
87 public function handleParticipantDeletion(int $obj_id, int $usr_id): void
88 {
89 $lso = $this->getInstanceByObjId($obj_id);
90 $db = $lso->getStateDB();
91 $db->deleteFor($lso->getRefId(), [$usr_id]);
92 }
93
94 public function handleClonedObject(ilObject $new_obj, ilObject $origin_obj): void
95 {
96 if ($this->getParentLSOInfo($new_obj->getRefId())
97 && $this->getParentLSOInfo($origin_obj->getRefId())
98 ) {
99 $new_lso = $this->getInstanceByRefId(
100 (int)$this->getParentLSOInfo($new_obj->getRefId())['ref_id']
101 );
102 $post_condition_db = $new_lso->getDI()['db.postconditions'];
103 $post_condition = current($post_condition_db->select([$origin_obj->getRefId()]))
104 ->withRefId($new_obj->getRefId());
105 $post_condition_db->upsert([$post_condition]);
106 }
107 }
108
112 protected function getParentLSOInfo(int $child_ref_id): ?array
113 {
114 if($child_ref_id === 0) {
115 return null;
116 }
117
118 foreach ($this->tree->getPathFull($child_ref_id) as $hop) {
119 if ($hop['type'] === 'lso') {
120 return $hop;
121 }
122 }
123 return null;
124 }
125
129 protected function getRefIdsOfObjId(int $triggerer_obj_id): array
130 {
131 return ilObject::_getAllReferences($triggerer_obj_id);
132 }
133
134 protected function getInstanceByRefId(int $ref_id): ilObjLearningSequence
135 {
138
139 if (!$obj instanceof ilObjLearningSequence) {
140 throw new LogicException("Object type should be ilObjLearningSequence. Actually is " . get_class($obj));
141 }
142
143 return $obj;
144 }
145
146 protected function getInstanceByObjId(int $obj_id): ilObjLearningSequence
147 {
148 $refs = array_keys(\ilObject::_getAllReferences($obj_id));
149 $ref_id = array_shift($refs);
150
153
154 if (!$obj instanceof ilObjLearningSequence) {
155 throw new LogicException("Object type should be ilObjLearningSequence. Actually is " . get_class($obj));
156 }
157
158 return $obj;
159 }
160}
handleObjectDeletion(array $parameter)
Find out, if a sub object is about to be deleted.
getRefIdsOfObjId(int $triggerer_obj_id)
handleClonedObject(ilObject $new_obj, ilObject $origin_obj)
handleParticipantDeletion(int $obj_id, int $usr_id)
getParentLSOInfo(int $child_ref_id)
get the LSO up from $child_ref_id
deleteLSOItem(int $obj_ref_id, int $parent_lso_ref_id)
handleObjectToTrash(array $parameter)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
static _getAllReferences(int $id)
get all reference ids for object ID
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$ref_id
Definition: ltiauth.php:66