ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjLTIAdministration.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2016 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once './Services/Object/classes/class.ilObject.php';
5 
13 {
14  public function __construct($a_id = 0, $a_call_by_reference = true)
15  {
16  $this->type = "ltis";
17  parent::__construct($a_id, $a_call_by_reference);
18  }
19 
23  public function getLTIObjectTypes()
24  {
25  $obj_def = new ilObjectDefinition();
26  return $obj_def->getLTIProviderTypes();
27  }
28 
32  public function getLTIRoles()
33  {
34  global $rbacreview;
35 
36  require_once("Services/AccessControl/classes/class.ilObjRole.php");
37 
38  $global_roles = $rbacreview->getGlobalRoles();
39 
40  $filtered_roles = array_diff($global_roles, array(SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID));
41 
42  $roles = array();
43  foreach ($filtered_roles as $role) {
44  $obj_role = new ilObjRole($role);
45  $roles[$role] = $obj_role->getTitle();
46  }
47 
48  return $roles;
49  }
50 
55  public function saveConsumerObjectTypes($a_consumer_id, $a_obj_types)
56  {
57  global $ilDB;
58 
59  $ilDB->manipulate("DELETE FROM lti_ext_consumer_otype WHERE consumer_id = " . $ilDB->quote($a_consumer_id, "integer"));
60 
61  if ($a_obj_types) {
62  $query = "INSERT INTO lti_ext_consumer_otype (consumer_id, object_type) VALUES (%s, %s)";
63  $types = array("integer", "text");
64  foreach ($a_obj_types as $ot) {
65  $values = array($a_consumer_id, $ot);
66  $ilDB->manipulateF($query, $types, $values);
67  }
68  }
69  }
70 
75  public function getActiveObjectTypes($a_consumer_id)
76  {
77  global $DIC;
78  $ilDB = $DIC['ilDB'];
79 
80  $result = $ilDB->query("SELECT object_type FROM lti_ext_consumer_otype WHERE consumer_id = " . $ilDB->quote($a_consumer_id, "integer"));
81 
82  $obj_ids = array();
83  while ($record = $ilDB->fetchAssoc($result)) {
84  array_push($obj_ids, $record['object_type']);
85  }
86  return $obj_ids;
87  }
88 
92  public static function isEnabledForType($a_type)
93  {
97  $db = $GLOBALS['DIC']->database();
98 
99  $query = 'select id from lti_ext_consumer join lti_ext_consumer_otype on id = consumer_id ' .
100  'WHERE active = ' . $db->quote(1, 'integer') . ' ' .
101  'AND object_type = ' . $db->quote($a_type, 'text');
102  $res = $db->query($query);
103  while ($row = $res->fetchObject()) {
104  return true;
105  }
106  return false;
107  }
108 
114  public static function getEnabledConsumersForType($a_type)
115  {
119  $db = $GLOBALS['DIC']->database();
120 
121  $query = 'select distinct(id) id from lti_ext_consumer join lti_ext_consumer_otype on id = consumer_id ' .
122  'WHERE active = ' . $db->quote(1, 'integer') . ' ' .
123  'AND object_type = ' . $db->quote($a_type, 'text');
124  $res = $db->query($query);
125 
126  $connector = new ilLTIDataConnector();
127  $consumers = array();
128  while ($row = $res->fetchObject()) {
129  $consumers[] = ilLTIToolConsumer::fromExternalConsumerId($row->id, $connector);
130  }
131  return $consumers;
132  }
133 
137  public static function lookupLTISettingsRefId()
138  {
139  $res = $GLOBALS['DIC']->database()->queryF(
140  '
141  SELECT object_reference.ref_id FROM object_reference, tree, object_data
142  WHERE tree.parent = %s
143  AND object_data.type = %s
144  AND object_reference.ref_id = tree.child
145  AND object_reference.obj_id = object_data.obj_id',
146  array('integer', 'text'),
147  array(SYSTEM_FOLDER_ID, 'ltis')
148  );
149  while ($row = $GLOBALS['DIC']->database()->fetchAssoc($res)) {
150  $lti_ref_id = $row['ref_id'];
151  }
152  return $lti_ref_id;
153  }
154 
158  public static function readReleaseObjects()
159  {
160  $db = $GLOBALS['DIC']->database();
161 
162  $query = 'select ref_id, title from lti2_consumer join lti_ext_consumer ' .
163  'on id = ext_consumer_id where enabled = ' . $db->quote(1, 'integer');
164  $res = $db->query($query);
165 
166  ilLoggerFactory::getLogger('lti')->debug($query);
167 
168  $rows = [];
169  while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
170  $item['ref_id'] = $row->ref_id;
171  $item['title'] = $row->title;
172 
173  $rows[] = $item;
174  }
175  return $rows;
176  }
177 }
Class ilObjRole.
$result
static readReleaseObjects()
Read released objects.
saveConsumerObjectTypes($a_consumer_id, $a_obj_types)
global $DIC
Definition: saml.php:7
Class to represent an LTI Data Connector for ILIAS.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$a_type
Definition: workflow.php:92
parses the objects.xml it handles the xml-description of all ilias objects
foreach($_POST as $key=> $value) $res
static lookupLTISettingsRefId()
Lookup ref_id.
$query
Create styles array
The data for the language used.
$rows
Definition: xhr_table.php:10
__construct($a_id=0, $a_call_by_reference=true)
global $ilDB
static getLogger($a_component_id)
Get component logger.
static fromExternalConsumerId($id, $dataConnector)