ILIAS  release_8 Revision v8.24
class.ilDidacticTemplateObjSettings.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 public static function lookupTemplateId(int $a_ref_id): int
14 {
15 global $DIC;
16
17 $ilDB = $DIC->database();
18
19 $query = 'SELECT tpl_id FROM didactic_tpl_objs ' .
20 'WHERE ref_id = ' . $ilDB->quote($a_ref_id, 'integer');
21 $res = $ilDB->query($query);
22 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
23 return (int) $row->tpl_id;
24 }
25
26 return 0;
27 }
28
29 public static function deleteByObjId(int $a_obj_id): void
30 {
31 global $DIC;
32
33 $ilDB = $DIC->database();
34
35 $query = 'DELETE FROM didactic_tpl_objs ' .
36 'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
37 $ilDB->manipulate($query);
38 }
39
40 public static function deleteByTemplateId(int $a_tpl_id): void
41 {
42 global $DIC;
43
44 $ilDB = $DIC->database();
45
46 $query = 'DELETE FROM didactic_tpl_objs ' .
47 'WHERE tpl_id = ' . $ilDB->quote($a_tpl_id, 'integer');
48 $ilDB->manipulate($query);
49 }
50
51 public static function deleteByRefId(int $a_ref_id): void
52 {
53 global $DIC;
54
55 $ilDB = $DIC->database();
56
57 $query = 'DELETE FROM didactic_tpl_objs ' .
58 'WHERE ref_id = ' . $ilDB->quote($a_ref_id, 'integer');
59 $ilDB->manipulate($query);
60 }
61
62 public static function assignTemplate(int $a_ref_id, int $a_obj_id, int $a_tpl_id): void
63 {
64 global $DIC;
65
66 $ilDB = $DIC->database();
67
68 self::deleteByRefId($a_ref_id);
69
70 $query = 'INSERT INTO didactic_tpl_objs (ref_id,obj_id,tpl_id) ' .
71 'VALUES ( ' .
72 $ilDB->quote($a_ref_id, 'integer') . ', ' .
73 $ilDB->quote($a_obj_id, 'integer') . ', ' .
74 $ilDB->quote($a_tpl_id, 'integer') . ' ' .
75 ')';
76 $ilDB->manipulate($query);
77 }
78
83 public static function getAssignmentsByTemplateID(int $a_tpl_id): array
84 {
85 global $DIC;
86
87 $ilDB = $DIC->database();
88
89 $query = 'SELECT * FROM didactic_tpl_objs ' .
90 'WHERE tpl_id = ' . $ilDB->quote($a_tpl_id, 'integer');
91 $res = $ilDB->query($query);
92 $assignments = [];
93
94 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
95 $assignments[] = ["ref_id" => (int) $row->ref_id, "obj_id" => (int) $row->obj_id];
96 }
97
98 return $assignments;
99 }
100
105 public static function getAssignmentsForTemplates(array $template_ids): array
106 {
107 global $DIC;
108
109 $db = $DIC->database();
110 $query = 'select * from didactic_tpl_objs ' .
111 'where ' . $db->in('tpl_id', $template_ids, false, ilDBConstants::T_INTEGER);
112 $res = $db->query($query);
113 $assignments = [];
114 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
115 $assignments[(int) $row->tpl_id][] = (int) $row->ref_id;
116 }
117
118 return $assignments;
119 }
120
127 public static function transferAutoGenerateStatus(int $a_src, int $a_dest): bool
128 {
129 global $DIC;
130
131 $ilDB = $DIC->database();
132
133 $query = 'SELECT auto_generated FROM didactic_tpl_settings ' .
134 'WHERE id = ' . $ilDB->quote($a_src, 'integer');
135 $res = $ilDB->query($query);
136
137 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
138
139 if ((int) $row->auto_generated === 0) {
140 return false;
141 }
142
143 $query = 'UPDATE didactic_tpl_settings ' .
144 'SET ' .
145 'auto_generated = ' . $ilDB->quote(1, 'integer') .
146 ' WHERE id = ' . $ilDB->quote($a_dest, 'integer');
147 $ilDB->manipulate($query);
148
149 $query = 'UPDATE didactic_tpl_settings ' .
150 'SET ' .
151 'auto_generated = ' . $ilDB->quote(0, 'integer') .
152 ' WHERE id = ' . $ilDB->quote($a_src, 'integer');
153 $ilDB->manipulate($query);
154
155 return true;
156 }
157}
Stores the applied template id for objects.
static getAssignmentsForTemplates(array $template_ids)
static transferAutoGenerateStatus(int $a_src, int $a_dest)
Transfer auto generated flag if source is auto generated.
static assignTemplate(int $a_ref_id, int $a_obj_id, int $a_tpl_id)
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query