ILIAS  release_8 Revision v8.24
class.ilDidacticTemplateCopier.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5
12{
13 private int $tpl_id = 0;
14 private int $new_tpl_id = 0;
15
16 public function __construct(int $a_tpl_id)
17 {
18 $this->tpl_id = $a_tpl_id;
19 }
20
21 public static function appendCopyInfo(string $a_orig_title): string
22 {
23 global $DIC;
24
25 $db = $DIC->database();
26 $lng = $DIC->language();
27
28 $query = 'SELECT title FROM didactic_tpl_settings ' .
29 'WHERE title = ' . $db->quote($a_orig_title, 'text');
30 $res = $db->query($query);
31 $num = 0;
32 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
33 ++$num;
34 }
35 if (!$num) {
36 return $a_orig_title;
37 }
38 if ($num === 1) {
39 return $a_orig_title . ' ' . $lng->txt('copy_of_suffix');
40 }
41 return $a_orig_title . ' ' . sprintf($lng->txt('copy_n_of_suffix'), $num);
42 }
43
44 public function getTemplateId(): int
45 {
46 return $this->tpl_id;
47 }
48
49 public function getNewTemplateId(): int
50 {
51 return $this->new_tpl_id;
52 }
53
57 public function start(): void
58 {
59 $orig = new ilDidacticTemplateSetting($this->getTemplateId());
60 $copy = clone $orig;
61 $copy->save();
62 $this->new_tpl_id = $copy->getId();
63
64 // copy icon
65 $copy->getIconHandler()->copy($orig);
67 $action->setTemplateId($this->getNewTemplateId());
68 $new = clone $action;
69 $new->save();
70 }
71
72 $trans = $orig->getTranslationObject();
73 $copy_trans = $trans->copy($this->new_tpl_id);
74 $copy_trans->addLanguage($trans->getDefaultLanguage(), $copy->getTitle(), $copy->getDescription(), true, true);
75 $copy_trans->save();
76 }
77}
static getActionsByTemplateId(int $a_tpl_id)
Get actions of one template.
Copy a didactic template and all subitems.
static appendCopyInfo(string $a_orig_title)
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query
$lng