ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $lng;
24
25 $this->parent_object = $a_parent_obj;
26 $this->lng = $lng;
27 $this->lng->loadLanguageModule('didactic');
28 }
29
30 public function getParentObject()
31 {
33 }
34
39 public function executeCommand()
40 {
41 global $ilCtrl;
42
43 $next_class = $ilCtrl->getNextClass($this);
44 $cmd = $ilCtrl->getCmd();
45
46 switch($next_class)
47 {
48 default:
49 if(!$cmd)
50 {
51 $cmd = 'overview';
52 }
53 $this->$cmd();
54
55 break;
56 }
57 return true;
58 }
59
60 public function appendToolbarSwitch(ilToolbarGUI $toolbar, $a_obj_type, $a_ref_id)
61 {
62 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSettings.php';
63 $tpls = ilDidacticTemplateSettings::getInstanceByObjectType($a_obj_type)->getTemplates();
64
65 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
66 $value = ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId());
67
68 if(!count($tpls) && !$value)
69 {
70 return false;
71 }
72
73 // Add template switch
74 $toolbar->addText($this->lng->txt('didactic_selected_tpl_option'));
75
76 // Show template options
77 $options = array(0 => $this->lng->txt('didactic_default_type'));
78 $excl_tpl = false;
79
80 foreach($tpls as $tpl)
81 {
82 //just add if template is effective except template is already applied to this object
83 if($tpl->isEffective($_GET['ref_id']))
84 {
85 $options[$tpl->getId()] = $tpl->getPresentationTitle();
86
87 if($tpl->isExclusive())
88 {
89 $excl_tpl = true;
90 }
91 }
92 }
93
94 if($excl_tpl && $value != 0)
95 {
96 //remove default entry if an exclusive template exists but only if the actual entry isn't the default
97 unset($options[0]);
98 }
99
100 if(!in_array($value, array_keys($options)) || ($excl_tpl && $value == 0))
101 {
102 $options[$value] = $this->lng->txt('not_available');
103 }
104
105 if(count($options) < 2)
106 {
107 return false;
108 }
109
110 include_once './Services/Form/classes/class.ilSelectInputGUI.php';
111 $tpl_selection = new ilSelectInputGUI(
112 '',
113 'tplid'
114 );
115 $tpl_selection->setOptions($options);
116 $tpl_selection->setValue($value);
117 $toolbar->addInputItem($tpl_selection);
118
119 // Apply templates switch
120 $toolbar->addFormButton($this->lng->txt('change'),'confirmTemplateSwitch');
121 return true;
122 }
123
124 /*
125 * Show didactic template switch confirmation screen
126 */
127 protected function confirmTemplateSwitch()
128 {
129 global $ilCtrl, $ilTabs, $tpl;
130
131 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
132
133 // Check if template is changed
134 $new_tpl_id = (int) $_REQUEST['tplid'];
135 if($new_tpl_id == ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId()))
136 {
137 ilLoggerFactory::getLogger('otpl')->debug('Template id: '.$new_tpl_id);
138 ilUtil::sendInfo($this->lng->txt('didactic_not_changed'),true);
139 $ilCtrl->returnToParent($this);
140 }
141
142 $ilTabs->clearTargets();
143 $ilTabs->clearSubTabs();
144
145 include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
146 $confirm = new ilConfirmationGUI();
147 $confirm->setFormAction($ilCtrl->getFormAction($this));
148 $confirm->setHeaderText($this->lng->txt('didactic_confirm_apply_new_template'));
149 $confirm->setConfirm($this->lng->txt('apply'), 'switchTemplate');
150 $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
151
152 if($new_tpl_id)
153 {
154 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
155 $dtpl = new ilDidacticTemplateSetting($new_tpl_id);
156
157 $confirm->addItem(
158 'tplid',
159 $new_tpl_id,
160 $dtpl->getPresentationTitle().
161 '<div class="il_Description">'.
162 $dtpl->getPresentationDescription().' '.
163 '</div>'
164 );
165 }
166 else
167 {
168 $confirm->addItem(
169 'tplid',
170 $new_tpl_id,
171 $this->lng->txt('default').' '.
172 '<div class="il_Description">'.
173 sprintf(
174 $this->lng->txt('didactic_default_type_info'),
175 $this->lng->txt('objs_'.$this->getParentObject()->object->getType())
176 ).
177 '</div>'
178 );
179
180 }
181 $tpl->setContent($confirm->getHTML());
182 }
183
187 protected function cancel()
188 {
189 global $ilCtrl;
190
191 $ilCtrl->returnToParent($this);
192 }
193
197 protected function switchTemplate()
198 {
199 global $ilCtrl;
200
201 $new_tpl_id = (int) $_REQUEST['tplid'];
202
203 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateUtils.php';
204 ilDidacticTemplateUtils::switchTemplate($this->getParentObject()->object->getRefId(), $new_tpl_id);
205
206 ilUtil::sendSuccess($this->lng->txt('didactic_template_applied'),true);
207 $ilCtrl->returnToParent($this);
208 }
209}
210?>
sprintf('%.4f', $callTime)
global $tpl
Definition: ilias.php:8
$_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 sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
if(!is_array($argv)) $options