ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
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
40
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';
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';
71
72 protected $has_outcome = false;
73
74 protected $mastery_score = 0.8;
75
76 protected $keep_lp = false;
77
84
90
94 protected $include_user_picture = false;
95
97
98 protected $always_learner = false;
99
100 protected $use_provider_id = false;
101
102 protected $use_xapi = false;
103
104 protected $xapi_launch_url = '';
105
106 protected $xapi_launch_key = '';
107
108 protected $xapi_launch_secret = '';
109
110 protected $xapi_activity_id = '';
111
112 protected $custom_params = '';
113
114 protected $keywords = '';
115
116 protected $creator = 0;
117
118 protected $accepted_by = 0;
119
120 protected $is_global = false;
121
126 public function __construct($providerId = null)
127 {
128 if ($providerId) {
129 $this->setId($providerId);
130 $this->load();
131 }
132 }
133
139 public static function getInstance($providerId = null)
140 {
141 return new self($providerId);
142 }
143
147 public function getId() : int
148 {
149 return $this->id;
150 }
151
155 public function setId(int $id)
156 {
157 $this->id = $id;
158 }
159
163 public function getTitle() : string
164 {
165 return $this->title;
166 }
167
171 public function setTitle(string $title)
172 {
173 $this->title = $title;
174 }
175
179 public function getDescription() : string
180 {
181 return $this->description;
182 }
183
187 public function setDescription(string $description)
188 {
189 $this->description = $description;
190 }
191
195 public function getAvailability() : int
196 {
197 return $this->availability;
198 }
199
203 public function setAvailability(int $availability)
204 {
205 $this->availability = $availability;
206 }
207
211 public function getRemarks() : string
212 {
213 return $this->remarks;
214 }
215
219 public function setRemarks(string $remarks)
220 {
221 $this->remarks = $remarks;
222 }
223
227 public function getTimeToDelete() : int
228 {
230 }
231
235 public function setTimeToDelete(int $time_to_delete)
236 {
237 $this->time_to_delete = $time_to_delete;
238 }
239
243 public function getLogLevel() : int
244 {
245 return $this->log_level;
246 }
247
251 public function setLogLevel(int $log_level)
252 {
253 $this->log_level = $log_level;
254 }
255
259 public function getProviderUrl() : string
260 {
261 return $this->provider_url;
262 }
263
267 public function setProviderUrl(string $provider_url)
268 {
269 $this->provider_url = $provider_url;
270 }
271
275 public function getProviderKey() : string
276 {
277 return $this->provider_key;
278 }
279
283 public function setProviderKey(string $provider_key)
284 {
285 $this->provider_key = $provider_key;
286 }
287
291 public function getProviderSecret() : string
292 {
294 }
295
299 public function setProviderSecret(string $provider_secret)
300 {
301 $this->provider_secret = $provider_secret;
302 }
303
307 public function isProviderKeyCustomizable() : bool
308 {
310 }
311
316 {
317 $this->provider_key_customizable = $provider_key_customizable;
318 }
319
323 public function getProviderIconFilename() : string
324 {
326 }
327
332 {
333 $this->provider_icon_filename = $provider_icon_filename;
334 }
335
340 {
341 return $this->providerIcon;
342 }
343
347 public function hasProviderIcon() : bool
348 {
349 if (!($this->providerIcon instanceof ilLTIConsumeProviderIcon)) {
350 return false;
351 }
352
353 return strlen($this->providerIcon->getFilename());
354 }
355
360 {
361 $this->providerIcon = $providerIcon;
362 }
363
367 public function hasProviderIconUploadInput() : bool
368 {
369 return $this->providerIconUploadInput instanceof ilImageFileInputGUI;
370 }
371
376 {
378 }
379
384 {
385 $this->providerIconUploadInput = $providerIconUploadInput;
386 }
387
391 public static function getCategoriesSelectOptions()
392 {
393 global $DIC; /* @var \ILIAS\DI\Container $DIC */
394
395 $categories = [];
396
397 foreach (self::getValidCategories() as $category) {
398 switch ($category) {
400
401 $translation = $DIC->language()->txt('rep_add_new_def_grp_organisation');
402 break;
404
405 $translation = $DIC->language()->txt('rep_add_new_def_grp_communication');
406 break;
408
409 $translation = $DIC->language()->txt('rep_add_new_def_grp_content');
410 break;
412
413 $translation = $DIC->language()->txt('rep_add_new_def_grp_assessment');
414 break;
416
417 $translation = $DIC->language()->txt('rep_add_new_def_grp_feedback');
418 break;
419 }
420
421 $categories[$category] = $translation;
422 }
423
424 return $categories;
425 }
426
430 public static function getValidCategories()
431 {
432 return [
438 ];
439 }
440
445 public function isValidCategory(string $category)
446 {
447 return in_array($category, self::getValidCategories());
448 }
449
453 public function getCategory() : string
454 {
455 return $this->category;
456 }
457
461 public function setCategory(string $category)
462 {
463 $this->category = $category;
464 }
465
469 public function getProviderXml() : string
470 {
471 return $this->provider_xml;
472 }
473
477 public function setProviderXml(string $provider_xml)
478 {
479 $this->provider_xml = $provider_xml;
480 }
481
485 public function isExternalProvider() : bool
486 {
488 }
489
494 {
495 $this->is_external_provider = $is_external_provider;
496 }
497
501 public function getLaunchMethod() : string
502 {
504 }
505
509 public function setLaunchMethod(string $launch_method)
510 {
511 $this->launch_method = $launch_method;
512 }
513
517 public function getHasOutcome() : bool
518 {
519 return $this->has_outcome;
520 }
521
525 public function setHasOutcome(bool $has_outcome)
526 {
527 $this->has_outcome = $has_outcome;
528 }
529
533 public function getMasteryScore() : float
534 {
536 }
537
541 public function setMasteryScore(float $mastery_score)
542 {
543 $this->mastery_score = $mastery_score;
544 }
545
549 public function getMasteryScorePercent() : float
550 {
551 return $this->mastery_score * 100;
552 }
553
557 public function setMasteryScorePercent(float $mastery_score_percent)
558 {
559 $this->mastery_score = $mastery_score_percent / 100;
560 }
561
565 public function isKeepLp() : bool
566 {
567 return $this->keep_lp;
568 }
569
573 public function setKeepLp(bool $keep_lp)
574 {
575 $this->keep_lp = $keep_lp;
576 }
577
578
582 public function getPrivacyIdent()
583 {
585 }
586
591 {
592 $this->privacy_ident = $privacy_ident;
593 }
594
598 public function getPrivacyName() : string
599 {
600 return $this->privacy_name;
601 }
602
606 public function setPrivacyName(string $privacy_name)
607 {
608 $this->privacy_name = $privacy_name;
609 }
610
614 public function getIncludeUserPicture() : bool
615 {
617 }
618
623 {
624 $this->include_user_picture = $include_user_picture;
625 }
626
630 public function getPrivacyCommentDefault() : string
631 {
633 }
634
639 {
640 $this->privacy_comment_default = $privacy_comment_default;
641 }
642
646 public function getAlwaysLearner() : bool
647 {
649 }
650
654 public function setAlwaysLearner(bool $always_learner)
655 {
656 $this->always_learner = $always_learner;
657 }
658
662 public function getUseProviderId() : bool
663 {
665 }
666
670 public function setUseProviderId(bool $use_provider_id)
671 {
672 $this->use_provider_id = $use_provider_id;
673 }
674
678 public function getUseXapi() : bool
679 {
680 return $this->use_xapi;
681 }
682
686 public function setUseXapi(bool $use_xapi)
687 {
688 $this->use_xapi = $use_xapi;
689 }
690
694 public function getXapiLaunchUrl() : string
695 {
697 }
698
702 public function setXapiLaunchUrl(string $xapi_launch_url)
703 {
704 $this->xapi_launch_url = $xapi_launch_url;
705 }
706
710 public function getXapiLaunchKey() : string
711 {
713 }
714
718 public function setXapiLaunchKey(string $xapi_launch_key)
719 {
720 $this->xapi_launch_key = $xapi_launch_key;
721 }
722
726 public function getXapiLaunchSecret() : string
727 {
729 }
730
735 {
736 $this->xapi_launch_secret = $xapi_launch_secret;
737 }
738
742 public function getXapiActivityId() : string
743 {
745 }
746
750 public function setXapiActivityId(string $xapi_activity_id)
751 {
752 $this->xapi_activity_id = $xapi_activity_id;
753 }
754
758 public function getCustomParams() : string
759 {
761 }
762
766 public function setCustomParams(string $custom_params)
767 {
768 $this->custom_params = $custom_params;
769 }
770
774 public function getKeywordsArray()
775 {
776 $keywords = [];
777
778 foreach (explode(';', $this->getKeywords()) as $keyword) {
779 $keywords[] = trim($keyword);
780 }
781
782 return $keywords;
783 }
784
788 public function getKeywords() : string
789 {
790 return $this->keywords;
791 }
792
796 public function setKeywords(string $keywords)
797 {
798 $this->keywords = $keywords;
799 }
800
804 public function getCreator() : int
805 {
806 return $this->creator;
807 }
808
812 public function setCreator(int $creator)
813 {
814 $this->creator = $creator;
815 }
816
820 public function getAcceptedBy() : int
821 {
822 return $this->accepted_by;
823 }
824
828 public function setAcceptedBy(int $accepted_by)
829 {
830 $this->accepted_by = $accepted_by;
831 }
832
836 public function isGlobal() : bool
837 {
838 return $this->is_global;
839 }
840
844 public function setIsGlobal(bool $is_global)
845 {
846 $this->is_global = $is_global;
847 }
848
853 public function assignFromDbRow($dbRow)
854 {
855 foreach ($dbRow as $field => $value) {
856 switch ($field) {
857 case 'id': $this->setId((int) $value); break;
858 case 'title': $this->setTitle($value); break;
859 case 'description': $this->setDescription($value); break;
860 case 'availability': $this->setAvailability((int) $value); break;
861 case 'remarks': $this->setRemarks($value); break;
862 case 'time_to_delete': $this->setTimeToDelete((int) $value); break;
863 case 'log_level': $this->setLogLevel((int) $value); break;
864 case 'provider_url': $this->setProviderUrl($value); break;
865 case 'provider_key': $this->setProviderKey($value); break;
866 case 'provider_secret': $this->setProviderSecret($value); break;
867 case 'provider_key_customizable': $this->setProviderKeyCustomizable((bool) $value); break;
868 case 'provider_icon': $this->setProviderIconFilename($value); break;
869 case 'category': $this->setCategory($value); break;
870 case 'provider_xml': $this->setProviderXml($value); break;
871 case 'external_provider': $this->setIsExternalProvider((bool) $value); break;
872 case 'launch_method': $this->setLaunchMethod($value); break;
873 case 'has_outcome': $this->setHasOutcome((bool) $value); break;
874 case 'mastery_score': $this->setMasteryScore((float) $value); break;
875 case 'keep_lp': $this->setKeepLp((bool) $value); break;
876 case 'privacy_ident': $this->setPrivacyIdent($value); break;
877 case 'privacy_name': $this->setPrivacyName($value); break;
878 case 'inc_usr_pic': $this->setIncludeUserPicture((bool) $value); break;
879 case 'privacy_comment_default': $this->setPrivacyCommentDefault($value); break;
880 case 'always_learner': $this->setAlwaysLearner((bool) $value); break;
881 case 'use_provider_id': $this->setUseProviderId((bool) $value); break;
882 case 'use_xapi': $this->setUseXapi((bool) $value); break;
883 case 'xapi_launch_url': $this->setXapiLaunchUrl((string) $value); break;
884 case 'xapi_launch_key': $this->setXapiLaunchKey((string) $value); break;
885 case 'xapi_launch_secret': $this->setXapiLaunchSecret((string) $value); break;
886 case 'xapi_activity_id': $this->setXapiActivityId((string) $value); break;
887 case 'custom_params': $this->setCustomParams((string) $value); break;
888 case 'keywords': $this->setKeywords((string) $value); break;
889 case 'creator': $this->setCreator((int) $value); break;
890 case 'accepted_by': $this->setAcceptedBy((int) $value); break;
891 case 'global': $this->setIsGlobal((bool) $value); break;
892 }
893 }
894
895 $this->setProviderIcon(new ilLTIConsumeProviderIcon($this->getId()));
896 $this->getProviderIcon()->setFilename($this->getProviderIconFilename());
897 }
898
902 public function load()
903 {
904 global $DIC; /* @var \ILIAS\DI\Container $DIC */
905
906 $query = "SELECT * FROM lti_ext_provider WHERE id = %s";
907 $res = $DIC->database()->queryF($query, array('integer'), array($this->getId()));
908
909 while ($row = $DIC->database()->fetchAssoc($res)) {
910 $this->assignFromDbRow($row);
911 }
912 }
913
919 public function save()
920 {
921 if ($this->getId()) {
922 if ($this->hasProviderIconUploadInput()) {
923 $this->getProviderIcon()->handleUploadInputSubission($this->getProviderIconUploadInput());
924 $this->setProviderIconFilename($this->getProviderIcon()->getFilename());
925 }
926
927 $this->update();
928 } else {
929 $this->insert();
930
931 if ($this->hasProviderIconUploadInput()) {
932 $this->setProviderIcon(new ilLTIConsumeProviderIcon($this->getId()));
933
934 $this->getProviderIcon()->handleUploadInputSubission($this->getProviderIconUploadInput());
935 $this->setProviderIconFilename($this->getProviderIcon()->getFilename());
936
937 $this->update();
938 }
939 }
940 }
941
942 public function update()
943 {
944 global $DIC; /* @var \ILIAS\DI\Container $DIC */
945
946 $DIC->database()->update('lti_ext_provider', $this->getInsertUpdateFields(), array(
947 'id' => array('integer', $this->getId()),
948 ));
949 }
950
951 public function insert()
952 {
953 global $DIC; /* @var \ILIAS\DI\Container $DIC */
954
955 $this->setId($DIC->database()->nextId('lti_ext_provider'));
956
957 $DIC->database()->insert('lti_ext_provider', $this->getInsertUpdateFields());
958 }
959
963 protected function getInsertUpdateFields() : array
964 {
965 return array(
966 'id' => array('integer', $this->getId()),
967 'title' => array('text', $this->getTitle()),
968 'description' => array('text', $this->getDescription()),
969 'availability' => array('integer', $this->getAvailability()),
970 'remarks' => array('text', $this->getRemarks()),
971 'time_to_delete' => array('integer', $this->getTimeToDelete()),
972 'provider_url' => array('text', $this->getProviderUrl()),
973 'provider_key' => array('text', $this->getProviderKey()),
974 'provider_secret' => array('text', $this->getProviderSecret()),
975 'provider_key_customizable' => array('integer', $this->isProviderKeyCustomizable()),
976 'provider_icon' => array('text', $this->getProviderIconFilename()),
977 'category' => array('text', $this->getCategory()),
978 'provider_xml' => array('text', $this->getProviderXml()),
979 'external_provider' => array('integer', $this->isExternalProvider()),
980 'launch_method' => array('text', $this->getLaunchMethod()),
981 'has_outcome' => array('integer', $this->getHasOutcome()),
982 'mastery_score' => array('float', $this->getMasteryScore()),
983 'keep_lp' => array('integer', $this->isKeepLp()),
984 'privacy_ident' => array('integer', $this->getPrivacyIdent()),
985 'privacy_name' => array('integer', $this->getPrivacyName()),
986 'inc_usr_pic' => array('integer', $this->getIncludeUserPicture()),
987 'privacy_comment_default' => array('text', $this->getPrivacyCommentDefault()),
988 'always_learner' => array('integer', $this->getAlwaysLearner()),
989 'use_provider_id' => array('integer', $this->getUseProviderId()),
990 'use_xapi' => array('integer', $this->getUseXapi()),
991 'xapi_launch_url' => array('text', $this->getXapiLaunchUrl()),
992 'xapi_launch_key' => array('text', $this->getXapiLaunchKey()),
993 'xapi_launch_secret' => array('text', $this->getXapiLaunchSecret()),
994 'xapi_activity_id' => array('text', $this->getXapiActivityId()),
995 'custom_params' => array('text', $this->getCustomParams()),
996 'keywords' => array('text', $this->getKeywords()),
997 'creator' => array('integer', $this->getCreator()),
998 'accepted_by' => array('integer', $this->getAcceptedBy()),
999 'global' => array('integer', (int) $this->isGlobal())
1000 );
1001 }
1002
1003 public function delete()
1004 {
1005 global $DIC; /* @var \ILIAS\DI\Container $DIC */
1006
1007 $DIC->database()->manipulateF(
1008 "DELETE FROM lti_ext_provider WHERE id = %s",
1009 ['integer'],
1010 [$this->getId()]
1011 );
1012 }
1013
1014 public function isAcceptableAsGlobal()
1015 {
1016 return !$this->isGlobal() && (bool) $this->getCreator();
1017 }
1018
1020 {
1021 return $this->isGlobal() && (bool) $this->getCreator();
1022 }
1023}
An exception for terminatinating execution or to throw for unit testing.
This class represents an image file property in a property form.
setProviderUrl(string $provider_url)
setPrivacyCommentDefault(string $privacy_comment_default)
setUseProviderId(bool $use_provider_id)
setCustomParams(string $custom_params)
setTimeToDelete(int $time_to_delete)
setProviderIconUploadInput(ilImageFileInputGUI $providerIconUploadInput)
setDescription(string $description)
setXapiLaunchSecret(string $xapi_launch_secret)
setProviderIconFilename(string $provider_icon_filename)
setProviderKey(string $provider_key)
setMasteryScorePercent(float $mastery_score_percent)
setMasteryScore(float $mastery_score)
setIncludeUserPicture(bool $include_user_picture)
setIsExternalProvider(bool $is_external_provider)
setXapiLaunchUrl(string $xapi_launch_url)
setAlwaysLearner(bool $always_learner)
setProviderKeyCustomizable(bool $provider_key_customizable)
setProviderIcon(ilLTIConsumeProviderIcon $providerIcon)
setXapiActivityId(string $xapi_activity_id)
__construct($providerId=null)
ilLTIConsumeProvider constructor.
setXapiLaunchKey(string $xapi_launch_key)
setLaunchMethod(string $launch_method)
setProviderSecret(string $provider_secret)
setProviderXml(string $provider_xml)
setPrivacyName(string $privacy_name)
static getInstance($providerId=null)
Inits class static.
$query
foreach($_POST as $key=> $value) $res
$DIC
Definition: xapitoken.php:46