ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 private $effective_from = array();
23 private $auto_generated = false;
24 private $exclusive = false;
25
26
31 public function __construct($a_id = 0)
32 {
33 $this->setId($a_id);
34 $this->read();
35 }
36
41 protected function setId($a_id)
42 {
43 $this->id = $a_id;
44 }
45
50 public function getId()
51 {
52 return $this->id;
53 }
54
59 public function enable($a_status)
60 {
61 $this->enabled = $a_status;
62 }
63
68 public function isEnabled()
69 {
70 return $this->enabled;
71 }
72
77 public function setTitle($a_title)
78 {
79 $this->title = $a_title;
80 }
81
86 public function getTitle()
87 {
88 return $this->title;
89 }
90
95 public function getPresentationTitle($a_lng = "")
96 {
97 if($this->isAutoGenerated())
98 {
99 global $lng;
100 return $lng->txt($this->getTitle());
101 }
102
103 $tit = $this->getPresentation('title', $a_lng);
104 return $tit ? $tit : $this->getTitle();
105 }
106
111 public function getDescription()
112 {
113 return $this->description;
114 }
115
120 public function getPresentationDescription($a_lng = "")
121 {
122 if($this->isAutoGenerated())
123 {
124 global $lng;
125 return $lng->txt($this->getDescription());
126 }
127
128 $desc = $this->getPresentation('description', $a_lng);
129 return $desc ? $desc : $this->getDescription();
130 }
131
136 public function setDescription($a_description)
137 {
138 $this->description = $a_description;
139 }
140
145 public function setInfo($a_info)
146 {
147 $this->info = $a_info;
148 }
149
154 public function getInfo()
155 {
156 return $this->info;
157 }
158
163 public function setType($a_type)
164 {
165 $this->type = $a_type;
166 }
167
172 public function getType()
173 {
174 return $this->type;
175 }
176
181 public function setAssignments(Array $a_ass)
182 {
183 $this->assignments = (array) $a_ass;
184 }
185
190 public function getAssignments()
191 {
192 return (array) $this->assignments;
193 }
194
199 public function addAssignment($a_obj_type)
200 {
201 $this->assignments[] = $a_obj_type;
202 }
203
207 public function getEffectiveFrom()
208 {
210 }
211
216 {
217 $this->effective_from = $effective_from;
218 }
219
223 public function isAutoGenerated()
224 {
226 }
227
234 {
235 $this->auto_generated = $auto_generated;
236 }
237
241 public function isExclusive()
242 {
243 return $this->exclusive;
244 }
245
249 public function setExclusive($exclusive)
250 {
251 $this->exclusive = $exclusive;
252 }
253
260 public function getTranslations()
261 {
262 $trans = $this->getTranslationObject();
263 $lang = $trans->getLanguages();
264
265 foreach($lang as $k => $v)
266 {
267 if($v['lang_default'])
268 {
269 $lang[0] = $lang[$k];
270 }
271
272 }
273
274 // fallback if translation object is empty
275 if(!isset($lang[0]))
276 {
277 $lang[0]['title'] = $this->getTitle();
278 $lang[0]['description'] = $this->getDescription();
279 $lang[0]['lang_code'] = $trans->getDefaultLanguage();
280 }
281
282 return $lang;
283 }
284
285 protected function getPresentation($a_value, $a_lng)
286 {
287 $lang = $this->getTranslationObject()->getLanguages();
288
289 if(!$lang)
290 {
291 return "";
292 }
293
294 if(!$a_lng)
295 {
296 global $ilUser;
297 $a_lng = $ilUser->getCurrentLanguage();
298 }
299
300 if(isset($lang[$a_lng][$a_value]))
301 {
302 return $lang[$a_lng][$a_value] ;
303 }
304 else{
305 return $lang[$a_lng][$this->getTranslationObject()->getDefaultLanguage()];
306 }
307 }
308
312 public function delete()
313 {
314 global $ilDB;
315
316 if($this->isAutoGenerated())
317 {
318 return false;
319 }
320
321 // Delete settings
322 $query = 'DELETE FROM didactic_tpl_settings '.
323 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
324 $ilDB->manipulate($query);
325
326 // Delete obj assignments
327 $query = 'DELETE FROM didactic_tpl_sa '.
328 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
329 $ilDB->manipulate($query);
330
331 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
333 {
334 $action->delete();
335 }
336
337 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
339
340 $this->getTranslationObject()->delete();
341 $this->deleteEffectiveNodes();
342 return true;
343 }
344
348 public function save()
349 {
350 global $ilDB;
351
352 $this->setId($ilDB->nextId('didactic_tpl_settings'));
353
354 $query = 'INSERT INTO didactic_tpl_settings (id,enabled,title,description,info,type,auto_generated,exclusive_tpl) '.
355 'VALUES( '.
356 $ilDB->quote($this->getId(),'integer').', '.
357 $ilDB->quote($this->isEnabled(),'integer').', '.
358 $ilDB->quote($this->getTitle(),'text').', '.
359 $ilDB->quote($this->getDescription(),'text').', '.
360 $ilDB->quote($this->getInfo(),'text').', '.
361 $ilDB->quote($this->getType(),'integer').', '.
362 $ilDB->quote((int)$this->isAutoGenerated(),'integer').', '.
363 $ilDB->quote((int)$this->isExclusive(),'integer').
364 ')';
365
366 $ilDB->manipulate($query);
367
368 $this->saveAssignments();
369
370 return true;
371 }
372
377 private function saveAssignments()
378 {
379 if($this->isAutoGenerated())
380 {
381 return false;
382 }
383
384 foreach($this->getAssignments() as $ass)
385 {
386 $this->saveAssignment($ass);
387 }
388 return true;
389 }
390
396 private function saveAssignment($a_obj_type)
397 {
398 global $ilDB;
399
400 if($this->isAutoGenerated())
401 {
402 return;
403 }
404
405 $query = 'INSERT INTO didactic_tpl_sa (id,obj_type) '.
406 'VALUES( '.
407 $ilDB->quote($this->getId(),'integer').', '.
408 $ilDB->quote($a_obj_type,'text').
409 ')';
410 $ilDB->manipulate($query);
411 }
412
416 protected function saveEffectiveNodes()
417 {
418 global $ilDB;
419
420 if(!count($this->getEffectiveFrom()))
421 {
422 return;
423 }
424
425 foreach($this->getEffectiveFrom() as $node)
426 {
427 $values[] = '( '.
428 $ilDB->quote($this->getId(),'integer').', '.
429 $ilDB->quote($node,'integer').
430 ')';
431 }
432
433 $query = 'INSERT INTO didactic_tpl_en (id,node) '.
434 'VALUES ' . implode(', ' , $values);
435
436 $ilDB->manipulate($query);
437 }
438
439 protected function deleteEffectiveNodes()
440 {
441 global $ilDB;
442
443 $query = 'DELETE FROM didactic_tpl_en '.
444 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
445 $ilDB->manipulate($query);
446 return true;
447 }
448
449 protected function readEffectiveNodes()
450 {
451 global $ilDB;
452 $effective_nodes = array();
453
454 $query = 'SELECT * FROM didactic_tpl_en '.
455 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
456 $res = $ilDB->query($query);
457 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
458 {
459 $effective_nodes[] = $row->node;
460 }
461
462 $this->setEffectiveFrom($effective_nodes);
463 }
464
470 private function deleteAssignments()
471 {
472 global $ilDB;
473
474 if($this->isAutoGenerated())
475 {
476 return false;
477 }
478
479 $query = 'DELETE FROM didactic_tpl_sa '.
480 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
481 $ilDB->manipulate($query);
482 return true;
483 }
484
490 public function update()
491 {
492 global $ilDB;
493
494 $query = 'UPDATE didactic_tpl_settings '.
495 'SET '.
496 'enabled = '.$ilDB->quote($this->isEnabled(),'integer').', '.
497 'title = '.$ilDB->quote($this->getTitle(),'text').', '.
498 'description = '.$ilDB->quote($this->getDescription(),'text').', '.
499 'info = '.$ilDB->quote($this->getInfo(),'text').', '.
500 'type = '.$ilDB->quote($this->getType(),'integer').', '.
501 'exclusive_tpl = '.$ilDB->quote((int)$this->isExclusive(),'integer').' '.
502 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
503 $ilDB->manipulate($query);
504 $this->deleteAssignments();
505 $this->saveAssignments();
506
507 $this->deleteEffectiveNodes();
508 $this->saveEffectiveNodes();
509
510 return true;
511 }
512
517 protected function read()
518 {
519 global $ilDB;
520
521 if(!$this->getId())
522 {
523 return false;
524 }
525
529 $query = 'SELECT * FROM didactic_tpl_settings dtpl '.
530 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
531 $res = $ilDB->query($query);
532 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
533 {
534 $this->setType($row->type);
535 $this->enable($row->enabled);
536 $this->setTitle($row->title);
537 $this->setDescription($row->description);
538 $this->setInfo($row->info);
539 $this->setAutoGenerated((bool) $row->auto_generated);
540 $this->setExclusive((bool) $row->exclusive_tpl);
541 }
542
546 $query = 'SELECT * FROM didactic_tpl_sa '.
547 'WHERE id = '.$ilDB->quote($this->getId(),'integer');
548 $res = $ilDB->query($query);
549 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
550 {
551 $this->addAssignment($row->obj_type);
552 }
553
554 $this->readEffectiveNodes();
555
556 return true;
557 }
558
564 public function toXml(ilXmlWriter $writer)
565 {
566 global $ilSetting;
567 switch($this->getType())
568 {
570 $type = 'creation';
571 break;
572 }
573
574 $writer->xmlStartTag('didacticTemplate',array('type' => $type));
575 $writer->xmlElement('title',array(),$this->getTitle());
576 $writer->xmlElement('description', array(), $this->getDescription());
577
578 $writer = $this->getTranslationObject()->toXml($writer);
579
580 // info text with p-tags
581 if(strlen($this->getInfo()))
582 {
583 $writer->xmlStartTag('info');
584
585 $info_lines = (array) explode("\n",$this->getInfo());
586 foreach($info_lines as $info)
587 {
588 $trimmed_info = trim($info);
589 if(strlen($trimmed_info))
590 {
591 $writer->xmlElement('p', array(), $trimmed_info);
592 }
593 }
594
595 $writer->xmlEndTag('info');
596 }
597
598 if($this->isExclusive())
599 {
600 $writer->xmlElement("exclusive");
601 }
602
603
604 if(count($this->getEffectiveFrom()) > 0)
605 {
606 $writer->xmlStartTag('effectiveFrom', array('nic_id'=> $ilSetting->get('inst_id')));
607
608 foreach($this->getEffectiveFrom() as $node)
609 {
610 $writer->xmlElement('node', array(), $node);
611 }
612 $writer->xmlEndTag('effectiveFrom');
613 }
614
615 // Assignments
616 $writer->xmlStartTag('assignments');
617 foreach($this->getAssignments() as $assignment)
618 {
619 $writer->xmlElement('assignment', array(), $assignment);
620 }
621 $writer->xmlEndTag('assignments');
622
623
624 $writer->xmlStartTag('actions');
625 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
627 {
628 $action->toXml($writer);
629 }
630 $writer->xmlEndTag('actions');
631 $writer->xmlEndTag('didacticTemplate');
632
633 return $writer;
634 }
635
639 public function __clone()
640 {
641 $this->setId(0);
642 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateCopier.php';
644 $this->enable(false);
645 $this->setAutoGenerated(false);
646 }
647
651 public function getTranslationObject()
652 {
653 include_once("./Services/Multilingualism/classes/class.ilMultilingualism.php");
654 return ilMultilingualism::getInstance($this->getId(), "dtpl");
655 }
656
661 public function isEffective($a_node_id)
662 {
663 global $tree;
664
665 if(!count($this->getEffectiveFrom()) || in_array($a_node_id, $this->getEffectiveFrom()))
666 {
667 return true;
668 }
669
670 foreach ($this->getEffectiveFrom() as $node)
671 {
672 if($tree->isGrandChild($node, $a_node_id))
673 {
674 return true;
675 }
676 }
677
678 return false;
679 }
680}
681
682?>
An exception for terminatinating execution or to throw for unit testing.
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.
setAutoGenerated($auto_generated)
DO NOT CHANGE THIS VALUE.
getTranslations()
get all translations from this object
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.
static getInstance($a_obj_id, $a_type)
Get instance.
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)
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:93