ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilDidacticTemplateObjSettings.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
12 
19  public static function lookupTemplateId($a_ref_id)
20  {
21  global $DIC;
22 
23  $ilDB = $DIC['ilDB'];
24 
25  $query = 'SELECT tpl_id FROM didactic_tpl_objs ' .
26  'WHERE ref_id = ' . $ilDB->quote($a_ref_id, 'integer');
27  $res = $ilDB->query($query);
28  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
29  return $row->tpl_id;
30  }
31  return 0;
32  }
33 
34 
41  public static function deleteByObjId($a_obj_id)
42  {
43  global $DIC;
44 
45  $ilDB = $DIC['ilDB'];
46 
47  $query = 'DELETE FROM didactic_tpl_objs ' .
48  'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
49  $ilDB->manipulate($query);
50  return true;
51  }
52 
59  public static function deleteByTemplateId($a_tpl_id)
60  {
61  global $DIC;
62 
63  $ilDB = $DIC['ilDB'];
64 
65  $query = 'DELETE FROM didactic_tpl_objs ' .
66  'WHERE tpl_id = ' . $ilDB->quote($a_tpl_id, 'integer');
67  $ilDB->manipulate($query);
68  return true;
69  }
70 
76  public static function deleteByRefId($a_ref_id)
77  {
78  global $DIC;
79 
80  $ilDB = $DIC['ilDB'];
81 
82  $query = 'DELETE FROM didactic_tpl_objs ' .
83  'WHERE ref_id = ' . $ilDB->quote($a_ref_id, 'integer');
84  $ilDB->manipulate($query);
85  }
86 
94  public static function assignTemplate($a_ref_id, $a_obj_id, $a_tpl_id)
95  {
96  global $DIC;
97 
98  $ilDB = $DIC['ilDB'];
99 
100  self::deleteByRefId($a_ref_id);
101 
102  $query = 'INSERT INTO didactic_tpl_objs (ref_id,obj_id,tpl_id) ' .
103  'VALUES ( ' .
104  $ilDB->quote($a_ref_id, 'integer') . ', ' .
105  $ilDB->quote($a_obj_id, 'integer') . ', ' .
106  $ilDB->quote($a_tpl_id, 'integer') . ' ' .
107  ')';
108  $ilDB->manipulate($query);
109  return true;
110  }
117  public static function getAssignmentsByTemplateID($a_tpl_id)
118  {
119  global $DIC;
120 
121  $ilDB = $DIC['ilDB'];
122 
123  $query = 'SELECT * FROM didactic_tpl_objs ' .
124  'WHERE tpl_id = ' . $ilDB->quote($a_tpl_id, 'integer');
125  $res = $ilDB->query($query);
126  $assignments = array();
127 
128  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
129  $assignments[] = array("ref_id" => $row->ref_id, "obj_id" => $row->obj_id);
130  }
131  return $assignments;
132  }
133 
138  public static function getAssignmentsForTemplates(array $template_ids) : array
139  {
140  global $DIC;
141 
142  $db = $DIC->database();
143  $query = 'select * from didactic_tpl_objs ' .
144  'where ' . $db->in('tpl_id', $template_ids, false, ilDBConstants::T_INTEGER);
145  $res = $db->query($query);
146  $assignments = [];
147  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
148  $assignments[$row->tpl_id][] = $row->ref_id;
149  }
150  return $assignments;
151  }
152 
153 
161  public static function transferAutoGenerateStatus($a_src, $a_dest)
162  {
163  global $DIC;
164 
165  $ilDB = $DIC['ilDB'];
166 
167  $query = 'SELECT auto_generated FROM didactic_tpl_settings ' .
168  'WHERE id = ' . $ilDB->quote($a_src, 'integer');
169  $res = $ilDB->query($query);
170 
171  $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
172 
173  if ($row->auto_generated == 0) {
174  return false;
175  }
176 
177  $query = 'UPDATE didactic_tpl_settings ' .
178  'SET ' .
179  'auto_generated = ' . $ilDB->quote(1, 'integer') .
180  ' WHERE id = ' . $ilDB->quote($a_dest, 'integer');
181  $ilDB->manipulate($query);
182 
183  $query = 'UPDATE didactic_tpl_settings ' .
184  'SET ' .
185  'auto_generated = ' . $ilDB->quote(0, 'integer') .
186  ' WHERE id = ' . $ilDB->quote($a_src, 'integer');
187  $ilDB->manipulate($query);
188 
189  return true;
190  }
191 }
static lookupTemplateId($a_ref_id)
Lookup template id ilDB $ilDB.
static deleteByRefId($a_ref_id)
Delete by ref_id ilDB $ilDB.
static transferAutoGenerateStatus($a_src, $a_dest)
transfer auto generated flag if source is auto generated
static getAssignmentsByTemplateID($a_tpl_id)
Lookup template id ilDB $ilDB.
Stores the applied template id for objects.
static assignTemplate($a_ref_id, $a_obj_id, $a_tpl_id)
Assign template to object ilDB $ilDB.
foreach($_POST as $key=> $value) $res
static getAssignmentsForTemplates(array $template_ids)
static deleteByTemplateId($a_tpl_id)
Delete by template id ilDB $ilDB.
global $DIC
Definition: goto.php:24
$query
global $ilDB
static deleteByObjId($a_obj_id)
Delete by obj id ilDB $ilDB.