ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
Handler.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 class 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  {
70  $object = \ilObjectFactory::getInstanceByRefId($ref_id);
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
static _getAllReferences(int $id)
get all reference ids for object ID
getObjectReferenceIDInContainer(int $obj_id, int $container_ref_id)
Definition: Handler.php:43
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
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