ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
DataConnector.php
Go to the documentation of this file.
1 <?php
2 
4 
12 use PDO;
13 
26 {
27 
31  const CONSUMER_TABLE_NAME = 'lti2_consumer';
35  const TOOL_PROXY_TABLE_NAME = 'lti2_tool_proxy';
39  const CONTEXT_TABLE_NAME = 'lti2_context';
43  const RESOURCE_LINK_TABLE_NAME = 'lti2_resource_link';
47  const USER_RESULT_TABLE_NAME = 'lti2_user_result';
51  const RESOURCE_LINK_SHARE_KEY_TABLE_NAME = 'lti2_share_key';
55  const NONCE_TABLE_NAME = 'lti2_nonce';
56 
62  protected $db = null;
68  protected $dbTableNamePrefix = '';
74  protected $dateFormat = 'Y-m-d';
80  protected $timeFormat = 'H:i:s';
81 
88  public function __construct($db, $dbTableNamePrefix = '')
89  {
90 
91  $this->db = $db;
92  $this->dbTableNamePrefix = $dbTableNamePrefix;
93 
94  }
95 
96 ###
97 ### ToolConsumer methods
98 ###
99 
107  public function loadToolConsumer($consumer)
108  {
109 
110  $consumer->secret = 'secret';
111  $consumer->enabled = true;
112  $now = time();
113  $consumer->created = $now;
114  $consumer->updated = $now;
115 
116  return true;
117 
118  }
119 
127  public function saveToolConsumer($consumer)
128  {
129 
130  $consumer->updated = time();
131 
132  return true;
133 
134  }
135 
143  public function deleteToolConsumer($consumer)
144  {
145 
146  $consumer->initialize();
147 
148  return true;
149 
150  }
151 
157  public function getToolConsumers()
158  {
159 
160  return array();
161 
162  }
163 
164 
165 ###
166 ### ToolProxy methods
167 ###
168 
176  public function loadToolProxy($toolProxy)
177  {
178 
179  $now = time();
180  $toolProxy->created = $now;
181  $toolProxy->updated = $now;
182 
183  return true;
184 
185  }
186 
194  public function saveToolProxy($toolProxy)
195  {
196 
197  $toolProxy->updated = time();
198 
199  return true;
200 
201  }
202 
210  public function deleteToolProxy($toolProxy)
211  {
212 
213  $toolProxy->initialize();
214 
215  return true;
216 
217  }
218 
219 ###
220 ### Context methods
221 ###
222 
230  public function loadContext($context)
231  {
232 
233  $now = time();
234  $context->created = $now;
235  $context->updated = $now;
236 
237  return true;
238 
239  }
240 
248  public function saveContext($context)
249  {
250 
251  $context->updated = time();
252 
253  return true;
254 
255  }
256 
264  public function deleteContext($context)
265  {
266 
267  $context->initialize();
268 
269  return true;
270 
271  }
272 
273 ###
274 ### ResourceLink methods
275 ###
276 
284  public function loadResourceLink($resourceLink)
285  {
286 
287  $now = time();
288  $resourceLink->created = $now;
289  $resourceLink->updated = $now;
290 
291  return true;
292 
293  }
294 
302  public function saveResourceLink($resourceLink)
303  {
304 
305  $resourceLink->updated = time();
306 
307  return true;
308 
309  }
310 
318  public function deleteResourceLink($resourceLink)
319  {
320 
321  $resourceLink->initialize();
322 
323  return true;
324 
325  }
326 
339  public function getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
340  {
341 
342  return array();
343 
344  }
345 
353  public function getSharesResourceLink($resourceLink)
354  {
355 
356  return array();
357 
358  }
359 
360 ###
361 ### ConsumerNonce methods
362 ###
363 
371  public function loadConsumerNonce($nonce)
372  {
373  return false; // assume the nonce does not already exist
374 
375  }
376 
384  public function saveConsumerNonce($nonce)
385  {
386 
387  return true;
388 
389  }
390 
391 ###
392 ### ResourceLinkShareKey methods
393 ###
394 
402  public function loadResourceLinkShareKey($shareKey)
403  {
404 
405  return true;
406 
407  }
408 
416  public function saveResourceLinkShareKey($shareKey)
417  {
418 
419  return true;
420 
421  }
422 
430  public function deleteResourceLinkShareKey($shareKey)
431  {
432 
433  return true;
434 
435  }
436 
437 ###
438 ### User methods
439 ###
440 
448  public function loadUser($user)
449  {
450 
451  $now = time();
452  $user->created = $now;
453  $user->updated = $now;
454 
455  return true;
456 
457  }
458 
466  public function saveUser($user)
467  {
468 
469  $user->updated = time();
470 
471  return true;
472 
473  }
474 
482  public function deleteUser($user)
483  {
484 
485  $user->initialize();
486 
487  return true;
488 
489  }
490 
491 ###
492 ### Other methods
493 ###
494 
501  protected static function getConsumerKey($key)
502  {
503 
504  $len = strlen($key);
505  if ($len > 255) {
506  $key = 'sha512:' . hash('sha512', $key);
507  }
508 
509  return $key;
510 
511  }
512 
529  public static function getDataConnector($dbTableNamePrefix = '', $db = null, $type = '')
530  {
531 
532  if (is_null($dbTableNamePrefix)) {
533  $dbTableNamePrefix = '';
534  }
535  if (!is_null($db) && empty($type)) {
536  if (is_object($db)) {
537  $type = get_class($db);
538  }
539  }
540  $type = strtolower($type);
541  if (($type === 'pdo') && ($db->getAttribute(PDO::ATTR_DRIVER_NAME) === 'sqlite')) {
542  $type .= '_sqlite';
543  }
544  if (!empty($type)) {
545  $type ="DataConnector_{$type}";
546  } else {
547  $type ='DataConnector';
548  }
549  $type = "\\IMSGlobal\\LTI\\ToolProvider\\DataConnector\\{$type}";
550  $dataConnector = new $type($db, $dbTableNamePrefix);
551 
552  return $dataConnector;
553 
554  }
555 
565  static function getRandomString($length = 8)
566  {
567 
568  $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
569 
570  $value = '';
571  $charsLength = strlen($chars) - 1;
572 
573  for ($i = 1 ; $i <= $length; $i++) {
574  $value .= $chars[rand(0, $charsLength)];
575  }
576 
577  return $value;
578 
579  }
580 
591  static function quoted($value, $addQuotes = true)
592  {
593 
594  if (is_null($value)) {
595  $value = 'null';
596  } else {
597  $value = str_replace('\'', '\'\'', $value);
598  if ($addQuotes) {
599  $value = "'{$value}'";
600  }
601  }
602 
603  return $value;
604 
605  }
606 
607 }
$dbTableNamePrefix
Prefix for database table names.
const RESOURCE_LINK_TABLE_NAME
Default name for database table used to store resource links.
const RESOURCE_LINK_SHARE_KEY_TABLE_NAME
Default name for database table used to store resource link share keys.
loadResourceLinkShareKey($shareKey)
Load resource link share key object.
loadResourceLink($resourceLink)
Load resource link object.
$context
Definition: webdav.php:25
$type
static getDataConnector($dbTableNamePrefix='', $db=null, $type='')
Create data connector object.
static quoted($value, $addQuotes=true)
Quote a string for use in a database query.
const NONCE_TABLE_NAME
Default name for database table used to store nonce values.
$timeFormat
SQL time format (default = &#39;H:i:s&#39;)
const CONSUMER_TABLE_NAME
Default name for database table used to store tool consumers.
__construct($db, $dbTableNamePrefix='')
Class constructor.
const CONTEXT_TABLE_NAME
Default name for database table used to store contexts.
deleteToolProxy($toolProxy)
Delete tool proxy object.
deleteToolConsumer($consumer)
Delete tool consumer object.
deleteResourceLink($resourceLink)
Delete resource link object.
loadToolConsumer($consumer)
Load tool consumer object.
deleteResourceLinkShareKey($shareKey)
Delete resource link share key object.
getSharesResourceLink($resourceLink)
Get array of shares defined for this resource link.
$dateFormat
SQL date format (default = &#39;Y-m-d&#39;)
Class to provide a connection to a persistent store for LTI objects.
$user
Definition: migrateto20.php:57
const TOOL_PROXY_TABLE_NAME
Default name for database table used to store pending tool proxies.
loadToolProxy($toolProxy)
Load tool proxy object.
saveResourceLinkShareKey($shareKey)
Save resource link share key object.
saveResourceLink($resourceLink)
Save resource link object.
static getConsumerKey($key)
Return a hash of a consumer key for values longer than 255 characters.
static getRandomString($length=8)
Generate a random string.
$i
Definition: disco.tpl.php:19
const USER_RESULT_TABLE_NAME
Default name for database table used to store users.
saveToolProxy($toolProxy)
Save tool proxy object.
getUserResultSourcedIDsResourceLink($resourceLink, $localOnly, $idScope)
Get array of user objects.
hash(StreamInterface $stream, $algo, $rawOutput=false)
Calculate a hash of a Stream.
Definition: functions.php:406
saveToolConsumer($consumer)
Save tool consumer object.
$key
Definition: croninfo.php:18