ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLSEventHandler.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
11 {
15  protected $tree;
16 
17  public function __construct(ilTree $tree)
18  {
19  $this->tree = $tree;
20  }
21 
26  public function handleObjectDeletion(array $parameter)
27  {
28  $obj_deleted = $parameter['object'];
29  $obj_ref_id = (int) $obj_deleted->getRefId();
30 
31  if (!$this->isExistingObject($obj_ref_id)) {
32  return;
33  }
34 
35  $parent_lso = $this->getParentLSOInfo($obj_ref_id);
36  if ($parent_lso) {
37  $this->deleteLSOItem($obj_ref_id, (int) $parent_lso['ref_id']);
38  }
39  }
40 
44  public function handleObjectToTrash(array $parameter)
45  {
46  $obj_ref_id = (int) $parameter['ref_id'];
47  $old_parent_ref_id = (int) $parameter['old_parent_ref_id'];
48  $parent_lso = $this->getParentLSOInfo($obj_ref_id);
49 
50  if (!$this->isExistingObject($obj_ref_id) || !$parent_lso) {
51  return;
52  }
53 
54  if ($old_parent_ref_id) {
55  $this->deleteLSOItem($obj_ref_id, $old_parent_ref_id);
56  }
57  }
58 
59  protected function isExistingObject(int $ref_id) : bool
60  {
61  if (empty($ref_id) || !$this->tree->isInTree($ref_id)) {
62  return false;
63  }
64  return true;
65  }
66 
67  protected function deleteLSOItem(int $obj_ref_id, int $parent_lso_ref_id)
68  {
69  $lso = $this->getInstanceByRefId($parent_lso_ref_id);
70  $lso->getStateDB()->deleteForItem(
71  $parent_lso_ref_id,
72  $obj_ref_id
73  );
74  }
75 
76  public function handleParticipantDeletion(int $obj_id, int $usr_id)
77  {
78  $lso = $this->getInstanceByObjId($obj_id);
79  $db = $lso->getStateDB();
80  $db->deleteFor($lso->getRefId(), [$usr_id]);
81  }
82 
87  protected function getParentLSOInfo(int $child_ref_id)
88  {
89  foreach ($this->tree->getPathFull($child_ref_id) as $hop) {
90  if ($hop['type'] === 'lso') {
91  return $hop;
92  }
93  }
94  return false;
95  }
96 
97  protected function getRefIdsOfObjId(int $triggerer_obj_id) : array
98  {
99  return ilObject::_getAllReferences($triggerer_obj_id);
100  }
101 
102  protected function getInstanceByRefId(int $ref_id) : ilObject
103  {
104  return ilObjectFactory::getInstanceByRefId($ref_id);
105  }
106 
107  protected function getInstanceByObjId(int $obj_id) : ilObjLearningSequence
108  {
109  $refs = \ilObject::_getAllReferences($obj_id);
110  $ref_id = array_shift(array_keys($refs));
111  return $this->getInstanceByRefId($ref_id);
112  }
113 }
getRefIdsOfObjId(int $triggerer_obj_id)
getParentLSOInfo(int $child_ref_id)
get the LSO up from $child_ref_if
Class ilObjLearningSequence.
static _getAllReferences($a_id)
get all reference ids of object
handleObjectToTrash(array $parameter)
handleParticipantDeletion(int $obj_id, int $usr_id)
deleteLSOItem(int $obj_ref_id, int $parent_lso_ref_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
handleObjectDeletion(array $parameter)
Find out, if a subobject is about to be deleted.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id