ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDidacticTemplateObjSettings.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
26 {
27  public static function lookupTemplateId(int $a_ref_id): int
28  {
29  global $DIC;
30 
31  $ilDB = $DIC->database();
32 
33  $query = 'SELECT tpl_id FROM didactic_tpl_objs ' .
34  'WHERE ref_id = ' . $ilDB->quote($a_ref_id, 'integer');
35  $res = $ilDB->query($query);
36  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
37  return (int) $row->tpl_id;
38  }
39 
40  return 0;
41  }
42 
43  public static function deleteByObjId(int $a_obj_id): void
44  {
45  global $DIC;
46 
47  $ilDB = $DIC->database();
48 
49  $query = 'DELETE FROM didactic_tpl_objs ' .
50  'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
51  $ilDB->manipulate($query);
52  }
53 
54  public static function deleteByTemplateId(int $a_tpl_id): void
55  {
56  global $DIC;
57 
58  $ilDB = $DIC->database();
59 
60  $query = 'DELETE FROM didactic_tpl_objs ' .
61  'WHERE tpl_id = ' . $ilDB->quote($a_tpl_id, 'integer');
62  $ilDB->manipulate($query);
63  }
64 
65  public static function deleteByRefId(int $a_ref_id): void
66  {
67  global $DIC;
68 
69  $ilDB = $DIC->database();
70 
71  $query = 'DELETE FROM didactic_tpl_objs ' .
72  'WHERE ref_id = ' . $ilDB->quote($a_ref_id, 'integer');
73  $ilDB->manipulate($query);
74  }
75 
76  public static function assignTemplate(int $a_ref_id, int $a_obj_id, int $a_tpl_id): void
77  {
78  global $DIC;
79 
80  $ilDB = $DIC->database();
81 
82  self::deleteByRefId($a_ref_id);
83 
84  $query = 'INSERT INTO didactic_tpl_objs (ref_id,obj_id,tpl_id) ' .
85  'VALUES ( ' .
86  $ilDB->quote($a_ref_id, 'integer') . ', ' .
87  $ilDB->quote($a_obj_id, 'integer') . ', ' .
88  $ilDB->quote($a_tpl_id, 'integer') . ' ' .
89  ')';
90  $ilDB->manipulate($query);
91  }
92 
97  public static function getAssignmentsByTemplateID(int $a_tpl_id): array
98  {
99  global $DIC;
100 
101  $ilDB = $DIC->database();
102 
103  $query = 'SELECT * FROM didactic_tpl_objs ' .
104  'WHERE tpl_id = ' . $ilDB->quote($a_tpl_id, 'integer');
105  $res = $ilDB->query($query);
106  $assignments = [];
107 
108  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
109  $assignments[] = ["ref_id" => (int) $row->ref_id, "obj_id" => (int) $row->obj_id];
110  }
111 
112  return $assignments;
113  }
114 
119  public static function getAssignmentsForTemplates(array $template_ids): array
120  {
121  global $DIC;
122 
123  $db = $DIC->database();
124  $query = 'select * from didactic_tpl_objs ' .
125  'where ' . $db->in('tpl_id', $template_ids, false, ilDBConstants::T_INTEGER);
126  $res = $db->query($query);
127  $assignments = [];
128  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
129  $assignments[(int) $row->tpl_id][] = (int) $row->ref_id;
130  }
131 
132  return $assignments;
133  }
134 
141  public static function transferAutoGenerateStatus(int $a_src, int $a_dest): bool
142  {
143  global $DIC;
144 
145  $ilDB = $DIC->database();
146 
147  $query = 'SELECT auto_generated FROM didactic_tpl_settings ' .
148  'WHERE id = ' . $ilDB->quote($a_src, 'integer');
149  $res = $ilDB->query($query);
150 
151  $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
152 
153  if ((int) $row->auto_generated === 0) {
154  return false;
155  }
156 
157  $query = 'UPDATE didactic_tpl_settings ' .
158  'SET ' .
159  'auto_generated = ' . $ilDB->quote(1, 'integer') .
160  ' WHERE id = ' . $ilDB->quote($a_dest, 'integer');
161  $ilDB->manipulate($query);
162 
163  $query = 'UPDATE didactic_tpl_settings ' .
164  'SET ' .
165  'auto_generated = ' . $ilDB->quote(0, 'integer') .
166  ' WHERE id = ' . $ilDB->quote($a_src, 'integer');
167  $ilDB->manipulate($query);
168 
169  return true;
170  }
171 }
static assignTemplate(int $a_ref_id, int $a_obj_id, int $a_tpl_id)
$res
Definition: ltiservices.php:66
static transferAutoGenerateStatus(int $a_src, int $a_dest)
Transfer auto generated flag if source is auto generated.
Stores the applied template id for objects.
static getAssignmentsForTemplates(array $template_ids)
global $DIC
Definition: shib_login.php:26