ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjectPlugin.php
Go to the documentation of this file.
1 <?php
2 
24 abstract class ilObjectPlugin extends ilObject2
25 {
26  protected ?ilPlugin $plugin = null;
28 
29  public function __construct(int $a_ref_id = 0)
30  {
31  global $DIC;
32  $this->component_factory = $DIC["component.factory"];
33  $this->initType();
34  parent::__construct($a_ref_id, true);
35  $this->plugin = $this->getPlugin();
36  }
37 
38 
43  public static function getPluginObjectByType(string $type): ?ilPlugin
44  {
45  global $DIC;
46  $component_factory = $DIC["component.factory"];
47  try {
48  return $component_factory->getPlugin($type);
49  } catch (InvalidArgumentException $e) {
50  ilLoggerFactory::getLogger("obj")->log("There was an error while instantiating repo plugin obj of type: $type. Error: $e");
51  }
52  return null;
53  }
54 
55  public static function lookupTxtById(
56  string $plugin_id,
57  string $lang_var
58  ): string {
59  $pl = self::getPluginObjectByType($plugin_id);
60  return $pl->txt($lang_var);
61  }
62 
67  protected function getPlugin(): ilPlugin
68  {
69  if (!$this->plugin) {
70  $this->plugin = $this->component_factory->getPlugin($this->getType());
71  }
72  return $this->plugin;
73  }
74 
75  final public function txt(string $a_var): string
76  {
77  return $this->getPlugin()->txt($a_var);
78  }
79 
84  public function getParentTypes(): array
85  {
86  return $this->plugin->getParentTypes();
87  }
88 
97  public static function langExitsById(string $pluginId, string $langVar): bool
98  {
99  global $DIC;
100  $lng = $DIC->language();
101 
102  $pl = self::getPluginObjectByType($pluginId);
103  $pl->loadLanguageModule();
104 
105  return $lng->exists($pl->getPrefix() . "_" . $langVar);
106  }
107 
108  public function getPrefix(): string
109  {
110  return $this->getPlugin()->getPrefix();
111  }
112 }
string $type
exists(string $a_topic)
Check if language entry exists.
getParentTypes()
returns a list of all repository object types which can be a parent of this type. ...
static getLogger(string $a_component_id)
Get component logger.
__construct(int $a_ref_id=0)
getPlugin(string $id)
Get the plugin for the given id.
ilComponentFactory $component_factory
global $DIC
Definition: feed.php:28
txt(string $a_var)
ilLanguage $lng
getPlugin()
Get plugin object.
static lookupTxtById(string $plugin_id, string $lang_var)
static getPluginObjectByType(string $type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin...
static langExitsById(string $pluginId, string $langVar)
Is searched lang var available in plugin lang files.
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...