ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilDidacticTemplateCopier.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
26 {
27  private int $tpl_id = 0;
28  private int $new_tpl_id = 0;
29 
30  public function __construct(int $a_tpl_id)
31  {
32  $this->tpl_id = $a_tpl_id;
33  }
34 
35  public static function appendCopyInfo(string $a_orig_title): string
36  {
37  global $DIC;
38 
39  $db = $DIC->database();
40  $lng = $DIC->language();
41 
42  $query = 'SELECT title FROM didactic_tpl_settings ' .
43  'WHERE title = ' . $db->quote($a_orig_title, 'text');
44  $res = $db->query($query);
45  $num = 0;
46  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
47  ++$num;
48  }
49  if (!$num) {
50  return $a_orig_title;
51  }
52  if ($num === 1) {
53  return $a_orig_title . ' ' . $lng->txt('copy_of_suffix');
54  }
55  return $a_orig_title . ' ' . sprintf($lng->txt('copy_n_of_suffix'), $num);
56  }
57 
58  public function getTemplateId(): int
59  {
60  return $this->tpl_id;
61  }
62 
63  public function getNewTemplateId(): int
64  {
65  return $this->new_tpl_id;
66  }
67 
71  public function start(): void
72  {
73  $orig = new ilDidacticTemplateSetting($this->getTemplateId());
74  $copy = clone $orig;
75  $copy->save();
76  $this->new_tpl_id = $copy->getId();
77 
78  // copy icon
79  $copy->getIconHandler()->copy($orig);
81  $action->setTemplateId($this->getNewTemplateId());
82  $new = clone $action;
83  $new->save();
84  }
85 
86  $trans = $orig->getTranslationObject();
87  $copy_trans = $trans->copy($this->new_tpl_id);
88  $copy_trans->addLanguage($trans->getDefaultLanguage(), $copy->getTitle(), $copy->getDescription(), true, true);
89  $copy_trans->save();
90  }
91 }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:26
static appendCopyInfo(string $a_orig_title)
Copy a didactic template and all subitems.
static getActionsByTemplateId(int $a_tpl_id)
Get actions of one template.
global $lng
Definition: privfeed.php:31