ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilObjQuestionPoolSettingsGeneralGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
20 const CMD_SHOW_FORM = 'showForm';
21 const CMD_SAVE_FORM = 'saveForm';
22
28 protected $ctrl = null;
29
35 protected $access = null;
36
42 protected $lng = null;
43
49 protected $tpl = null;
50
56 protected $tabs = null;
57
63 protected $poolGUI = null;
64
70 protected $poolOBJ = null;
71
76 {
77 $this->ctrl = $ctrl;
78 $this->access = $access;
79 $this->lng = $lng;
80 $this->tpl = $tpl;
81 $this->tabs = $tabs;
82
83 $this->poolGUI = $poolGUI;
84 $this->poolOBJ = $poolGUI->object;
85 }
86
90 public function executeCommand()
91 {
92 // allow only write access
93
94 if (!$this->access->checkAccess('write', '', $this->poolGUI->ref_id))
95 {
96 ilUtil::sendInfo($this->lng->txt('cannot_edit_question_pool'), true);
97 $this->ctrl->redirectByClass('ilObjQuestionPoolGUI', 'infoScreen');
98 }
99
100 // activate corresponding tab (auto activation does not work in ilObjTestGUI-Tabs-Salad)
101
102 $this->tabs->activateTab('settings');
103
104 // process command
105
106 $nextClass = $this->ctrl->getNextClass();
107
108 switch($nextClass)
109 {
110 default:
111 $cmd = $this->ctrl->getCmd(self::CMD_SHOW_FORM).'Cmd';
112 $this->$cmd();
113 }
114 }
115
116 private function showFormCmd(ilPropertyFormGUI $form = null)
117 {
118 if( $form === null )
119 {
120 $form = $this->buildForm();
121 }
122
123 $this->tpl->setContent( $this->ctrl->getHTML($form) );
124 }
125
126 private function saveFormCmd()
127 {
128 $form = $this->buildForm();
129
130 // form validation and initialisation
131
132 $errors = !$form->checkInput(); // ALWAYS CALL BEFORE setValuesByPost()
133 $form->setValuesByPost(); // NEVER CALL THIS BEFORE checkInput()
134
135 // return to form when any form validation errors exist
136
137 if($errors)
138 {
139 ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
140 return $this->showFormCmd($form);
141 }
142
143 // perform saving the form data
144
145 $this->performSaveForm($form);
146
147 // redirect to form output
148
149 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
150 $this->ctrl->redirect($this, self::CMD_SHOW_FORM);
151 }
152
153 private function performSaveForm(ilPropertyFormGUI $form)
154 {
155 include_once 'Services/MetaData/classes/class.ilMD.php';
156 $md_obj = new ilMD($this->poolOBJ->getId(), 0, "qpl");
157 $md_section = $md_obj->getGeneral();
158
159 // title
160 $md_section->setTitle($form->getItemByPostVar('title')->getValue());
161 $md_section->update();
162
163 // Description
164 $md_desc_ids = $md_section->getDescriptionIds();
165 if ($md_desc_ids)
166 {
167 $md_desc = $md_section->getDescription(array_pop($md_desc_ids));
168 $md_desc->setDescription($form->getItemByPostVar('description')->getValue());
169 $md_desc->update();
170 }
171 else
172 {
173 $md_desc = $md_section->addDescription();
174 $md_desc->setDescription($form->getItemByPostVar('description')->getValue());
175 $md_desc->save();
176 }
177
178 $this->poolOBJ->setTitle($form->getItemByPostVar('title')->getValue());
179 $this->poolOBJ->setDescription($form->getItemByPostVar('description')->getValue());
180 $this->poolOBJ->update();
181
182 $online = $form->getItemByPostVar('online');
183 $this->poolOBJ->setOnline($online->getChecked());
184
185 $showTax = $form->getItemByPostVar('show_taxonomies');
186 $this->poolOBJ->setShowTaxonomies($showTax->getChecked());
187
188 $navTax = $form->getItemByPostVar('nav_taxonomy');
189 $this->poolOBJ->setNavTaxonomyId($navTax->getValue());
190
191 if( $this->formPropertyExists($form, 'skill_service') )
192 {
193 $skillService = $form->getItemByPostVar('skill_service');
194 $this->poolOBJ->setSkillServiceEnabled($skillService->getChecked());
195 }
196
197 $this->poolOBJ->saveToDb();
198 }
199
200 private function buildForm()
201 {
202 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
203 $form = new ilPropertyFormGUI();
204
205 $form->setFormAction($this->ctrl->getFormAction($this));
206 $form->addCommandButton(self::CMD_SAVE_FORM, $this->lng->txt('save'));
207
208 $form->setTitle($this->lng->txt('qpl_form_general_settings'));
209 $form->setId('properties');
210
211 include_once 'Services/MetaData/classes/class.ilMD.php';
212 $md_obj = new ilMD($this->poolOBJ->getId(), 0, "qpl");
213 $md_section = $md_obj->getGeneral();
214
215 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
216 $title->setRequired(true);
217 $title->setValue($md_section->getTitle());
218 $form->addItem($title);
219
220 $ids = $md_section->getDescriptionIds();
221 if($ids)
222 {
223 $desc_obj = $md_section->getDescription(array_pop($ids));
224
225 $desc = new ilTextAreaInputGUI($this->lng->txt("description"), "description");
226 $desc->setCols(50);
227 $desc->setRows(4);
228 $desc->setValue($desc_obj->getDescription());
229 $form->addItem($desc);
230 }
231
232 // online
233
234 $online = new ilCheckboxInputGUI($this->lng->txt('qpl_settings_general_form_property_online'), 'online');
235 $online->setInfo($this->lng->txt('qpl_settings_general_form_property_online_description'));
236 $online->setChecked($this->poolOBJ->getOnline());
237 $form->addItem($online);
238
239 // show taxonomies
240
241 $showTax = new ilCheckboxInputGUI($this->lng->txt('qpl_settings_general_form_property_show_taxonomies'), 'show_taxonomies');
242 $showTax->setInfo($this->lng->txt('qpl_settings_general_form_prop_show_tax_desc'));
243 $showTax->setChecked($this->poolOBJ->getShowTaxonomies());
244 $form->addItem($showTax);
245
246 $taxSelectOptions = $this->getTaxonomySelectInputOptions();
247
248 // pool navigation taxonomy
249
250 $navTax = new ilSelectInputGUI($this->lng->txt('qpl_settings_general_form_property_nav_taxonomy'), 'nav_taxonomy');
251 $navTax->setInfo($this->lng->txt('qpl_settings_general_form_property_nav_taxonomy_description'));
252 $navTax->setValue($this->poolOBJ->getNavTaxonomyId());
253 $navTax->setOptions($taxSelectOptions);
254 $showTax->addSubItem($navTax);
255
256 // skill service activation
257
259 {
260 $skillService = new ilCheckboxInputGUI($this->lng->txt('tst_activate_skill_service'), 'skill_service');
261 $skillService->setChecked($this->poolOBJ->isSkillServiceEnabled());
262 $form->addItem($skillService);
263 }
264
265 return $form;
266 }
267
269 {
270 $taxSelectOptions = array(
271 '0' => $this->lng->txt('qpl_settings_general_form_property_opt_notax_selected')
272 );
273
274 foreach($this->poolOBJ->getTaxonomyIds() as $taxId)
275 {
276 $taxSelectOptions[$taxId] = ilObject::_lookupTitle($taxId);
277 }
278
279 return $taxSelectOptions;
280 }
281
282 protected function formPropertyExists(ilPropertyFormGUI $form, $propertyId)
283 {
284 return $form->getItemByPostVar($propertyId) instanceof ilFormPropertyGUI;
285 }
286}
Class ilAccessHandler.
This class represents a checkbox property in a property form.
This class provides processing control methods.
This class represents a property in a property form.
language handling
Class ilObjQuestionPoolGUI.
__construct(ilCtrl $ctrl, ilAccessHandler $access, ilLanguage $lng, ilTemplate $tpl, ilTabsGUI $tabs, ilObjQuestionPoolGUI $poolGUI)
Constructor.
static _lookupTitle($a_id)
lookup object title
This class represents a property form user interface.
getItemByPostVar($a_post_var)
Get Item by POST variable.
This class represents a selection list property in a property form.
Tabs GUI.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$cmd
Definition: sahs_server.php:35
$errors