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