ILIAS  release_8 Revision v8.24
class.ilObjectGUIFactory.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
31{
33 protected ilDBInterface $db;
34
36 {
37 global $DIC;
38
39 if (is_null($obj_definition)) {
40 $obj_definition = $DIC["objDefinition"];
41 }
42 $this->obj_definition = $obj_definition;
43
44 if (is_null($db)) {
45 $db = $DIC->database();
46 }
47 $this->db = $db;
48 }
49
50
57 public function getInstanceByRefId(int $ref_id): ilObject
58 {
59 // check reference id
60 if (!isset($ref_id)) {
61 throw new ilObjectNotFoundException("ilObjectGUIFactory::getInstanceByRefId(): No ref_id given!");
62 }
63
64 $sql =
65 "SELECT object_data.type" . PHP_EOL
66 . "FROM object_data,object_reference" . PHP_EOL
67 . "WHERE object_reference.obj_id = object_data.obj_id" . PHP_EOL
68 . "AND object_reference.ref_id = %s" . PHP_EOL
69 ;
70 // check if object exists
71 $result = $this->db->queryF($sql, ["integer"], [$ref_id]);
72 if (!($row = $this->db->fetchAssoc($result))) {
74 "ilObjectGUIFactory::getInstanceByRefId(): Object with ref_id " . $ref_id . " not found!"
75 );
76 }
77
78 // check class name
79 $class_name = "ilObj" . $this->obj_definition->getClassName($row["type"]) . "GUI";
80 if ($class_name == "ilObjGUI") {
81 throw new ilObjectException("ilObjectGUIFactory::getInstanceByRefId(): Not able to determine object " .
82 "class for type" . $row["type"] . ".");
83 }
84
85 // create instance
86 $location = $this->obj_definition->getLocation($row["type"]);
87 include_once($location . "/class." . $class_name . ".php");
88 return new $class_name("", $ref_id, true, false);
89 }
90}
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
parses the objects.xml it handles the xml-description of all ilias objects
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilObjectDefinition $obj_definition
__construct(ilObjectDefinition $obj_definition=null, ilDBInterface $db=null)
getInstanceByRefId(int $ref_id)
Get ilObj...GUI instance by reference id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$ref_id
Definition: ltiauth.php:67