ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilLTIConsumeProvider.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 
15 {
16  protected $id = 0;
17 
18  protected $title = '';
19 
20  protected $description = '';
21 
22  protected $availability = self::AVAILABILITY_NONE;
23  const AVAILABILITY_NONE = 0; // Provider is not longer available (error message)
24  const AVAILABILITY_EXISTING = 1; // Existing objects can still use the provider, new objects not
25  const AVAILABILITY_CREATE = 2; // New objects can use this provider
26 
27  protected $remarks = '';
28 
29  protected $time_to_delete = 0;
30 
31  protected $log_level = 0;
32 
33  protected $provider_url = '';
34 
35  protected $provider_key = '';
36 
37  protected $provider_secret = '';
38 
39  protected $provider_key_customizable = true;
40 
41  protected $provider_icon_filename = '';
42 
46  protected $providerIcon = null;
47 
51  protected $providerIconUploadInput = null;
52 
53  const CATEGORY_ASSESSMENT = 'assessment';
54  const CATEGORY_FEEDBACK = 'feedback';
55  const CATEGORY_CONTENT = 'content';
56  const CATEGORY_COMMUNICATION = 'communication';
57  const CATEGORY_ORGANISATION = 'organisation';
61  protected $category = self::CATEGORY_CONTENT;
62 
63  protected $provider_xml = '';
64 
65  protected $is_external_provider = false;
66 
67  //ToDo : necessary?
68  const LAUNCH_METHOD_OWN = 'ownWin';
69  const LAUNCH_METHOD_NEW = 'newWin';
70  protected $launch_method = self::LAUNCH_METHOD_NEW;
71 
72  protected $has_outcome = false;
73 
74  protected $mastery_score = 0.8;
75 
76  protected $keep_lp = false;
77 
84  protected $privacy_ident = self::PRIVACY_IDENT_IL_UUID_USER_ID;
85 
86  const PRIVACY_NAME_NONE = 0;
90  protected $privacy_name = self::PRIVACY_NAME_NONE;
91 
95  protected $include_user_picture = false;
96 
97  protected $privacy_comment_default = '';
98 
99  protected $always_learner = false;
100 
101  protected $use_provider_id = false;
102 
103  protected $use_xapi = false;
104 
105  protected $xapi_launch_url = '';
106 
107  protected $xapi_launch_key = '';
108 
109  protected $xapi_launch_secret = '';
110 
111  protected $xapi_activity_id = '';
112 
113  protected $custom_params = '';
114 
115  protected $keywords = '';
116 
117  protected $creator = 0;
118 
119  protected $accepted_by = 0;
120 
121  protected $is_global = false;
122 
127  public function __construct($providerId = null)
128  {
129  if ($providerId) {
130  $this->setId($providerId);
131  $this->load();
132  }
133  }
134 
140  public static function getInstance($providerId = null)
141  {
142  return new self($providerId);
143  }
144 
148  public function getId() : int
149  {
150  return $this->id;
151  }
152 
156  public function setId(int $id)
157  {
158  $this->id = $id;
159  }
160 
164  public function getTitle() : string
165  {
166  return $this->title;
167  }
168 
172  public function setTitle(string $title)
173  {
174  $this->title = $title;
175  }
176 
180  public function getDescription() : string
181  {
182  return $this->description;
183  }
184 
188  public function setDescription(string $description)
189  {
190  $this->description = $description;
191  }
192 
196  public function getAvailability() : int
197  {
198  return $this->availability;
199  }
200 
204  public function setAvailability(int $availability)
205  {
206  $this->availability = $availability;
207  }
208 
212  public function getRemarks() : string
213  {
214  return $this->remarks;
215  }
216 
220  public function setRemarks(string $remarks)
221  {
222  $this->remarks = $remarks;
223  }
224 
228  public function getTimeToDelete() : int
229  {
230  return $this->time_to_delete;
231  }
232 
236  public function setTimeToDelete(int $time_to_delete)
237  {
238  $this->time_to_delete = $time_to_delete;
239  }
240 
244  public function getLogLevel() : int
245  {
246  return $this->log_level;
247  }
248 
252  public function setLogLevel(int $log_level)
253  {
254  $this->log_level = $log_level;
255  }
256 
260  public function getProviderUrl() : string
261  {
262  return $this->provider_url;
263  }
264 
268  public function setProviderUrl(string $provider_url)
269  {
270  $this->provider_url = $provider_url;
271  }
272 
276  public function getProviderKey() : string
277  {
278  return $this->provider_key;
279  }
280 
284  public function setProviderKey(string $provider_key)
285  {
286  $this->provider_key = $provider_key;
287  }
288 
292  public function getProviderSecret() : string
293  {
294  return $this->provider_secret;
295  }
296 
300  public function setProviderSecret(string $provider_secret)
301  {
302  $this->provider_secret = $provider_secret;
303  }
304 
308  public function isProviderKeyCustomizable() : bool
309  {
311  }
312 
317  {
318  $this->provider_key_customizable = $provider_key_customizable;
319  }
320 
324  public function getProviderIconFilename() : string
325  {
327  }
328 
333  {
334  $this->provider_icon_filename = $provider_icon_filename;
335  }
336 
341  {
342  return $this->providerIcon;
343  }
344 
348  public function hasProviderIcon() : bool
349  {
350  if (!($this->providerIcon instanceof ilLTIConsumeProviderIcon)) {
351  return false;
352  }
353 
354  return strlen($this->providerIcon->getFilename());
355  }
356 
361  {
362  $this->providerIcon = $providerIcon;
363  }
364 
368  public function hasProviderIconUploadInput() : bool
369  {
370  return $this->providerIconUploadInput instanceof ilImageFileInputGUI;
371  }
372 
377  {
379  }
380 
385  {
386  $this->providerIconUploadInput = $providerIconUploadInput;
387  }
388 
392  public static function getCategoriesSelectOptions()
393  {
394  global $DIC; /* @var \ILIAS\DI\Container $DIC */
395 
396  $categories = [];
397 
398  foreach (self::getValidCategories() as $category) {
399  switch ($category) {
400  case self::CATEGORY_ORGANISATION:
401 
402  $translation = $DIC->language()->txt('rep_add_new_def_grp_organisation');
403  break;
404  case self::CATEGORY_COMMUNICATION:
405 
406  $translation = $DIC->language()->txt('rep_add_new_def_grp_communication');
407  break;
408  case self::CATEGORY_CONTENT:
409 
410  $translation = $DIC->language()->txt('rep_add_new_def_grp_content');
411  break;
412  case self::CATEGORY_ASSESSMENT:
413 
414  $translation = $DIC->language()->txt('rep_add_new_def_grp_assessment');
415  break;
416  case self::CATEGORY_FEEDBACK:
417 
418  $translation = $DIC->language()->txt('rep_add_new_def_grp_feedback');
419  break;
420  }
421 
422  $categories[$category] = $translation;
423  }
424 
425  return $categories;
426  }
427 
431  public static function getValidCategories()
432  {
433  return [
434  self::CATEGORY_ORGANISATION,
435  self::CATEGORY_COMMUNICATION,
436  self::CATEGORY_CONTENT,
437  self::CATEGORY_ASSESSMENT,
438  self::CATEGORY_FEEDBACK
439  ];
440  }
441 
446  public function isValidCategory(string $category)
447  {
448  return in_array($category, self::getValidCategories());
449  }
450 
454  public function getCategory() : string
455  {
456  return $this->category;
457  }
458 
462  public function setCategory(string $category)
463  {
464  $this->category = $category;
465  }
466 
470  public function getProviderXml() : string
471  {
472  return $this->provider_xml;
473  }
474 
478  public function setProviderXml(string $provider_xml)
479  {
480  $this->provider_xml = $provider_xml;
481  }
482 
486  public function isExternalProvider() : bool
487  {
489  }
490 
495  {
496  $this->is_external_provider = $is_external_provider;
497  }
498 
502  public function getLaunchMethod() : string
503  {
504  return $this->launch_method;
505  }
506 
510  public function setLaunchMethod(string $launch_method)
511  {
512  $this->launch_method = $launch_method;
513  }
514 
518  public function getHasOutcome() : bool
519  {
520  return $this->has_outcome;
521  }
522 
526  public function setHasOutcome(bool $has_outcome)
527  {
528  $this->has_outcome = $has_outcome;
529  }
530 
534  public function getMasteryScore() : float
535  {
536  return $this->mastery_score;
537  }
538 
542  public function setMasteryScore(float $mastery_score)
543  {
544  $this->mastery_score = $mastery_score;
545  }
546 
550  public function getMasteryScorePercent() : float
551  {
552  return $this->mastery_score * 100;
553  }
554 
558  public function setMasteryScorePercent(float $mastery_score_percent)
559  {
560  $this->mastery_score = $mastery_score_percent / 100;
561  }
562 
566  public function isKeepLp() : bool
567  {
568  return $this->keep_lp;
569  }
570 
574  public function setKeepLp(bool $keep_lp)
575  {
576  $this->keep_lp = $keep_lp;
577  }
578 
579 
583  public function getPrivacyIdent()
584  {
585  return $this->privacy_ident;
586  }
587 
592  {
593  $this->privacy_ident = $privacy_ident;
594  }
595 
599  public function getPrivacyName() : string
600  {
601  return $this->privacy_name;
602  }
603 
607  public function setPrivacyName(string $privacy_name)
608  {
609  $this->privacy_name = $privacy_name;
610  }
611 
615  public function getIncludeUserPicture() : bool
616  {
618  }
619 
624  {
625  $this->include_user_picture = $include_user_picture;
626  }
627 
631  public function getPrivacyCommentDefault() : string
632  {
634  }
635 
640  {
641  $this->privacy_comment_default = $privacy_comment_default;
642  }
643 
647  public function getAlwaysLearner() : bool
648  {
649  return $this->always_learner;
650  }
651 
655  public function setAlwaysLearner(bool $always_learner)
656  {
657  $this->always_learner = $always_learner;
658  }
659 
663  public function getUseProviderId() : bool
664  {
665  return $this->use_provider_id;
666  }
667 
671  public function setUseProviderId(bool $use_provider_id)
672  {
673  $this->use_provider_id = $use_provider_id;
674  }
675 
679  public function getUseXapi() : bool
680  {
681  return $this->use_xapi;
682  }
683 
687  public function setUseXapi(bool $use_xapi)
688  {
689  $this->use_xapi = $use_xapi;
690  }
691 
695  public function getXapiLaunchUrl() : string
696  {
697  return $this->xapi_launch_url;
698  }
699 
703  public function setXapiLaunchUrl(string $xapi_launch_url)
704  {
705  $this->xapi_launch_url = $xapi_launch_url;
706  }
707 
711  public function getXapiLaunchKey() : string
712  {
713  return $this->xapi_launch_key;
714  }
715 
719  public function setXapiLaunchKey(string $xapi_launch_key)
720  {
721  $this->xapi_launch_key = $xapi_launch_key;
722  }
723 
727  public function getXapiLaunchSecret() : string
728  {
730  }
731 
735  public function setXapiLaunchSecret(string $xapi_launch_secret)
736  {
737  $this->xapi_launch_secret = $xapi_launch_secret;
738  }
739 
743  public function getXapiActivityId() : string
744  {
746  }
747 
751  public function setXapiActivityId(string $xapi_activity_id)
752  {
753  $this->xapi_activity_id = $xapi_activity_id;
754  }
755 
759  public function getCustomParams() : string
760  {
761  return $this->custom_params;
762  }
763 
767  public function setCustomParams(string $custom_params)
768  {
769  $this->custom_params = $custom_params;
770  }
771 
775  public function getKeywordsArray()
776  {
777  $keywords = [];
778 
779  foreach (explode(';', $this->getKeywords()) as $keyword) {
780  $keywords[] = trim($keyword);
781  }
782 
783  return $keywords;
784  }
785 
789  public function getKeywords() : string
790  {
791  return $this->keywords;
792  }
793 
797  public function setKeywords(string $keywords)
798  {
799  $this->keywords = $keywords;
800  }
801 
805  public function getCreator() : int
806  {
807  return $this->creator;
808  }
809 
813  public function setCreator(int $creator)
814  {
815  $this->creator = $creator;
816  }
817 
821  public function getAcceptedBy() : int
822  {
823  return $this->accepted_by;
824  }
825 
829  public function setAcceptedBy(int $accepted_by)
830  {
831  $this->accepted_by = $accepted_by;
832  }
833 
837  public function isGlobal() : bool
838  {
839  return $this->is_global;
840  }
841 
845  public function setIsGlobal(bool $is_global)
846  {
847  $this->is_global = $is_global;
848  }
849 
854  public function assignFromDbRow($dbRow)
855  {
856  foreach ($dbRow as $field => $value) {
857  switch ($field) {
858  case 'id': $this->setId((int) $value); break;
859  case 'title': $this->setTitle($value); break;
860  case 'description': $this->setDescription($value); break;
861  case 'availability': $this->setAvailability((int) $value); break;
862  case 'remarks': $this->setRemarks($value); break;
863  case 'time_to_delete': $this->setTimeToDelete((int) $value); break;
864  case 'log_level': $this->setLogLevel((int) $value); break;
865  case 'provider_url': $this->setProviderUrl($value); break;
866  case 'provider_key': $this->setProviderKey($value); break;
867  case 'provider_secret': $this->setProviderSecret($value); break;
868  case 'provider_key_customizable': $this->setProviderKeyCustomizable((bool) $value); break;
869  case 'provider_icon': $this->setProviderIconFilename($value); break;
870  case 'category': $this->setCategory($value); break;
871  case 'provider_xml': $this->setProviderXml($value); break;
872  case 'external_provider': $this->setIsExternalProvider((bool) $value); break;
873  case 'launch_method': $this->setLaunchMethod($value); break;
874  case 'has_outcome': $this->setHasOutcome((bool) $value); break;
875  case 'mastery_score': $this->setMasteryScore((float) $value); break;
876  case 'keep_lp': $this->setKeepLp((bool) $value); break;
877  case 'privacy_ident': $this->setPrivacyIdent($value); break;
878  case 'privacy_name': $this->setPrivacyName($value); break;
879  case 'inc_usr_pic': $this->setIncludeUserPicture((bool) $value); break;
880  case 'privacy_comment_default': $this->setPrivacyCommentDefault($value); break;
881  case 'always_learner': $this->setAlwaysLearner((bool) $value); break;
882  case 'use_provider_id': $this->setUseProviderId((bool) $value); break;
883  case 'use_xapi': $this->setUseXapi((bool) $value); break;
884  case 'xapi_launch_url': $this->setXapiLaunchUrl((string) $value); break;
885  case 'xapi_launch_key': $this->setXapiLaunchKey((string) $value); break;
886  case 'xapi_launch_secret': $this->setXapiLaunchSecret((string) $value); break;
887  case 'xapi_activity_id': $this->setXapiActivityId((string) $value); break;
888  case 'custom_params': $this->setCustomParams((string) $value); break;
889  case 'keywords': $this->setKeywords((string) $value); break;
890  case 'creator': $this->setCreator((int) $value); break;
891  case 'accepted_by': $this->setAcceptedBy((int) $value); break;
892  case 'global': $this->setIsGlobal((bool) $value); break;
893  }
894  }
895 
896  $this->setProviderIcon(new ilLTIConsumeProviderIcon($this->getId()));
897  $this->getProviderIcon()->setFilename($this->getProviderIconFilename());
898  }
899 
903  public function load()
904  {
905  global $DIC; /* @var \ILIAS\DI\Container $DIC */
906 
907  $query = "SELECT * FROM lti_ext_provider WHERE id = %s";
908  $res = $DIC->database()->queryF($query, array('integer'), array($this->getId()));
909 
910  while ($row = $DIC->database()->fetchAssoc($res)) {
911  $this->assignFromDbRow($row);
912  }
913  }
914 
920  public function save()
921  {
922  if ($this->getId()) {
923  if ($this->hasProviderIconUploadInput()) {
924  $this->getProviderIcon()->handleUploadInputSubission($this->getProviderIconUploadInput());
925  $this->setProviderIconFilename($this->getProviderIcon()->getFilename());
926  }
927 
928  $this->update();
929  } else {
930  $this->insert();
931 
932  if ($this->hasProviderIconUploadInput()) {
933  $this->setProviderIcon(new ilLTIConsumeProviderIcon($this->getId()));
934 
935  $this->getProviderIcon()->handleUploadInputSubission($this->getProviderIconUploadInput());
936  $this->setProviderIconFilename($this->getProviderIcon()->getFilename());
937 
938  $this->update();
939  }
940  }
941  }
942 
943  public function update()
944  {
945  global $DIC; /* @var \ILIAS\DI\Container $DIC */
946 
947  $DIC->database()->update('lti_ext_provider', $this->getInsertUpdateFields(), array(
948  'id' => array('integer', $this->getId()),
949  ));
950  }
951 
952  public function insert()
953  {
954  global $DIC; /* @var \ILIAS\DI\Container $DIC */
955 
956  $this->setId($DIC->database()->nextId('lti_ext_provider'));
957 
958  $DIC->database()->insert('lti_ext_provider', $this->getInsertUpdateFields());
959  }
960 
964  protected function getInsertUpdateFields() : array
965  {
966  return array(
967  'id' => array('integer', $this->getId()),
968  'title' => array('text', $this->getTitle()),
969  'description' => array('text', $this->getDescription()),
970  'availability' => array('integer', $this->getAvailability()),
971  'remarks' => array('text', $this->getRemarks()),
972  'time_to_delete' => array('integer', $this->getTimeToDelete()),
973  'provider_url' => array('text', $this->getProviderUrl()),
974  'provider_key' => array('text', $this->getProviderKey()),
975  'provider_secret' => array('text', $this->getProviderSecret()),
976  'provider_key_customizable' => array('integer', $this->isProviderKeyCustomizable()),
977  'provider_icon' => array('text', $this->getProviderIconFilename()),
978  'category' => array('text', $this->getCategory()),
979  'provider_xml' => array('text', $this->getProviderXml()),
980  'external_provider' => array('integer', $this->isExternalProvider()),
981  'launch_method' => array('text', $this->getLaunchMethod()),
982  'has_outcome' => array('integer', $this->getHasOutcome()),
983  'mastery_score' => array('float', $this->getMasteryScore()),
984  'keep_lp' => array('integer', $this->isKeepLp()),
985  'privacy_ident' => array('integer', $this->getPrivacyIdent()),
986  'privacy_name' => array('integer', $this->getPrivacyName()),
987  'inc_usr_pic' => array('integer', $this->getIncludeUserPicture()),
988  'privacy_comment_default' => array('text', $this->getPrivacyCommentDefault()),
989  'always_learner' => array('integer', $this->getAlwaysLearner()),
990  'use_provider_id' => array('integer', $this->getUseProviderId()),
991  'use_xapi' => array('integer', $this->getUseXapi()),
992  'xapi_launch_url' => array('text', $this->getXapiLaunchUrl()),
993  'xapi_launch_key' => array('text', $this->getXapiLaunchKey()),
994  'xapi_launch_secret' => array('text', $this->getXapiLaunchSecret()),
995  'xapi_activity_id' => array('text', $this->getXapiActivityId()),
996  'custom_params' => array('text', $this->getCustomParams()),
997  'keywords' => array('text', $this->getKeywords()),
998  'creator' => array('integer', $this->getCreator()),
999  'accepted_by' => array('integer', $this->getAcceptedBy()),
1000  'global' => array('integer', (int) $this->isGlobal())
1001  );
1002  }
1003 
1004  public function delete()
1005  {
1006  global $DIC; /* @var \ILIAS\DI\Container $DIC */
1007 
1008  $DIC->database()->manipulateF(
1009  "DELETE FROM lti_ext_provider WHERE id = %s",
1010  ['integer'],
1011  [$this->getId()]
1012  );
1013  }
1014 
1015  public function isAcceptableAsGlobal()
1016  {
1017  return !$this->isGlobal() && (bool) $this->getCreator();
1018  }
1019 
1020  public function isResetableToUserDefined()
1021  {
1022  return $this->isGlobal() && (bool) $this->getCreator();
1023  }
1024 }
static getInstance($providerId=null)
Inits class static.
setIsExternalProvider(bool $is_external_provider)
setMasteryScore(float $mastery_score)
setLaunchMethod(string $launch_method)
setProviderIcon(ilLTIConsumeProviderIcon $providerIcon)
setTimeToDelete(int $time_to_delete)
setMasteryScorePercent(float $mastery_score_percent)
setXapiLaunchSecret(string $xapi_launch_secret)
setXapiLaunchUrl(string $xapi_launch_url)
setPrivacyName(string $privacy_name)
setIncludeUserPicture(bool $include_user_picture)
foreach($_POST as $key=> $value) $res
setUseProviderId(bool $use_provider_id)
setCustomParams(string $custom_params)
setProviderKey(string $provider_key)
global $DIC
Definition: goto.php:24
setAlwaysLearner(bool $always_learner)
setXapiActivityId(string $xapi_activity_id)
setProviderKeyCustomizable(bool $provider_key_customizable)
setProviderIconUploadInput(ilImageFileInputGUI $providerIconUploadInput)
$query
setXapiLaunchKey(string $xapi_launch_key)
setProviderIconFilename(string $provider_icon_filename)
setProviderXml(string $provider_xml)
This class represents an image file property in a property form.
__construct($providerId=null)
ilLTIConsumeProvider constructor.
setProviderSecret(string $provider_secret)
setDescription(string $description)
setProviderUrl(string $provider_url)
setPrivacyCommentDefault(string $privacy_comment_default)