ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Handler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23class Handler implements HandlerInterface
24{
25 protected \ilTree $tree;
26
27 public function __construct(\ilTree $tree)
28 {
29 $this->tree = $tree;
30 }
31
32 public function referenceObjectInTargetContainer(int $obj_id, int $container_ref_id): int
33 {
34 $object = \ilObjectFactory::getInstanceByObjId($obj_id);
35 $new_ref_id = $object->createReference();
36
37 $object->putInTree($container_ref_id);
38 $object->setPermissions($container_ref_id);
39
40 return $new_ref_id;
41 }
42
43 public function getObjectReferenceIDInContainer(int $obj_id, int $container_ref_id): ?int
44 {
45 $ref_ids = \ilObject::_getAllReferences($obj_id);
46 foreach ($ref_ids as $ref_id) {
47 if ($this->tree->isDeleted($ref_id)) {
48 continue;
49 }
50 if ($this->tree->isGrandChild($container_ref_id, $ref_id)) {
51 return $ref_id;
52 }
53 }
54 return null;
55 }
56
57 public function isObjectDeleted(int $obj_id): bool
58 {
59 $exists = false;
60 foreach (\ilObject::_getAllReferences($obj_id) as $ref_id => $tmp) {
61 if (!$this->tree->isDeleted($ref_id)) {
62 $exists = true;
63 }
64 }
65 return !$exists;
66 }
67
68 public function deleteReference(int $ref_id): void
69 {
71 $object->delete();
72 }
73
74 public function getTypeOfReferencedObject(int $ref_id): string
75 {
76 return \ilObject::_lookupType($ref_id, true);
77 }
78}
referenceObjectInTargetContainer(int $obj_id, int $container_ref_id)
Returns the new ref ID.
Definition: Handler.php:32
getObjectReferenceIDInContainer(int $obj_id, int $container_ref_id)
Definition: Handler.php:43
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
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