ILIAS  release_8 Revision v8.24
class.ilObjLTIAdministration.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
27{
28 public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
29 {
30 $this->type = "ltis";
31 parent::__construct($a_id, $a_call_by_reference);
32 }
33
37 public function getLTIObjectTypes(): array
38 {
39 $obj_def = new ilObjectDefinition();
40 return $obj_def->getLTIProviderTypes();
41 }
42
46 public function getLTIRoles(): array
47 {
48 global $rbacreview;
49
50 $global_roles = $rbacreview->getGlobalRoles();
51
52 $filtered_roles = array_diff($global_roles, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID));
53
54 $roles = array();
55 foreach ($filtered_roles as $role) {
56 $obj_role = new ilObjRole($role);
57 $roles[$role] = $obj_role->getTitle();
58 }
59
60 return $roles;
61 }
62
67 public function saveConsumerObjectTypes(int $a_consumer_id, array $a_obj_types): void
68 {
69 $this->db->manipulate("DELETE FROM lti_ext_consumer_otype WHERE consumer_id = " . $this->db->quote($a_consumer_id, "integer"));
70
71 if ($a_obj_types) {
72 $query = "INSERT INTO lti_ext_consumer_otype (consumer_id, object_type) VALUES (%s, %s)";
73 $types = array("integer", "text");
74 foreach ($a_obj_types as $ot) {
75 $values = array($a_consumer_id, $ot);
76 $this->db->manipulateF($query, $types, $values);
77 }
78 }
79 }
80
84 public static function getActiveObjectTypes(int $a_consumer_id): array
85 {
86 global $DIC;
87 $ilDB = $DIC['ilDB'];
88
89 $result = $ilDB->query("SELECT object_type FROM lti_ext_consumer_otype WHERE consumer_id = " . $ilDB->quote($a_consumer_id, "integer"));
90
91 $obj_ids = array();
92 while ($record = $ilDB->fetchAssoc($result)) {
93 $obj_ids[] = $record['object_type'];
94 }
95 return $obj_ids;
96 }
97
101 public static function isEnabledForType(string $a_type): bool
102 {
106 $db = $GLOBALS['DIC']->database();
107
108 $query = 'select id from lti_ext_consumer join lti_ext_consumer_otype on id = consumer_id ' .
109 'WHERE active = ' . $db->quote(1, 'integer') . ' ' .
110 'AND object_type = ' . $db->quote($a_type, 'text');
111 $res = $db->query($query);
112 while ($row = $res->fetchObject()) {
113 return true;
114 }
115 return false;
116 }
117
123 public static function getEnabledConsumersForType(string $a_type): array
124 {
128 $db = $GLOBALS['DIC']->database();
129
130 $query = 'select distinct(id) id from lti_ext_consumer join lti_ext_consumer_otype on id = consumer_id ' .
131 'WHERE active = ' . $db->quote(1, 'integer') . ' ' .
132 'AND object_type = ' . $db->quote($a_type, 'text');
133 $res = $db->query($query);
134
135 $connector = new ilLTIDataConnector();
136 $consumers = array();
137 while ($row = $res->fetchObject()) {
138 $consumers[] = ilLTIPlatform::fromExternalConsumerId((int) $row->id, $connector);
139 }
140 return $consumers;
141 }
142
146 public static function lookupLTISettingsRefId(): ?int
147 {
148 $lti_ref_id = null;
149 $res = $GLOBALS['DIC']->database()->queryF(
150 '
151 SELECT object_reference.ref_id FROM object_reference, tree, object_data
152 WHERE tree.parent = %s
153 AND object_data.type = %s
154 AND object_reference.ref_id = tree.child
155 AND object_reference.obj_id = object_data.obj_id',
156 array('integer', 'text'),
157 array(SYSTEM_FOLDER_ID, 'ltis')
158 );
159 while ($row = $GLOBALS['DIC']->database()->fetchAssoc($res)) {
160 $lti_ref_id = (int) $row['ref_id'];
161 }
162 return $lti_ref_id;
163 }
164
169 public static function readReleaseObjects(): array
170 {
171 $db = $GLOBALS['DIC']->database();
172
173 $query = 'select ref_id, title from lti2_consumer join lti_ext_consumer ' .
174 'on id = ext_consumer_id where enabled = ' . $db->quote(1, 'integer');
175 $res = $db->query($query);
176
177 ilLoggerFactory::getLogger('ltis')->debug($query);
178
179 $rows = [];
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
181 $item['ref_id'] = $row->ref_id;
182 $item['title'] = $row->title;
183
184 $rows[] = $item;
185 }
186 return $rows;
187 }
188}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static fromExternalConsumerId(int $id, ilLTIDataConnector $dataConnector)
static getLogger(string $a_component_id)
Get component logger.
static lookupLTISettingsRefId()
Lookup ref_id.
static getActiveObjectTypes(int $a_consumer_id)
static readReleaseObjects()
Read released objects.
saveConsumerObjectTypes(int $a_consumer_id, array $a_obj_types)
__construct(int $a_id=0, bool $a_call_by_reference=true)
Class ilObjRole.
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...
ilDBInterface $db
const SYSTEM_ROLE_ID
Definition: constants.php:29
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
const SYSTEM_FOLDER_ID
Definition: constants.php:35
global $DIC
Definition: feed.php:28
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
$rows
Definition: xhr_table.php:10