ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilPlugin.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
7
14abstract class ilPlugin
15{
16
20 protected $slot;
24 protected $active = false;
28 protected $iliasmaxversion = "";
32 protected $iliasminversion = "";
36 protected $version = "";
40 protected $lastupdateversion = "";
44 protected $dbversion = 0;
48 protected $lang_initialised = false;
52 protected $id = '';
57
58
59 public function __construct()
60 {
61 $this->__init();
62 $this->provider_collection = new PluginProviderCollection();
63 }
64
65
73 abstract public function getComponentType();
74
75
83 abstract public function getComponentName();
84
85
93 abstract public function getSlot();
94
95
103 abstract public function getSlotId();
104
105
114 abstract public function getPluginName();
115
116
122 private function setId($a_id)
123 {
124 $this->id = $a_id;
125 }
126
127
131 public function getId() : string
132 {
133 return $this->id;
134 }
135
136
142 private function setLastUpdateVersion(string $a_lastupdateversion)
143 {
144 $this->lastupdateversion = $a_lastupdateversion;
145 }
146
147
153 public function getLastUpdateVersion() : string
154 {
156 }
157
158
162 private function setVersion(string $a_version)
163 {
164 $this->version = $a_version;
165 }
166
167
171 public function getVersion() : string
172 {
173 return $this->version;
174 }
175
176
180 private function setIliasMinVersion(string $a_iliasminversion)
181 {
182 $this->iliasminversion = $a_iliasminversion;
183 }
184
185
189 public function getIliasMinVersion() : string
190 {
192 }
193
194
198 private function setIliasMaxVersion(string $a_iliasmaxversion)
199 {
200 $this->iliasmaxversion = $a_iliasmaxversion;
201 }
202
203
209 public function getIliasMaxVersion()
210 {
212 }
213
214
218 private function setActive(bool $a_active)
219 {
220 $this->active = $a_active;
221 }
222
223
227 public function getActive() : bool
228 {
229 return $this->active;
230 }
231
232
236 protected function setSlotObject(ilPluginSlot $a_slot)
237 {
238 $this->slot = $a_slot;
239 }
240
241
245 protected function getSlotObject() : ilPluginSlot
246 {
247 return $this->slot;
248 }
249
250
254 public function setDBVersion(int $a_dbversion)
255 {
256 $this->dbversion = $a_dbversion;
257 }
258
259
263 public function getDBVersion() : int
264 {
265 return $this->dbversion;
266 }
267
268
272 public function writeDBVersion(int $a_dbversion)
273 {
274 global $DIC;
275 $ilDB = $DIC->database();
276
277 $this->setDBVersion($a_dbversion);
278
279 $q = "UPDATE il_plugin SET db_version = " . $ilDB->quote((int) $this->getDBVersion(), "integer") .
280 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
281 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
282 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
283 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
284
285 $ilDB->manipulate($q);
286 }
287
288
294 public function getDirectory() : string
295 {
296 return $this->getSlotObject()->getPluginsDirectory() . "/" . $this->getPluginName();
297 }
298
299
303 public static function _getDirectory(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : string
304 {
305 return ilPluginSlot::_getPluginsDirectory($a_ctype, $a_cname, $a_slot_id) . "/" . $a_pname;
306 }
307
308
312 protected function getClassesDirectory() : string
313 {
314 return $this->getDirectory() . "/classes";
315 }
316
317
321 public function includeClass($a_class_file_name)
322 {
323 include_once($this->getClassesDirectory() . "/" . $a_class_file_name);
324 }
325
326
330 protected function getLanguageDirectory() : string
331 {
332 return $this->getDirectory() . "/lang";
333 }
334
335
339 public static function getAvailableLangFiles(string $a_lang_directory) : array
340 {
341 $langs = array();
342
343 if (!@is_dir($a_lang_directory)) {
344 return array();
345 }
346
347 $dir = opendir($a_lang_directory);
348 while ($file = readdir($dir)) {
349 if ($file != "." and
350 $file != ".."
351 ) {
352 // directories
353 if (@is_file($a_lang_directory . "/" . $file)) {
354 if (substr($file, 0, 6) == "ilias_"
355 && substr($file, strlen($file) - 5) == ".lang"
356 ) {
357 $langs[] = array(
358 "key" => substr($file, 6, 2),
359 "file" => $file,
360 "path" => $a_lang_directory . "/" . $file,
361 );
362 }
363 }
364 }
365 }
366
367 return $langs;
368 }
369
370
380 public static function hasConfigureClass(string $a_slot_dir, array $plugin_data, array $plugin_db_data) : bool
381 {
382 // Mantis: 23282: Disable plugin config page for incompatible plugins
383 if (!(ilComponent::isVersionGreaterString($plugin_data["ilias_min_version"], ILIAS_VERSION_NUMERIC)
384 || ilComponent::isVersionGreaterString(ILIAS_VERSION_NUMERIC, $plugin_data["ilias_max_version"])
385 || ilComponent::isVersionGreaterString($plugin_db_data["last_update_version"], $plugin_data["version"]))
386 ) {
387 if (is_file($a_slot_dir . "/" . $plugin_data["name"] . "/classes/class.il" . $plugin_data["name"] . "ConfigGUI.php")) {
388 return true;
389 }
390 }
391
392 return false;
393 }
394
395
403 public static function getConfigureClassName(array $plugin_data) : string
404 {
405 return "il" . $plugin_data["name"] . "ConfigGUI";
406 }
407
408
412 public function getPrefix() : string
413 {
414 return $this->getSlotObject()->getPrefix() . "_" . $this->getId();
415 }
416
417
426 public static function getDBUpdateScriptName(string $a_ctype, string $a_cname, string $a_slot_name, string $a_pname) : string
427 {
428 return "Customizing/global/plugins/" . $a_ctype . "/" . $a_cname . "/" .
429 $a_slot_name . "/" . $a_pname . "/sql/dbupdate.php";
430 }
431
432
436 public function getTablePrefix()
437 {
438 return $this->getPrefix();
439 }
440
441
447 public function updateLanguages($a_lang_keys = null)
448 {
449 ilGlobalCache::flushAll();
450
451 // get the keys of all installed languages if keys are not provided
452 if (!isset($a_lang_keys)) {
453 $a_lang_keys = array();
454 foreach (ilObjLanguage::getInstalledLanguages() as $langObj) {
455 if ($langObj->isInstalled()) {
456 $a_lang_keys[] = $langObj->getKey();
457 }
458 }
459 }
460
461 $langs = $this->getAvailableLangFiles($this->getLanguageDirectory());
462
463 $prefix = $this->getPrefix();
464
465 foreach ($langs as $lang) {
466 // check if the language should be updated, otherwise skip it
467 if (!in_array($lang['key'], $a_lang_keys)) {
468 continue;
469 }
470
471 $txt = file($this->getLanguageDirectory() . "/" . $lang["file"]);
472 $lang_array = array();
473
474 // get locally changed variables of the module (these should be kept)
475 $local_changes = ilObjLanguage::_getLocalChangesByModule($lang['key'], $prefix);
476
477 // get language data
478 if (is_array($txt)) {
479 foreach ($txt as $row) {
480 if ($row[0] != "#" && strpos($row, "#:#") > 0) {
481 $a = explode("#:#", trim($row));
482 $identifier = $prefix . "_" . trim($a[0]);
483 $value = trim($a[1]);
484
485 if (isset($local_changes[$identifier])) {
486 $lang_array[$identifier] = $local_changes[$identifier];
487 } else {
488 $lang_array[$identifier] = $value;
489 ilObjLanguage::replaceLangEntry($prefix, $identifier, $lang["key"], $value);
490 }
491 //echo "<br>-$prefix-".$prefix."_".trim($a[0])."-".$lang["key"]."-";
492 }
493 }
494 }
495
496 ilObjLanguage::replaceLangModule($lang["key"], $prefix, $lang_array);
497 }
498 }
499
500
504 public function updateDatabase()
505 {
506 global $DIC;
507 $ilDB = $DIC->database();
508 $lng = $DIC->language();
509
510 ilGlobalCache::flushAll();
511
512 $dbupdate = new ilPluginDBUpdate(
513 $this->getComponentType(),
514 $this->getComponentName(),
515 $this->getSlotId(),
516 $this->getPluginName(),
517 $ilDB,
518 true,
519 $this->getTablePrefix()
520 );
521
522 $result = $dbupdate->applyUpdate();
523 $message = '';
524 if ($dbupdate->updateMsg == "no_changes") {
525 $message = $lng->txt("no_changes") . ". " . $lng->txt("database_is_uptodate");
526 } else {
527 foreach ($dbupdate->updateMsg as $row) {
528 $message .= $lng->txt($row["msg"]) . ": " . $row["nr"] . "<br/>";
529 }
530 }
531
532 $this->message .= $message;
533 ilGlobalCache::flushAll();
534
535 return $result;
536 }
537
538
542 public function loadLanguageModule()
543 {
544 global $DIC;
545 $lng = $DIC->language();
546
547 if (!$this->lang_initialised && is_object($lng)) {
548 $lng->loadLanguageModule($this->getPrefix());
549 $this->lang_initialised = true;
550 }
551 }
552
553
557 public function txt(string $a_var) : string
558 {
559 global $DIC;
560 $lng = $DIC->language();
561 $this->loadLanguageModule();
562
563 return $lng->txt($this->getPrefix() . "_" . $a_var, $this->getPrefix());
564 }
565
566
574 public static function lookupTxt(string $a_mod_prefix, string $a_pl_id, string $a_lang_var) : string
575 {
576 global $DIC;
577 $lng = $DIC->language();
578
579 // this enables default language fallback
580 $prefix = $a_mod_prefix . "_" . $a_pl_id;
581
582 return $lng->txt($prefix . "_" . $a_lang_var, $prefix);
583 }
584
585
594 public static function langExitsById(string $pluginId, string $langVar) : bool
595 {
596 global $DIC;
597 $lng = $DIC->language();
598
600 $pl->loadLanguageModule();
601
602 return $lng->exists($pl->getPrefix() . "_" . $langVar);
603 }
604
605
615 public function getTemplate(string $a_template, bool $a_par1 = true, bool $a_par2 = true) : ilTemplate
616 {
617 return new ilTemplate($this->getDirectory() . "/templates/" . $a_template, $a_par1, $a_par2);
618 }
619
620
630 public static function _getImagePath(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname, string $a_img) : string
631 {
632 $d2 = ilComponent::lookupId($a_ctype, $a_cname) . "_" . $a_slot_id . "_" .
633 ilPlugin::lookupIdForName($a_ctype, $a_cname, $a_slot_id, $a_pname);
634
635 $img = ilUtil::getImagePath($d2 . "/" . $a_img);
636 if (is_int(strpos($img, "Customizing"))) {
637 return $img;
638 }
639
640 $d = ilPlugin::_getDirectory($a_ctype, $a_cname, $a_slot_id, $a_pname);
641
642 return $d . "/templates/images/" . $a_img;
643 }
644
645
649 public function getImagePath(string $a_img) : string
650 {
651 return self::_getImagePath(
652 $this->getComponentType(),
653 $this->getComponentName(),
654 $this->getSlotId(),
655 $this->getPluginName(),
656 $a_img
657 );
658 }
659
660
666 public function getStyleSheetLocation(string $a_css_file) : string
667 {
668 $d2 = ilComponent::lookupId($this->getComponentType(), $this->getComponentName()) . "_" . $this->getSlotId() . "_" .
670
671 $css = ilUtil::getStyleSheetLocation("output", $a_css_file, $d2);
672 if (is_int(strpos($css, "Customizing"))) {
673 return $css;
674 }
675
676 return $this->getDirectory() . "/templates/" . $a_css_file;
677 }
678
679
683 public function addBlockFile($a_tpl, $a_var, $a_block, $a_tplname)
684 {
685 $a_tpl->addBlockFile(
686 $a_var,
687 $a_block,
688 $this->getDirectory() . "/templates/" . $a_tplname
689 );
690 }
691
692
701 public static function createPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
702 {
703 global $DIC;
704 $ilDB = $DIC->database();
705
707
708 $q = "INSERT INTO il_plugin (component_type, component_name, slot_id, name)" .
709 " VALUES (" . $ilDB->quote($a_ctype, "text") . "," .
710 $ilDB->quote($a_cname, "text") . "," .
711 $ilDB->quote($a_slot_id, "text") . "," .
712 $ilDB->quote($a_pname, "text") . ")";
713
714 $ilDB->manipulate($q);
715 }
716
717
727 public static function getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : array
728 {
729 $cached_component = ilCachedComponentData::getInstance();
730 $rec = $cached_component->lookupPluginByName($a_pname);
731
732 if ($rec['component_type'] == $a_ctype and $rec['component_name'] == $a_cname and $rec['slot_id'] == $a_slot_id) {
733 return $rec;
734 } else {
735 throw new ilPluginException("No plugin record found for '{$a_ctype}', '{$a_cname}', '{$a_slot_id}', '{$a_pname}");
736 }
737 }
738
739
743 private function __init()
744 {
745 global $DIC;
746 $ilPluginAdmin = $DIC['ilPluginAdmin'];
747
748 // read/set basic data
750 $this->getComponentType(),
751 $this->getComponentName(),
752 $this->getSlotId(),
753 $this->getPluginName()
754 );
755 $this->setLastUpdateVersion((string) $rec["last_update_version"]);
756 $this->setDBVersion((int) $rec["db_version"]);
757 $this->setActive((bool) $rec["active"]);
758
759 // get id
760 $this->setId(
761 $ilPluginAdmin->getId(
762 $this->getComponentType(),
763 $this->getComponentName(),
764 $this->getSlotId(),
765 $this->getPluginName()
766 )
767 );
768
769 // get version
770 $this->setVersion(
771 $ilPluginAdmin->getVersion(
772 $this->getComponentType(),
773 $this->getComponentName(),
774 $this->getSlotId(),
775 $this->getPluginName()
776 )
777 );
778
779 // get ilias min version
780 $this->setIliasMinVersion(
781 $ilPluginAdmin->getIliasMinVersion(
782 $this->getComponentType(),
783 $this->getComponentName(),
784 $this->getSlotId(),
785 $this->getPluginName()
786 )
787 );
788
789 // get ilias max version
790 $this->setIliasMaxVersion(
791 $ilPluginAdmin->getIliasMaxVersion(
792 $this->getComponentType(),
793 $this->getComponentName(),
794 $this->getSlotId(),
795 $this->getPluginName()
796 )
797 );
798
799 // get slot object
800 $this->setSlotObject(
801 new ilPluginSlot(
802 $this->getComponentType(),
803 $this->getComponentName(),
804 $this->getSlotId()
805 )
806 );
807
808 // load language module
809
810 // Fix for authentication plugins
811 $this->loadLanguageModule();
812
813 // call slot and plugin init methods
814 $this->slotInit();
815 $this->init();
816 }
817
818
825 abstract protected function slotInit();
826
827
832 protected function init()
833 {
834 }
835
836
840 public function isActive()
841 {
842 global $DIC;
843 $ilPluginAdmin = $DIC['ilPluginAdmin'];
844
845 return $ilPluginAdmin->isActive(
846 $this->getComponentType(),
847 $this->getComponentName(),
848 $this->getSlotId(),
849 $this->getPluginName()
850 );
851 }
852
853
857 public function needsUpdate()
858 {
859 global $DIC;
860 $ilPluginAdmin = $DIC['ilPluginAdmin'];
861
862 return $ilPluginAdmin->needsUpdate(
863 $this->getComponentType(),
864 $this->getComponentName(),
865 $this->getSlotId(),
866 $this->getPluginName()
867 );
868 }
869
870
871 public function install()
872 {
873 global $DIC;
874 $ilDB = $DIC->database();
875
877 $q = "UPDATE il_plugin SET plugin_id = " . $ilDB->quote($this->getId(), "text") .
878 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
879 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
880 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
881 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
882
883 $ilDB->manipulate($q);
884 $this->afterInstall();
885 }
886
887
891 public function activate()
892 {
893 global $DIC;
894 $ilDB = $DIC->database();
895
897
898 $result = true;
899
900 // check whether update is necessary
901 if ($this->needsUpdate()) {
902 //$result = $this->isUpdatePossible();
903
904 // do update
905 if ($result === true) {
906 $result = $this->update();
907 }
908 }
909 if ($result === true) {
910 $result = $this->beforeActivation();
911 // activate plugin
912 if ($result === true) {
913 $q = "UPDATE il_plugin SET active = " . $ilDB->quote(1, "integer") .
914 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
915 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
916 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
917 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
918
919 $ilDB->manipulate($q);
920 $this->afterActivation();
921 }
922 }
924
925 return $result;
926 }
927
928
934 protected function afterInstall()
935 {
936 }
937
938
942 protected function beforeActivation()
943 {
944 return true; // false would indicate that anything went wrong
945 // activation would not proceed
946 // throw an exception in this case
947 //throw new ilPluginException($lng->txt(""));
948 }
949
950
954 protected function afterActivation()
955 {
956 }
957
958
962 public function deactivate()
963 {
964 global $DIC;
965 $ilDB = $DIC->database();
966
968
969 $result = true;
970
971 $q = "UPDATE il_plugin SET active = " . $ilDB->quote(0, "integer") .
972 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
973 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
974 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
975 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
976
977 $ilDB->manipulate($q);
978 $this->afterDeactivation();
979
980 return $result;
981 }
982
983
987 protected function afterDeactivation()
988 {
989 }
990
991
992 protected function beforeUninstall()
993 {
994 // plugin-specific
995 // false would indicate that anything went wrong
996 return true;
997 }
998
999
1000 final public function uninstall()
1001 {
1002 global $DIC;
1003 $ilDB = $DIC->database();
1004
1005 if ($this->beforeUninstall()) {
1006 // remove all language entries (see ilObjLanguage)
1007 // see updateLanguages
1008 $prefix = $this->getPrefix();
1009 if ($prefix) {
1010 $ilDB->manipulate(
1011 "DELETE FROM lng_data" .
1012 " WHERE module = " . $ilDB->quote($prefix, "text")
1013 );
1014 $ilDB->manipulate(
1015 "DELETE FROM lng_modules" .
1016 " WHERE module = " . $ilDB->quote($prefix, "text")
1017 );
1018 }
1019
1020 $this->clearEventListening();
1021
1022 // db version is kept in il_plugin - will be deleted, too
1023
1024 $q = "DELETE FROM il_plugin" .
1025 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
1026 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
1027 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
1028 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
1029 $ilDB->manipulate($q);
1030
1031 $ilDB->manipulateF('DELETE FROM ctrl_classfile WHERE comp_prefix=%s', [ilDBConstants::T_TEXT], [$this->getPrefix()]);
1032 $ilDB->manipulateF('DELETE FROM ctrl_calls WHERE comp_prefix=%s', [ilDBConstants::T_TEXT], [$this->getPrefix()]);
1033
1034 $this->afterUninstall();
1035
1037
1038 return true;
1039 }
1040
1041 return false;
1042 }
1043
1044
1048 protected function afterUninstall()
1049 {
1050 }
1051
1052
1056 public function update()
1057 {
1058 global $DIC;
1059 $ilDB = $DIC->database();
1060 $ilCtrl = $DIC->ctrl();
1061
1062 ilGlobalCache::flushAll();
1063
1064 $result = $this->beforeUpdate();
1065 if ($result === false) {
1066 return false;
1067 }
1068
1069 // Load language files
1070 $this->updateLanguages();
1071
1072 // DB update
1073 if ($result === true) {
1074 $result = $this->updateDatabase();
1075 }
1076
1077 // load control structure
1078 $structure_reader = new ilCtrlStructureReader();
1079 $structure_reader->readStructure(
1080 true,
1081 "./" . $this->getDirectory(),
1082 $this->getPrefix(),
1083 $this->getDirectory()
1084 );
1085
1086 // add config gui to the ctrl calls
1087 $ilCtrl->insertCtrlCalls(
1088 "ilobjcomponentsettingsgui",
1089 ilPlugin::getConfigureClassName(["name" => $this->getPluginName()]),
1090 $this->getPrefix()
1091 );
1092
1093 $this->readEventListening();
1094
1095 // set last update version to current version
1096 if ($result === true) {
1097 $q = "UPDATE il_plugin SET last_update_version = " . $ilDB->quote($this->getVersion(), "text") .
1098 " WHERE component_type = " . $ilDB->quote($this->getComponentType(), "text") .
1099 " AND component_name = " . $ilDB->quote($this->getComponentName(), "text") .
1100 " AND slot_id = " . $ilDB->quote($this->getSlotId(), "text") .
1101 " AND name = " . $ilDB->quote($this->getPluginName(), "text");
1102
1103 $ilDB->manipulate($q);
1104 $this->afterUpdate();
1105 }
1106 ilGlobalCache::flushAll();
1107
1108 return $result;
1109 }
1110
1111
1115 protected function readEventListening()
1116 {
1117 $reader = new ilPluginReader(
1118 $this->getDirectory() . '/plugin.xml',
1119 $this->getComponentType(),
1120 $this->getComponentName(),
1121 $this->getSlotId(),
1122 $this->getPluginName()
1123 );
1124 $reader->clearEvents();
1125 $reader->startParsing();
1126 }
1127
1128
1132 protected function clearEventListening()
1133 {
1134 $reader = new ilPluginReader(
1135 $this->getDirectory() . '/plugin.xml',
1136 $this->getComponentType(),
1137 $this->getComponentName(),
1138 $this->getSlotId(),
1139 $this->getPluginName()
1140 );
1141 $reader->clearEvents();
1142 }
1143
1144
1148 protected function beforeUpdate()
1149 {
1150 return true; // false would indicate that anything went wrong
1151 // update would not proceed
1152 // throw an exception in this case
1153 //throw new ilPluginException($lng->txt(""));
1154 }
1155
1156
1160 protected function afterUpdate()
1161 {
1162 }
1163
1172 public static function getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : ilPlugin
1173 {
1174 $slot_name = ilPluginSlot::lookupSlotName($a_ctype, $a_cname, $a_slot_id);
1175
1176 $cached_component = ilCachedComponentData::getInstance();
1177 $rec = $cached_component->lookCompId($a_ctype, $a_cname);
1178 if (!$rec) {
1179 return null;
1180 }
1181
1182 $file = "./Customizing/global/plugins/" . $a_ctype . "/" .
1183 $a_cname . "/" . $slot_name . "/" .
1184 $a_pname . "/classes/class.il" . $a_pname . "Plugin.php";
1185
1186 if (is_file($file)) {
1187 include_once($file);
1188 $class = "il" . $a_pname . "Plugin";
1189 $plugin = new $class();
1190
1191 return $plugin;
1192 }
1193 throw new ilPluginException("File : ".$file. " . does not Exist for plugin: ".$a_pname. " Check if your
1194 plugin is still marked as active in the DB Table 'il_plugin' but not installed anymore.");
1195 }
1196
1197
1208 public static function lookupStoredData(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname) : array
1209 {
1210 global $DIC;
1211 $ilDB = $DIC->database();
1212
1213 $q = "SELECT * FROM il_plugin WHERE" .
1214 " component_type = " . $ilDB->quote($a_ctype, "text") . " AND" .
1215 " component_name = " . $ilDB->quote($a_cname, "text") . " AND" .
1216 " slot_id = " . $ilDB->quote($a_slot_id, "text") . " AND" .
1217 " name = " . $ilDB->quote($a_pname, "text");
1218
1219 $set = $ilDB->query($q);
1220
1221 if ($ilDB->numRows($set) == 0) {
1222 return array();
1223 }
1224
1225 return $ilDB->fetchAssoc($set);
1226 }
1227
1228
1236 public static function getActivePluginsForSlot(string $a_ctype, string $a_cname, string $a_slot_id) : array
1237 {
1238 global $DIC;
1239 $ilPluginAdmin = $DIC['ilPluginAdmin'];
1240
1241 $plugins = array();
1242
1243 $cached_component = ilCachedComponentData::getInstance();
1244
1245 $lookupActivePluginsBySlotId = $cached_component->lookupActivePluginsBySlotId($a_slot_id);
1246 foreach ($lookupActivePluginsBySlotId as $rec) {
1247 if ($ilPluginAdmin->isActive($a_ctype, $a_cname, $a_slot_id, $rec["name"])) {
1248 $plugins[] = $rec["name"];
1249 }
1250 }
1251
1252 return $plugins;
1253 }
1254
1255
1265 public static function getActivePluginIdsForSlot(string $a_ctype, string $a_cname, string $a_slot_id) : array
1266 {
1267 global $DIC;
1268 $ilPluginAdmin = $DIC['ilPluginAdmin'];
1269
1270 $plugins = array();
1271 $cached_component = ilCachedComponentData::getInstance();
1272 $lookupActivePluginsBySlotId = $cached_component->lookupActivePluginsBySlotId($a_slot_id);
1273 foreach ($lookupActivePluginsBySlotId as $rec) {
1274 if ($ilPluginAdmin->isActive($a_ctype, $a_cname, $a_slot_id, $rec["name"])) {
1275 $plugins[] = $rec["plugin_id"];
1276 }
1277 }
1278
1279 return $plugins;
1280 }
1281
1282
1291 public static function lookupNameForId(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_id)
1292 {
1293 global $DIC;
1294 $ilDB = $DIC->database();
1295
1296 $q = "SELECT name FROM il_plugin " .
1297 " WHERE component_type = " . $ilDB->quote($a_ctype, "text") .
1298 " AND component_name = " . $ilDB->quote($a_cname, "text") .
1299 " AND slot_id = " . $ilDB->quote($a_slot_id, "text") .
1300 " AND plugin_id = " . $ilDB->quote($a_plugin_id, "text");
1301
1302 $set = $ilDB->query($q);
1303 if ($rec = $ilDB->fetchAssoc($set)) {
1304 return $rec["name"];
1305 }
1306 }
1307
1308
1317 public static function lookupIdForName(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_name) : string
1318 {
1319 global $DIC;
1320 $ilDB = $DIC->database();
1321
1322 $q = "SELECT plugin_id FROM il_plugin " .
1323 " WHERE component_type = " . $ilDB->quote($a_ctype, "text") .
1324 " AND component_name = " . $ilDB->quote($a_cname, "text") .
1325 " AND slot_id = " . $ilDB->quote($a_slot_id, "text") .
1326 " AND name = " . $ilDB->quote($a_plugin_name, "text");
1327
1328 $set = $ilDB->query($q);
1329 if ($rec = $ilDB->fetchAssoc($set)) {
1330 return $rec["plugin_id"];
1331 }
1332 }
1333
1334
1340 public static function lookupTypeInformationsForId(string $id)
1341 {
1342 global $DIC;
1343 $ilDB = $DIC->database();
1344
1345 $q = "SELECT component_type, component_name, slot_id FROM il_plugin "
1346 . " WHERE plugin_id = " . $ilDB->quote($id, "text");
1347
1348 $set = $ilDB->query($q);
1349 if ($rec = $ilDB->fetchAssoc($set)) {
1350 return [
1351 $rec["component_type"],
1352 $rec["component_name"],
1353 $rec["slot_id"],
1354 ];
1355 }
1356 }
1357
1358
1366 {
1367 global $DIC;
1368
1369 return new ilPluginGlobalScreenNullProvider($DIC, $this);
1370 }
1371
1372
1377 {
1379 $this->provider_collection->setMainBarProvider($this->promoteGlobalScreenProvider());
1380 }
1381
1383 }
1384
1385
1401 public function exchangeUIRendererAfterInitialization(\ILIAS\DI\Container $dic) : Closure
1402 {
1403 //This returns the callable of $c['ui.renderer'] without executing it.
1404 return $dic->raw('ui.renderer');
1405 }
1406
1407
1426 public function exchangeUIFactoryAfterInitialization(string $dic_key, \ILIAS\DI\Container $dic) : Closure
1427 {
1428 //This returns the callable of $c[$key] without executing it.
1429 return $dic->raw($dic_key);
1430 }
1431}
$result
An exception for terminatinating execution or to throw for unit testing.
setMainBarProvider(AbstractStaticMainMenuPluginProvider $static_mai_menu_provider)
static isVersionGreaterString($a_ver1, $a_ver2)
static lookupId($a_type, $a_name)
Lookup ID of a component.
Class ilCtrlStructureReader.
static _getLocalChangesByModule($a_key, $a_module)
Get the local changes of a language module.
static getInstalledLanguages()
Get the language objects of the installed languages.
static replaceLangEntry( $a_module, $a_identifier, $a_lang_key, $a_value, $a_local_change=null, $a_remarks=null)
Replace lang entry.
static getPluginObjectByType($type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin.
Database Update class.
Class ilPluginReader.
static lookupSlotName($a_ctype, $a_cname, $a_slot_id)
Lookup slot name for component and slot id.
static _getPluginsDirectory($a_ctype, $a_cname, $a_slot_id)
Get plugins directory.
Abstract Class ilPlugin.
setDBVersion(int $a_dbversion)
setActive(bool $a_active)
static lookupNameForId(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_id)
promoteGlobalScreenProvider()
exchangeUIFactoryAfterInitialization(string $dic_key, \ILIAS\DI\Container $dic)
This methods allows to replace some factory for UI Components (see src/UI) of ILIAS after initializat...
static _getDirectory(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Get plugin directory.
static _getImagePath(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname, string $a_img)
needsUpdate()
Check whether update is needed.
static getPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
getTablePrefix()
Get db table plugin prefix.
afterActivation()
After activation processing.
static lookupTxt(string $a_mod_prefix, string $a_pl_id, string $a_lang_var)
readEventListening()
Read the event listening definitions from the plugin.xml (if file exists)
updateLanguages($a_lang_keys=null)
exchangeUIRendererAfterInitialization(\ILIAS\DI\Container $dic)
This methods allows to replace the UI Renderer (see src/UI) of ILIAS after initialization by returnin...
includeClass($a_class_file_name)
Include (once) a class file.
activate()
Activate.
isActive()
Check whether plugin is active.
static getAvailableLangFiles(string $a_lang_directory)
Get array of all language files in the plugin.
getSlotId()
Get Slot ID.
static getActivePluginsForSlot(string $a_ctype, string $a_cname, string $a_slot_id)
setId($a_id)
Set Id.
getLastUpdateVersion()
Get Version of last update.
clearEventListening()
Clear the entries of this plugin in the event handling table.
static hasConfigureClass(string $a_slot_dir, array $plugin_data, array $plugin_db_data)
Has the plugin a configure class?
txt(string $a_var)
Get Language Variable (prefix will be prepended automatically)
addBlockFile($a_tpl, $a_var, $a_block, $a_tplname)
Add template content to placeholder variable.
getLanguageDirectory()
afterUpdate()
After update processing.
getPrefix()
Get plugin prefix, used for lang vars.
update()
Update plugin.
static getDBUpdateScriptName(string $a_ctype, string $a_cname, string $a_slot_name, string $a_pname)
afterInstall()
After install processing.
setIliasMinVersion(string $a_iliasminversion)
static langExitsById(string $pluginId, string $langVar)
Is searched lang var available in plugin lang files.
static getActivePluginIdsForSlot(string $a_ctype, string $a_cname, string $a_slot_id)
Get All active plugin ids for a slot.
static lookupIdForName(string $a_ctype, string $a_cname, string $a_slot_id, string $a_plugin_name)
static lookupStoredData(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
Lookup information data in il_plugin.
afterUninstall()
This is Plugin-Specific and is triggered after the uninstall command of a plugin.
init()
Object initialization.
getPluginName()
Get Plugin Name.
deactivate()
Deactivate.
getSlot()
Get Slot Name.
static lookupTypeInformationsForId(string $id)
getComponentName()
Get Component Name.
getTemplate(string $a_template, bool $a_par1=true, bool $a_par2=true)
gets a ilTemplate instance of a html-file in the plugin /templates
__init()
Default initialization.
writeDBVersion(int $a_dbversion)
beforeUpdate()
Before update processing.
setSlotObject(ilPluginSlot $a_slot)
getDirectory()
Get Plugin Directory.
getIliasMaxVersion()
Get Required ILIAS max.
beforeActivation()
Before activation processing.
static getPluginObject(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
loadLanguageModule()
Load language module for plugin.
getImagePath(string $a_img)
Get image path.
setLastUpdateVersion(string $a_lastupdateversion)
Set Version of last update.
slotInit()
Object initialization done by slot.
static getConfigureClassName(array $plugin_data)
Get plugin configure class name.
setVersion(string $a_version)
afterDeactivation()
After deactivation processing.
getStyleSheetLocation(string $a_css_file)
getComponentType()
Get Component Type.
setIliasMaxVersion(string $a_iliasmaxversion)
static createPluginRecord(string $a_ctype, string $a_cname, string $a_slot_id, string $a_pname)
getGlobalScreenProviderCollection()
updateDatabase()
Update database.
special template class to simplify handling of ITX/PEAR
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$txt
Definition: error.php:13
global $ilCtrl
Definition: ilias.php:18
const ILIAS_VERSION_NUMERIC
Class HTTPServicesTest.
Class ChatMainBarProvider \MainMenu\Provider.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$dic
Definition: result.php:13
$lng
global $ilDB
$lang
Definition: xapiexit.php:8
$message
Definition: xapiexit.php:14
$DIC
Definition: xapitoken.php:46