ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDidacticTemplateSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
27 private static ?ilDidacticTemplateSettings $instance = null;
28 private static array $instances = [];
29
31 private array $templates = [];
32 private string $obj_type = '';
33
35
36 private function __construct(string $a_obj_type = '')
37 {
38 global $DIC;
39
40 $this->obj_type = $a_obj_type;
41 $this->db = $DIC->database();
42 $this->read();
43 }
44
45 public static function getInstance(): ilDidacticTemplateSettings
46 {
47 if (self::$instance) {
48 return self::$instance;
49 }
50
51 return self::$instance = new ilDidacticTemplateSettings();
52 }
53
54 public static function getInstanceByObjectType(string $a_obj_type): ilDidacticTemplateSettings
55 {
56 return self::$instances[$a_obj_type] ?? (self::$instances[$a_obj_type] = new ilDidacticTemplateSettings($a_obj_type));
57 }
58
63 public static function lookupAssignedObjectTypes(): array
64 {
65 global $DIC;
66
67 $db = $DIC->database();
68 $query = 'select distinct (obj_type) from didactic_tpl_sa ' .
69 'group by obj_type';
70 $res = $db->query($query);
71 $types = [];
72 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
73 $types[] = $row->obj_type;
74 }
75
76 return $types;
77 }
78
82 public function getTemplates(): array
83 {
84 return $this->templates;
85 }
86
87 public function getObjectType(): string
88 {
89 return $this->obj_type;
90 }
91
95 public function readInactive(): bool
96 {
97 $query = 'SELECT dtpl.id FROM didactic_tpl_settings dtpl ';
98
99 if ($this->getObjectType()) {
100 $query .= 'JOIN didactic_tpl_sa tplsa ON dtpl.id = tplsa.id ';
101 }
102 $query .= 'WHERE enabled = ' . $this->db->quote(0, 'integer') . ' ';
103
104 if ($this->getObjectType()) {
105 $query .= 'AND obj_type = ' . $this->db->quote($this->getObjectType(), 'text');
106 }
107
108 $res = $this->db->query($query);
109 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
110 $this->templates[$row->id] = new ilDidacticTemplateSetting((int) $row->id);
111 }
112
113 return true;
114 }
115
120 protected function read(): bool
121 {
122 $query = 'SELECT dtpl.id FROM didactic_tpl_settings dtpl ';
123 if ($this->getObjectType()) {
124 $query .= 'JOIN didactic_tpl_sa tplsa ON dtpl.id = tplsa.id ';
125 }
126 $query .= 'WHERE enabled = ' . $this->db->quote(1, 'integer') . ' ';
127
128 if ($this->getObjectType()) {
129 $query .= 'AND obj_type = ' . $this->db->quote($this->getObjectType(), 'text');
130 }
131 $res = $this->db->query($query);
132 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
133 $this->templates[$row->id] = new ilDidacticTemplateSetting((int) $row->id);
134 }
135
136 return true;
137 }
138}
read()
Read active didactic templates.
static ilDidacticTemplateSettings $instance
static getInstanceByObjectType(string $a_obj_type)
Interface ilDBInterface.
query(string $query)
Run a (read-only) Query on the database.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26