ILIAS  release_8 Revision v8.24
class.ilDidacticTemplateSettings.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5
12{
13 private static ?ilDidacticTemplateSettings $instance = null;
14 private static array $instances = [];
15
17 private array $templates = [];
18 private string $obj_type = '';
19
21
22 private function __construct(string $a_obj_type = '')
23 {
24 global $DIC;
25
26 $this->obj_type = $a_obj_type;
27 $this->db = $DIC->database();
28 $this->read();
29 }
30
31 public static function getInstance(): ilDidacticTemplateSettings
32 {
33 if (self::$instance) {
34 return self::$instance;
35 }
36
37 return self::$instance = new ilDidacticTemplateSettings();
38 }
39
40 public static function getInstanceByObjectType(string $a_obj_type): ilDidacticTemplateSettings
41 {
42 return self::$instances[$a_obj_type] ?? (self::$instances[$a_obj_type] = new ilDidacticTemplateSettings($a_obj_type));
43 }
44
49 public static function lookupAssignedObjectTypes(): array
50 {
51 global $DIC;
52
53 $db = $DIC->database();
54 $query = 'select distinct (obj_type) from didactic_tpl_sa ' .
55 'group by obj_type';
56 $res = $db->query($query);
57 $types = [];
58 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
59 $types[] = $row->obj_type;
60 }
61
62 return $types;
63 }
64
68 public function getTemplates(): array
69 {
70 return $this->templates;
71 }
72
73 public function getObjectType(): string
74 {
75 return $this->obj_type;
76 }
77
81 public function readInactive(): bool
82 {
83 $query = 'SELECT dtpl.id FROM didactic_tpl_settings dtpl ';
84
85 if ($this->getObjectType()) {
86 $query .= 'JOIN didactic_tpl_sa tplsa ON dtpl.id = tplsa.id ';
87 }
88 $query .= 'WHERE enabled = ' . $this->db->quote(0, 'integer') . ' ';
89
90 if ($this->getObjectType()) {
91 $query .= 'AND obj_type = ' . $this->db->quote($this->getObjectType(), 'text');
92 }
93
94 $res = $this->db->query($query);
95 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
96 $this->templates[$row->id] = new ilDidacticTemplateSetting((int) $row->id);
97 }
98
99 return true;
100 }
101
106 protected function read(): bool
107 {
108 $query = 'SELECT dtpl.id FROM didactic_tpl_settings dtpl ';
109 if ($this->getObjectType()) {
110 $query .= 'JOIN didactic_tpl_sa tplsa ON dtpl.id = tplsa.id ';
111 }
112 $query .= 'WHERE enabled = ' . $this->db->quote(1, 'integer') . ' ';
113
114 if ($this->getObjectType()) {
115 $query .= 'AND obj_type = ' . $this->db->quote($this->getObjectType(), 'text');
116 }
117
118 $res = $this->db->query($query);
119 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
120 $this->templates[$row->id] = new ilDidacticTemplateSetting((int) $row->id);
121 }
122
123 return true;
124 }
125}
read()
Read active didactic templates.
static ilDidacticTemplateSettings $instance
static getInstanceByObjectType(string $a_obj_type)
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
query(string $query)
Run a (read-only) Query on the database.
$res
Definition: ltiservices.php:69
$query