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