ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilDidacticTemplateSetting.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 const TYPE_CREATION = 1;
13
14
15 private $id = 0;
16 private $enabled = false;
17 private $title = '';
18 private $description = '';
19 private $info = '';
21 private $assignments = array();
22
23
28 public function __construct($a_id = 0)
29 {
30 $this->setId($a_id);
31 $this->read();
32 }
33
38 protected function setId($a_id)
39 {
40 $this->id = $a_id;
41 }
42
47 public function getId()
48 {
49 return $this->id;
50 }
51
56 public function enable($a_status)
57 {
58 $this->enabled = $a_status;
59 }
60
65 public function isEnabled()
66 {
67 return $this->enabled;
68 }
69
74 public function setTitle($a_title)
75 {
76 $this->title = $a_title;
77 }
78
83 public function getTitle()
84 {
85 return $this->title;
86 }
87
92 public function getDescription()
93 {
94 return $this->description;
95 }
96
101 public function setDescription($a_description)
102 {
103 $this->description = $a_description;
104 }
105
110 public function setInfo($a_info)
111 {
112 $this->info = $a_info;
113 }
114
119 public function getInfo()
120 {
121 return $this->info;
122 }
123
128 public function setType($a_type)
129 {
130 $this->type = $a_type;
131 }
132
137 public function getType()
138 {
139 return $this->type;
140 }
141
146 public function setAssignments(Array $a_ass)
147 {
148 $this->assignments = (array) $a_ass;
149 }
150
155 public function getAssignments()
156 {
157 return (array) $this->assignments;
158 }
159
164 public function addAssignment($a_obj_type)
165 {
166 $this->assignments[] = $a_obj_type;
167 }
168
172 public function delete()
173 {
174 global $ilDB;
175
176 // Delete settings
177 $query = 'DELETE FROM didactic_tpl_settings '.
178 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
179 $ilDB->manipulate($query);
180
181 // Delete obj assignments
182 $query = 'DELETE FROM didactic_tpl_sa '.
183 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
184 $ilDB->manipulate($query);
185
186 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
188 {
189 $action->delete();
190 }
191
192 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
194
195 return true;
196 }
197
201 public function save()
202 {
203 global $ilDB;
204
205 $this->setId($ilDB->nextId('didactic_tpl_settings'));
206
207 $query = 'INSERT INTO didactic_tpl_settings (id,enabled,title,description,info,type) '.
208 'VALUES( '.
209 $ilDB->quote($this->getId(),'integer').', '.
210 $ilDB->quote($this->isEnabled(),'integer').', '.
211 $ilDB->quote($this->getTitle(),'text').', '.
212 $ilDB->quote($this->getDescription(),'text').', '.
213 $ilDB->quote($this->getInfo(),'text').', '.
214 $ilDB->quote($this->getType(),'integer').
215 ')';
216
217 $ilDB->manipulate($query);
218
219 $this->saveAssignments();
220
221
222 return true;
223 }
224
229 private function saveAssignments()
230 {
231 foreach($this->getAssignments() as $ass)
232 {
233 $this->saveAssignment($ass);
234 }
235 return true;
236 }
237
243 private function saveAssignment($a_obj_type)
244 {
245 global $ilDB;
246
247 $query = 'INSERT INTO didactic_tpl_sa (id,obj_type) '.
248 'VALUES( '.
249 $ilDB->quote($this->getId(),'integer').', '.
250 $ilDB->quote($a_obj_type,'text').
251 ')';
252 $ilDB->manipulate($query);
253 }
254
260 private function deleteAssignments()
261 {
262 global $ilDB;
263
264 $query = 'DELETE FROM didactic_tpl_sa '.
265 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
266 $ilDB->manipulate($query);
267 return true;
268 }
269
274 public function update()
275 {
276 global $ilDB;
277
278 $query = 'UPDATE didactic_tpl_settings '.
279 'SET '.
280 'enabled = '.$ilDB->quote($this->isEnabled(),'integer').', '.
281 'title = '.$ilDB->quote($this->getTitle(),'text').', '.
282 'description = '.$ilDB->quote($this->getDescription(),'text').', '.
283 'info = '.$ilDB->quote($this->getInfo(),'text').', '.
284 'type = '.$ilDB->quote($this->getType(),'integer').' '.
285 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
286 $ilDB->manipulate($query);
287 $this->deleteAssignments();
288 $this->saveAssignments();
289
290 return true;
291 }
292
297 protected function read()
298 {
299 global $ilDB;
300
301 if(!$this->getId())
302 {
303 return false;
304 }
305
309 $query = 'SELECT * FROM didactic_tpl_settings dtpl '.
310 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
311 $res = $ilDB->query($query);
312 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
313 {
314 $this->setType($row->type);
315 $this->enable($row->enabled);
316 $this->setTitle($row->title);
317 $this->setDescription($row->description);
318 $this->setInfo($row->info);
319
320 }
321
325 $query = 'SELECT * FROM didactic_tpl_sa '.
326 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
327 $res = $ilDB->query($query);
328 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
329 {
330 $this->addAssignment($row->obj_type);
331 }
332 return true;
333 }
334
340 public function toXml(ilXmlWriter $writer)
341 {
342 switch($this->getType())
343 {
345 $type = 'creation';
346 break;
347 }
348
349 $writer->xmlStartTag('didacticTemplate',array('type' => $type));
350 $writer->xmlElement('title',array(),$this->getTitle());
351 $writer->xmlElement('description', array(), $this->getDescription());
352
353 // info text with p-tags
354 if(strlen($this->getInfo()))
355 {
356 $writer->xmlStartTag('info');
357
358 $info_lines = (array) explode("\n",$this->getInfo());
359 foreach($info_lines as $info)
360 {
361 $trimmed_info = trim($info);
362 if(strlen($trimmed_info))
363 {
364 $writer->xmlElement('p', array(), $trimmed_info);
365 }
366 }
367
368 $writer->xmlEndTag('info');
369 }
370
371 // Assignments
372 $writer->xmlStartTag('assignments');
373 foreach($this->getAssignments() as $assignment)
374 {
375 $writer->xmlElement('assignment', array(), $assignment);
376 }
377 $writer->xmlEndTag('assignments');
378
379
380 $writer->xmlStartTag('actions');
381 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
383 {
384 $action->toXml($writer);
385 }
386 $writer->xmlEndTag('actions');
387 $writer->xmlEndTag('didacticTemplate');
388
389 return $writer;
390 }
391
395 public function __clone()
396 {
397 $this->setId(0);
398 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateCopier.php';
400 $this->enable(false);
401 }
402}
403
404?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static getActionsByTemplateId($a_tpl_id)
Get actions of one template.
static deleteByTemplateId($a_tpl_id)
Delete by template id @global ilDB $ilDB.
saveAssignment($a_obj_type)
Add one object assignment @global ilDB $ilDB.
enable($a_status)
Set enabled status.
setDescription($a_description)
Set description.
addAssignment($a_obj_type)
Add one assignment obj type.
setAssignments(Array $a_ass)
Set assignments.
getInfo()
Get installation info text.
isEnabled()
Check if template is enabled.
deleteAssignments()
Delete assignments @global ilDB $ilDB.
update()
Update settings @global ilDB $ilDB.
setInfo($a_info)
Set installation info text.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
global $ilDB