ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDidacticTemplateGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private object $parent_object;
31 private ilCtrl $ctrl;
35 private \ILIAS\HTTP\GlobalHttpState $http;
36 private \ILIAS\Refinery\Factory $refinery;
38
39 public function __construct(object $a_parent_obj, int $requested_template_id = 0)
40 {
41 global $DIC;
42
43 $this->ctrl = $DIC->ctrl();
44 $this->tabs = $DIC->tabs();
45 $this->lng = $DIC->language();
46 $this->lng->loadLanguageModule('didactic');
47 $this->tpl = $DIC->ui()->mainTemplate();
48 $this->http = $DIC->http();
49 $this->refinery = $DIC->refinery();
50 $this->logger = $DIC->logger()->otpl();
51
52 $this->parent_object = $a_parent_obj;
53 if ($requested_template_id === 0) {
55 } else {
56 $this->requested_template_id = $requested_template_id;
57 }
58 }
59
60 protected function initTemplateIdFromPost()
61 {
62 $this->requested_template_id = 0;
63 if ($this->http->wrapper()->post()->has('tplid')) {
64 $this->requested_template_id = $this->http->wrapper()->post()->retrieve(
65 'tplid',
66 $this->refinery->kindlyTo()->int()
67 );
68 }
69 }
70
71 public function getParentObject(): object
72 {
74 }
75
76 public function executeCommand(): void
77 {
78 $next_class = $this->ctrl->getNextClass($this);
79 $cmd = $this->ctrl->getCmd();
80
81 switch ($next_class) {
82 default:
83 if (!$cmd) {
84 $cmd = 'overview';
85 }
86 $this->$cmd();
87
88 break;
89 }
90 }
91
92 public function appendToolbarSwitch(ilToolbarGUI $toolbar, string $a_obj_type, int $a_ref_id): bool
93 {
94 $tpls = ilDidacticTemplateSettings::getInstanceByObjectType($a_obj_type)->getTemplates();
95 $value = ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->getObject()->getRefId());
96
97 if (0 === $value && 0 === count($tpls)) {
98 return false;
99 }
100
101 // Add template switch
102 $toolbar->addText($this->lng->txt('didactic_selected_tpl_option'));
103
104 // Show template options
105 $options = array(0 => $this->lng->txt('didactic_default_type'));
106 $excl_tpl = false;
107
108 foreach ($tpls as $tpl) {
109 //just add if template is effective except template is already applied to this object
110 if ($tpl->isEffective($a_ref_id)) {
111 $options[$tpl->getId()] = $tpl->getPresentationTitle();
112
113 if ($tpl->isExclusive()) {
114 $excl_tpl = true;
115 }
116 }
117 }
118
119 if ($excl_tpl && $value !== 0) {
120 //remove default entry if an exclusive template exists but only if the actual entry isn't the default
121 unset($options[0]);
122 }
123
124 if (($excl_tpl && $value === 0) || !array_key_exists($value, $options)) {
125 $options[$value] = $this->lng->txt('not_available');
126 }
127
128 if (count($options) < 2) {
129 return false;
130 }
131
132 $tpl_selection = new ilSelectInputGUI(
133 $this->lng->txt('didactic_selected_tpl_option'),
134 'tplid'
135 );
136 $tpl_selection->setOptions($options);
137 $tpl_selection->setValue((string) $value);
138 $toolbar->addInputItem($tpl_selection);
139
140 // Apply templates switch
141 $toolbar->addFormButton($this->lng->txt('change'), 'confirmTemplateSwitch');
142 return true;
143 }
144
148 protected function confirmTemplateSwitch(): void
149 {
150 // Check if template is changed
151 $new_tpl_id = $this->requested_template_id;
152 if ($new_tpl_id === ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->getObject()->getRefId())) {
153 $this->logger->debug('Template id: ' . $new_tpl_id);
154 $this->tpl->setOnScreenMessage('info', $this->lng->txt('didactic_not_changed'), true);
155 $this->ctrl->returnToParent($this);
156 }
157
158 $this->tabs->clearTargets();
159 $this->tabs->clearSubTabs();
160
161 $confirm = new ilConfirmationGUI();
162 $confirm->setFormAction($this->ctrl->getFormAction($this));
163 $confirm->setHeaderText($this->lng->txt('didactic_confirm_apply_new_template'));
164 $confirm->setConfirm($this->lng->txt('apply'), 'switchTemplate');
165 $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
166
167 if ($new_tpl_id) {
168 $dtpl = new ilDidacticTemplateSetting($new_tpl_id);
169
170 $confirm->addItem(
171 'tplid',
172 (string) $new_tpl_id,
173 $dtpl->getPresentationTitle() .
174 '<div class="il_Description">' .
175 $dtpl->getPresentationDescription() . ' ' .
176 '</div>'
177 );
178 } else {
179 $confirm->addItem(
180 'tplid',
181 (string) $new_tpl_id,
182 $this->lng->txt('default') . ' ' .
183 '<div class="il_Description">' .
184 sprintf(
185 $this->lng->txt('didactic_default_type_info'),
186 $this->lng->txt('objs_' . $this->getParentObject()->getObject()->getType())
187 ) .
188 '</div>'
189 );
190 }
191 $this->tpl->setContent($confirm->getHTML());
192 }
193
197 protected function cancel(): void
198 {
199 $this->ctrl->returnToParent($this);
200 }
201
202 protected function switchTemplate(): void
203 {
204 $new_tpl_id = $this->requested_template_id;
205 ilDidacticTemplateUtils::switchTemplate($this->getParentObject()->getObject()->getRefId(), $new_tpl_id);
206 $this->tpl->setOnScreenMessage('success', $this->lng->txt('didactic_template_applied'), true);
207 $this->ctrl->returnToParent($this);
208 }
209}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
GUI class for didactic template settings inside repository objects.
ILIAS HTTP GlobalHttpState $http
__construct(object $a_parent_obj, int $requested_template_id=0)
confirmTemplateSwitch()
Show didactic template switch confirmation screen.
ilGlobalTemplateInterface $tpl
ILIAS Refinery Factory $refinery
appendToolbarSwitch(ilToolbarGUI $toolbar, string $a_obj_type, int $a_ref_id)
static getInstanceByObjectType(string $a_obj_type)
static switchTemplate(int $a_ref_id, int $a_new_tpl_id)
language handling
Component logger with individual log levels by component id.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addInputItem(ilToolbarItem $a_item, bool $a_output_label=false)
addFormButton(string $a_txt, string $a_cmd, ?int $a_acc_key=null, bool $a_primary=false, ?string $a_class=null)
addText(string $a_text)
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26