ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDidacticTemplateGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
5
14{
16 private $lng;
17
21 public function __construct($a_parent_obj)
22 {
23 global $DIC;
24
25 $lng = $DIC['lng'];
26
27 $this->parent_object = $a_parent_obj;
28 $this->lng = $lng;
29 $this->lng->loadLanguageModule('didactic');
30 }
31
32 public function getParentObject()
33 {
35 }
36
41 public function executeCommand()
42 {
43 global $DIC;
44
45 $ilCtrl = $DIC['ilCtrl'];
46
47 $next_class = $ilCtrl->getNextClass($this);
48 $cmd = $ilCtrl->getCmd();
49
50 switch ($next_class) {
51 default:
52 if (!$cmd) {
53 $cmd = 'overview';
54 }
55 $this->$cmd();
56
57 break;
58 }
59 return true;
60 }
61
62 public function appendToolbarSwitch(ilToolbarGUI $toolbar, $a_obj_type, $a_ref_id)
63 {
64 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSettings.php';
65 $tpls = ilDidacticTemplateSettings::getInstanceByObjectType($a_obj_type)->getTemplates();
66
67 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
68 $value = ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId());
69
70 if (!count($tpls) && !$value) {
71 return false;
72 }
73
74 // Add template switch
75 $toolbar->addText($this->lng->txt('didactic_selected_tpl_option'));
76
77 // Show template options
78 $options = array(0 => $this->lng->txt('didactic_default_type'));
79 $excl_tpl = false;
80
81 foreach ($tpls as $tpl) {
82 //just add if template is effective except template is already applied to this object
83 if ($tpl->isEffective($_GET['ref_id'])) {
84 $options[$tpl->getId()] = $tpl->getPresentationTitle();
85
86 if ($tpl->isExclusive()) {
87 $excl_tpl = true;
88 }
89 }
90 }
91
92 if ($excl_tpl && $value != 0) {
93 //remove default entry if an exclusive template exists but only if the actual entry isn't the default
94 unset($options[0]);
95 }
96
97 if (!in_array($value, array_keys($options)) || ($excl_tpl && $value == 0)) {
98 $options[$value] = $this->lng->txt('not_available');
99 }
100
101 if (count($options) < 2) {
102 return false;
103 }
104
105 include_once './Services/Form/classes/class.ilSelectInputGUI.php';
106 $tpl_selection = new ilSelectInputGUI(
107 '',
108 'tplid'
109 );
110 $tpl_selection->setOptions($options);
111 $tpl_selection->setValue($value);
112 $toolbar->addInputItem($tpl_selection);
113
114 // Apply templates switch
115 $toolbar->addFormButton($this->lng->txt('change'), 'confirmTemplateSwitch');
116 return true;
117 }
118
119 /*
120 * Show didactic template switch confirmation screen
121 */
122 protected function confirmTemplateSwitch()
123 {
124 global $DIC;
125
126 $ilCtrl = $DIC['ilCtrl'];
127 $ilTabs = $DIC['ilTabs'];
128 $tpl = $DIC['tpl'];
129
130 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
131
132 // Check if template is changed
133 $new_tpl_id = (int) $_REQUEST['tplid'];
134 if ($new_tpl_id == ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId())) {
135 ilLoggerFactory::getLogger('otpl')->debug('Template id: ' . $new_tpl_id);
136 ilUtil::sendInfo($this->lng->txt('didactic_not_changed'), true);
137 $ilCtrl->returnToParent($this);
138 }
139
140 $ilTabs->clearTargets();
141 $ilTabs->clearSubTabs();
142
143 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
144 $confirm = new ilConfirmationGUI();
145 $confirm->setFormAction($ilCtrl->getFormAction($this));
146 $confirm->setHeaderText($this->lng->txt('didactic_confirm_apply_new_template'));
147 $confirm->setConfirm($this->lng->txt('apply'), 'switchTemplate');
148 $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
149
150 if ($new_tpl_id) {
151 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
152 $dtpl = new ilDidacticTemplateSetting($new_tpl_id);
153
154 $confirm->addItem(
155 'tplid',
156 $new_tpl_id,
157 $dtpl->getPresentationTitle() .
158 '<div class="il_Description">' .
159 $dtpl->getPresentationDescription() . ' ' .
160 '</div>'
161 );
162 } else {
163 $confirm->addItem(
164 'tplid',
165 $new_tpl_id,
166 $this->lng->txt('default') . ' ' .
167 '<div class="il_Description">' .
168 sprintf(
169 $this->lng->txt('didactic_default_type_info'),
170 $this->lng->txt('objs_' . $this->getParentObject()->object->getType())
171 ) .
172 '</div>'
173 );
174 }
175 $tpl->setContent($confirm->getHTML());
176 }
177
181 protected function cancel()
182 {
183 global $DIC;
184
185 $ilCtrl = $DIC['ilCtrl'];
186
187 $ilCtrl->returnToParent($this);
188 }
189
193 protected function switchTemplate()
194 {
195 global $DIC;
196
197 $ilCtrl = $DIC['ilCtrl'];
198
199 $new_tpl_id = (int) $_REQUEST['tplid'];
200
201 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateUtils.php';
202 ilDidacticTemplateUtils::switchTemplate($this->getParentObject()->object->getRefId(), $new_tpl_id);
203
204 ilUtil::sendSuccess($this->lng->txt('didactic_template_applied'), true);
205 $ilCtrl->returnToParent($this);
206 }
207}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Confirmation screen class.
GUI class for didactic template settings inside repository objects.
__construct($a_parent_obj)
Constructor.
appendToolbarSwitch(ilToolbarGUI $toolbar, $a_obj_type, $a_ref_id)
static lookupTemplateId($a_ref_id)
Lookup template id @global ilDB $ilDB.
static getInstanceByObjectType($a_obj_type)
Get instance by obj type.
static switchTemplate($a_ref_id, $a_new_tpl_id)
static getLogger($a_component_id)
Get component logger.
This class represents a selection list property in a property form.
addInputItem(ilToolbarItem $a_item, $a_output_label=false)
Add input item.
addFormButton($a_txt, $a_cmd, $a_acc_key="", $a_primary=false, $a_class=false)
Add form button to toolbar.
addText($a_text)
Add text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$DIC
Definition: xapitoken.php:46