ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.PCDefinition.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\COPage\PC;
22
27{
28 protected \ilDBInterface $db;
29 protected array $pc_def = [];
30 protected array $pc_def_by_name = [];
31 protected array $pc_gui_classes = array();
32 protected array $pc_gui_classes_lc = array();
33 protected array $pc_def_by_gui_class_cl = array();
34
35 public function __construct()
36 {
37 global $DIC;
38
39 $this->db = $DIC->database();
40 }
41
42 public function getRecords(): array
43 {
44 $db = $this->db;
45 $set = $db->query("SELECT * FROM copg_pc_def ORDER BY order_nr");
46 return $db->fetchAll($set);
47 }
48
49 protected function init(): void
50 {
51 $db = $this->db;
52 if ($this->pc_def == null) {
53 foreach ($this->getRecords() as $rec) {
54 $rec["pc_class"] = "ilPC" . $rec["name"];
55 $rec["pc_gui_class"] = "ilPC" . $rec["name"] . "GUI";
56 $this->pc_gui_classes[] = $rec["pc_gui_class"];
57 $this->pc_gui_classes_lc[] = strtolower($rec["pc_gui_class"]);
58 $this->pc_def[$rec["pc_type"]] = $rec;
59 $this->pc_def_by_name[$rec["name"]] = $rec;
60 $this->pc_def_by_gui_class_cl[strtolower($rec["pc_gui_class"])] = $rec;
61 }
62 }
63 }
64
65 public function getPCDefinitions(): array
66 {
67 $this->init();
68 return $this->pc_def;
69 }
70
74 public function getPCDefinitionByType(string $a_pc_type): ?array
75 {
76 $this->init();
77 return ($this->pc_def[$a_pc_type] ?? null);
78 }
79
83 public function getPCDefinitionByName(
84 string $a_pc_name
85 ): array {
86 $this->init();
87 return $this->pc_def_by_name[$a_pc_name];
88 }
89
94 string $a_gui_class_name
95 ): array {
96 $this->init();
97 $a_gui_class_name = strtolower($a_gui_class_name);
98 return $this->pc_def_by_gui_class_cl[$a_gui_class_name];
99 }
100
101 public function isPCGUIClassName(
102 string $a_class_name,
103 bool $a_lower_case = false
104 ): bool {
105 $this->init();
106 if ($a_lower_case) {
107 return in_array($a_class_name, $this->pc_gui_classes_lc);
108 } else {
109 return in_array($a_class_name, $this->pc_gui_classes);
110 }
111 }
112
117 string $a_name
118 ): ?\ILIAS\COPage\Editor\Components\PageComponentEditor {
119 $this->init();
120 $pc_def = $this->getPCDefinitionByName($a_name);
121 $pc_class = "ilPC" . $pc_def["name"] . "EditorGUI";
122 if (class_exists($pc_class)) {
123 return new $pc_class();
124 }
125 return null;
126 }
127
129 string $a_name
130 ): ?\ILIAS\COPage\Editor\Components\PageComponentModelProvider {
131 $this->init();
132 $pc_def = $this->getPCDefinitionByName($a_name);
133 $pc_class = "ilPC" . $pc_def["name"] . "ModelProvider";
134 if (class_exists($pc_class)) {
135 return new $pc_class();
136 }
137 return null;
138 }
139}
getPCDefinitionByType(string $a_pc_type)
Get PC definition by type.
getPCEditorInstanceByName(string $a_name)
Get instance.
isPCGUIClassName(string $a_class_name, bool $a_lower_case=false)
getPCDefinitionByGUIClassName(string $a_gui_class_name)
Get PC definition by name.
getPCDefinitionByName(string $a_pc_name)
Get PC definition by name.
init(array|\ArrayAccess &$define, array|\ArrayAccess &$implement, array|\ArrayAccess &$use, array|\ArrayAccess &$contribute, array|\ArrayAccess &$seek, array|\ArrayAccess &$provide, array|\ArrayAccess &$pull, array|\ArrayAccess &$internal,)
Definition: COPage.php:25
fetchAll(ilDBStatement $statement, int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
query(string $query)
Run a (read-only) Query on the database.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26