ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
Handler.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilObject;
25use ilTree;
26
27class Handler implements HandlerInterface
28{
29 protected ilTree $tree;
30
31 public function __construct(ilTree $tree)
32 {
33 $this->tree = $tree;
34 }
35
36 public function referenceObjectInTargetContainer(int $obj_id, int $container_ref_id): int
37 {
38 $object = ilObjectFactory::getInstanceByObjId($obj_id);
39 $new_ref_id = $object->createReference();
40
41 $object->putInTree($container_ref_id);
42 $object->setPermissions($container_ref_id);
43
44 return $new_ref_id;
45 }
46
47 public function isObjectDeleted(int $obj_id): bool
48 {
49 $exists = false;
50 foreach (ilObject::_getAllReferences($obj_id) as $ref_id => $tmp) {
51 if (!$this->tree->isDeleted($ref_id)) {
52 $exists = true;
53 }
54 }
55 return !$exists;
56 }
57
58 public function deleteReference(int $ref_id): void
59 {
60 if (!ilObject::_exists($ref_id, true)) {
61 return;
62 }
64 $object->delete();
65 }
66
67 public function getTypeOfObject(int $obj_id): string
68 {
69 return ilObject::_lookupType($obj_id);
70 }
71
72 public function isReferenceInContainer(int $ref_id, int $container_ref_id): bool
73 {
74 return $this->tree->isGrandChild($container_ref_id, $ref_id);
75 }
76
77 public function doesReferenceExist(int $ref_id): bool
78 {
79 return ilObject::_exists($ref_id, true);
80 }
81
82 public function isOnlyReference(int $ref_id): bool
83 {
84 $other_references_count = 0;
86 if ($other_ref_id === $ref_id) {
87 continue;
88 }
89 if (ilObject::_isInTrash($other_ref_id)) {
90 continue;
91 }
92 $other_references_count++;
93 }
94 return $other_references_count === 0;
95 }
96}
referenceObjectInTargetContainer(int $obj_id, int $container_ref_id)
Returns the new ref ID.
Definition: Handler.php:36
isReferenceInContainer(int $ref_id, int $container_ref_id)
Definition: Handler.php:72
Class ilObjectFactory This class offers methods to get instances of the type-specific object classes ...
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
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 _isInTrash(int $ref_id)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupObjId(int $ref_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$ref_id
Definition: ltiauth.php:66