ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 global $DIC;
99
100 $lng = $DIC['lng'];
101 return $lng->txt($this->getTitle());
102 }
103
104 $tit = $this->getPresentation('title', $a_lng);
105 return $tit ? $tit : $this->getTitle();
106 }
107
112 public function getDescription()
113 {
114 return $this->description;
115 }
116
121 public function getPresentationDescription($a_lng = "")
122 {
123 if ($this->isAutoGenerated()) {
124 global $DIC;
125
126 $lng = $DIC['lng'];
127 return $lng->txt($this->getDescription());
128 }
129
130 $desc = $this->getPresentation('description', $a_lng);
131 return $desc ? $desc : $this->getDescription();
132 }
133
138 public function setDescription($a_description)
139 {
140 $this->description = $a_description;
141 }
142
147 public function setInfo($a_info)
148 {
149 $this->info = $a_info;
150 }
151
156 public function getInfo()
157 {
158 return $this->info;
159 }
160
165 public function setType($a_type)
166 {
167 $this->type = $a_type;
168 }
169
174 public function getType()
175 {
176 return $this->type;
177 }
178
183 public function setAssignments(array $a_ass)
184 {
185 $this->assignments = (array) $a_ass;
186 }
187
192 public function getAssignments()
193 {
194 return (array) $this->assignments;
195 }
196
201 public function addAssignment($a_obj_type)
202 {
203 $this->assignments[] = $a_obj_type;
204 }
205
209 public function getEffectiveFrom()
210 {
212 }
213
218 {
219 $this->effective_from = $effective_from;
220 }
221
225 public function isAutoGenerated()
226 {
228 }
229
236 {
237 $this->auto_generated = $auto_generated;
238 }
239
243 public function isExclusive()
244 {
245 return $this->exclusive;
246 }
247
251 public function setExclusive($exclusive)
252 {
253 $this->exclusive = $exclusive;
254 }
255
262 public function getTranslations()
263 {
264 $trans = $this->getTranslationObject();
265 $lang = $trans->getLanguages();
266
267 foreach ($lang as $k => $v) {
268 if ($v['lang_default']) {
269 $lang[0] = $lang[$k];
270 }
271 }
272
273 // fallback if translation object is empty
274 if (!isset($lang[0])) {
275 $lang[0]['title'] = $this->getTitle();
276 $lang[0]['description'] = $this->getDescription();
277 $lang[0]['lang_code'] = $trans->getDefaultLanguage();
278 }
279
280 return $lang;
281 }
282
283 protected function getPresentation($a_value, $a_lng)
284 {
285 $lang = $this->getTranslationObject()->getLanguages();
286
287 if (!$lang) {
288 return "";
289 }
290
291 if (!$a_lng) {
292 global $DIC;
293
294 $ilUser = $DIC['ilUser'];
295 $a_lng = $ilUser->getCurrentLanguage();
296 }
297
298 if (isset($lang[$a_lng][$a_value])) {
299 return $lang[$a_lng][$a_value] ;
300 } else {
301 return $lang[$a_lng][$this->getTranslationObject()->getDefaultLanguage()];
302 }
303 }
304
308 public function delete()
309 {
310 global $DIC;
311
312 $ilDB = $DIC['ilDB'];
313
314 if ($this->isAutoGenerated()) {
315 return false;
316 }
317
318 // Delete settings
319 $query = 'DELETE FROM didactic_tpl_settings ' .
320 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
321 $ilDB->manipulate($query);
322
323 // Delete obj assignments
324 $query = 'DELETE FROM didactic_tpl_sa ' .
325 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
326 $ilDB->manipulate($query);
327
328 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
330 $action->delete();
331 }
332
333 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
335
336 $this->getTranslationObject()->delete();
337 $this->deleteEffectiveNodes();
338 return true;
339 }
340
344 public function save()
345 {
346 global $DIC;
347
348 $ilDB = $DIC['ilDB'];
349
350 $this->setId($ilDB->nextId('didactic_tpl_settings'));
351
352 $query = 'INSERT INTO didactic_tpl_settings (id,enabled,title,description,info,type,auto_generated,exclusive_tpl) ' .
353 'VALUES( ' .
354 $ilDB->quote($this->getId(), 'integer') . ', ' .
355 $ilDB->quote($this->isEnabled(), 'integer') . ', ' .
356 $ilDB->quote($this->getTitle(), 'text') . ', ' .
357 $ilDB->quote($this->getDescription(), 'text') . ', ' .
358 $ilDB->quote($this->getInfo(), 'text') . ', ' .
359 $ilDB->quote($this->getType(), 'integer') . ', ' .
360 $ilDB->quote((int) $this->isAutoGenerated(), 'integer') . ', ' .
361 $ilDB->quote((int) $this->isExclusive(), 'integer') .
362 ')';
363
364 $ilDB->manipulate($query);
365
366 $this->saveAssignments();
367
368 return true;
369 }
370
375 private function saveAssignments()
376 {
377 if ($this->isAutoGenerated()) {
378 return false;
379 }
380
381 foreach ($this->getAssignments() as $ass) {
382 $this->saveAssignment($ass);
383 }
384 return true;
385 }
386
392 private function saveAssignment($a_obj_type)
393 {
394 global $DIC;
395
396 $ilDB = $DIC['ilDB'];
397
398 if ($this->isAutoGenerated()) {
399 return;
400 }
401
402 $query = 'INSERT INTO didactic_tpl_sa (id,obj_type) ' .
403 'VALUES( ' .
404 $ilDB->quote($this->getId(), 'integer') . ', ' .
405 $ilDB->quote($a_obj_type, 'text') .
406 ')';
407 $ilDB->manipulate($query);
408 }
409
413 protected function saveEffectiveNodes()
414 {
415 global $DIC;
416
417 $ilDB = $DIC['ilDB'];
418
419 if (!count($this->getEffectiveFrom())) {
420 return;
421 }
422
423 foreach ($this->getEffectiveFrom() as $node) {
424 $values[] = '( ' .
425 $ilDB->quote($this->getId(), 'integer') . ', ' .
426 $ilDB->quote($node, 'integer') .
427 ')';
428 }
429
430 $query = 'INSERT INTO didactic_tpl_en (id,node) ' .
431 'VALUES ' . implode(', ', $values);
432
433 $ilDB->manipulate($query);
434 }
435
436 protected function deleteEffectiveNodes()
437 {
438 global $DIC;
439
440 $ilDB = $DIC['ilDB'];
441
442 $query = 'DELETE FROM didactic_tpl_en ' .
443 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
444 $ilDB->manipulate($query);
445 return true;
446 }
447
448 protected function readEffectiveNodes()
449 {
450 global $DIC;
451
452 $ilDB = $DIC['ilDB'];
453 $effective_nodes = array();
454
455 $query = 'SELECT * FROM didactic_tpl_en ' .
456 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
457 $res = $ilDB->query($query);
458 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
459 $effective_nodes[] = $row->node;
460 }
461
462 $this->setEffectiveFrom($effective_nodes);
463 }
464
470 private function deleteAssignments()
471 {
472 global $DIC;
473
474 $ilDB = $DIC['ilDB'];
475
476 if ($this->isAutoGenerated()) {
477 return false;
478 }
479
480 $query = 'DELETE FROM didactic_tpl_sa ' .
481 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
482 $ilDB->manipulate($query);
483 return true;
484 }
485
491 public function update()
492 {
493 global $DIC;
494
495 $ilDB = $DIC['ilDB'];
496
497 $query = 'UPDATE didactic_tpl_settings ' .
498 'SET ' .
499 'enabled = ' . $ilDB->quote($this->isEnabled(), 'integer') . ', ' .
500 'title = ' . $ilDB->quote($this->getTitle(), 'text') . ', ' .
501 'description = ' . $ilDB->quote($this->getDescription(), 'text') . ', ' .
502 'info = ' . $ilDB->quote($this->getInfo(), 'text') . ', ' .
503 'type = ' . $ilDB->quote($this->getType(), 'integer') . ', ' .
504 'exclusive_tpl = ' . $ilDB->quote((int) $this->isExclusive(), 'integer') . ' ' .
505 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
506 $ilDB->manipulate($query);
507 $this->deleteAssignments();
508 $this->saveAssignments();
509
510 $this->deleteEffectiveNodes();
511 $this->saveEffectiveNodes();
512
513 return true;
514 }
515
520 protected function read()
521 {
522 global $DIC;
523
524 $ilDB = $DIC['ilDB'];
525
526 if (!$this->getId()) {
527 return false;
528 }
529
533 $query = 'SELECT * FROM didactic_tpl_settings dtpl ' .
534 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
535 $res = $ilDB->query($query);
536 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
537 $this->setType($row->type);
538 $this->enable($row->enabled);
539 $this->setTitle($row->title);
540 $this->setDescription($row->description);
541 $this->setInfo($row->info);
542 $this->setAutoGenerated((bool) $row->auto_generated);
543 $this->setExclusive((bool) $row->exclusive_tpl);
544 }
545
549 $query = 'SELECT * FROM didactic_tpl_sa ' .
550 'WHERE id = ' . $ilDB->quote($this->getId(), 'integer');
551 $res = $ilDB->query($query);
552 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
553 $this->addAssignment($row->obj_type);
554 }
555
556 $this->readEffectiveNodes();
557
558 return true;
559 }
560
566 public function toXml(ilXmlWriter $writer)
567 {
568 global $DIC;
569
570 $ilSetting = $DIC['ilSetting'];
571 switch ($this->getType()) {
573 $type = 'creation';
574 break;
575 }
576
577 $writer->xmlStartTag('didacticTemplate', array('type' => $type));
578 $writer->xmlElement('title', array(), $this->getTitle());
579 $writer->xmlElement('description', array(), $this->getDescription());
580
581 $writer = $this->getTranslationObject()->toXml($writer);
582
583 // info text with p-tags
584 if (strlen($this->getInfo())) {
585 $writer->xmlStartTag('info');
586
587 $info_lines = (array) explode("\n", $this->getInfo());
588 foreach ($info_lines as $info) {
589 $trimmed_info = trim($info);
590 if (strlen($trimmed_info)) {
591 $writer->xmlElement('p', array(), $trimmed_info);
592 }
593 }
594
595 $writer->xmlEndTag('info');
596 }
597
598 if ($this->isExclusive()) {
599 $writer->xmlElement("exclusive");
600 }
601
602
603 if (count($this->getEffectiveFrom()) > 0) {
604 $writer->xmlStartTag('effectiveFrom', array('nic_id' => $ilSetting->get('inst_id')));
605
606 foreach ($this->getEffectiveFrom() as $node) {
607 $writer->xmlElement('node', array(), $node);
608 }
609 $writer->xmlEndTag('effectiveFrom');
610 }
611
612 // Assignments
613 $writer->xmlStartTag('assignments');
614 foreach ($this->getAssignments() as $assignment) {
615 $writer->xmlElement('assignment', array(), $assignment);
616 }
617 $writer->xmlEndTag('assignments');
618
619
620 $writer->xmlStartTag('actions');
621 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
623 $action->toXml($writer);
624 }
625 $writer->xmlEndTag('actions');
626 $writer->xmlEndTag('didacticTemplate');
627
628 return $writer;
629 }
630
634 public function __clone()
635 {
636 $this->setId(0);
637 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateCopier.php';
639 $this->enable(false);
640 $this->setAutoGenerated(false);
641 }
642
646 public function getTranslationObject()
647 {
648 include_once("./Services/Multilingualism/classes/class.ilMultilingualism.php");
649 return ilMultilingualism::getInstance($this->getId(), "dtpl");
650 }
651
656 public function isEffective($a_node_id)
657 {
658 global $DIC;
659
660 $tree = $DIC['tree'];
661
662 if (!count($this->getEffectiveFrom()) || in_array($a_node_id, $this->getEffectiveFrom())) {
663 return true;
664 }
665
666 foreach ($this->getEffectiveFrom() as $node) {
667 if ($tree->isGrandChild($node, $a_node_id)) {
668 return true;
669 }
670 }
671
672 return false;
673 }
674}
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
getInfo()
Get installation info text.
setAssignments(array $a_ass)
Set assignments.
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.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
$action
info()
Definition: info.php:2
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
$row
global $ilSetting
Definition: privfeed.php:17
$query
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res
global $ilDB
$values
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92