ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDidacticTemplateSettings.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
5
13{
14 private static $instance = null;
15 private static $instances = null;
16
17
18 private $templates = array();
19 private $obj_type = '';
20
25 private function __construct($a_obj_type = '')
26 {
27 $this->obj_type = $a_obj_type;
28 $this->read();
29 }
30
35 public static function getInstance()
36 {
37 if (self::$instance) {
38 return self::$instance;
39 }
40 return self::$instance = new ilDidacticTemplateSettings();
41 }
42
48 public static function getInstanceByObjectType($a_obj_type)
49 {
50 if (self::$instances[$a_obj_type]) {
51 return self::$instances[$a_obj_type];
52 }
53 return self::$instances[$a_obj_type] = new ilDidacticTemplateSettings($a_obj_type);
54 }
55
60 public static function lookupAssignedObjectTypes() : array
61 {
62 global $DIC;
63
64 $db = $DIC->database();
65 $query = 'select distinct (obj_type) from didactic_tpl_sa ' .
66 'group by obj_type';
67 $res = $db->query($query);
68 $types = [];
69 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
70 $types[] = $row->obj_type;
71 }
72 return $types;
73 }
74
79 public function getTemplates()
80 {
81 return (array) $this->templates;
82 }
83
88 public function getObjectType()
89 {
90 return $this->obj_type;
91 }
92
96 public function readInactive()
97 {
98 global $DIC;
99
100 $ilDB = $DIC['ilDB'];
101
102 $query = 'SELECT dtpl.id FROM didactic_tpl_settings dtpl ';
103
104 if ($this->getObjectType()) {
105 $query .= 'JOIN didactic_tpl_sa tplsa ON dtpl.id = tplsa.id ';
106 }
107 $query .= 'WHERE enabled = ' . $ilDB->quote(0, 'integer') . ' ';
108
109 if ($this->getObjectType()) {
110 $query .= 'AND obj_type = ' . $ilDB->quote($this->getObjectType(), 'text');
111 }
112
113 $res = $ilDB->query($query);
114 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
115 $this->templates[$row->id] = new ilDidacticTemplateSetting($row->id);
116 }
117 return true;
118 }
119
125 protected function read()
126 {
127 global $DIC;
128
129 $ilDB = $DIC['ilDB'];
130
131 $query = 'SELECT dtpl.id FROM didactic_tpl_settings dtpl ';
132
133 if ($this->getObjectType()) {
134 $query .= 'JOIN didactic_tpl_sa tplsa ON dtpl.id = tplsa.id ';
135 }
136 $query .= 'WHERE enabled = ' . $ilDB->quote(1, 'integer') . ' ';
137
138 if ($this->getObjectType()) {
139 $query .= 'AND obj_type = ' . $ilDB->quote($this->getObjectType(), 'text');
140 }
141
142 $res = $ilDB->query($query);
143 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
144 $this->templates[$row->id] = new ilDidacticTemplateSetting($row->id);
145 }
146 return true;
147 }
148}
An exception for terminatinating execution or to throw for unit testing.
read()
Read active didactic templates @global ilDB $ilDB.
static getInstanceByObjectType($a_obj_type)
Get instance by obj type.
static getInstance()
Get singelton instance.
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB