ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  $online = $form->getItemByPostVar('online');
156  $this->poolOBJ->setOnline($online->getChecked());
157 
158  $showTax = $form->getItemByPostVar('show_taxonomies');
159  $this->poolOBJ->setShowTaxonomies($showTax->getChecked());
160 
161  $navTax = $form->getItemByPostVar('nav_taxonomy');
162  $this->poolOBJ->setNavTaxonomyId($navTax->getValue());
163 
164  $this->poolOBJ->saveToDb();
165  }
166 
167  private function buildForm()
168  {
169  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
170  $form = new ilPropertyFormGUI();
171 
172  $form->setFormAction($this->ctrl->getFormAction($this));
173  $form->addCommandButton(self::CMD_SAVE_FORM, $this->lng->txt('save'));
174 
175  $form->setTitle($this->lng->txt('qpl_form_general_settings'));
176  $form->setId('properties');
177 
178  // online
179 
180  $online = new ilCheckboxInputGUI($this->lng->txt('qpl_settings_general_form_property_online'), 'online');
181  $online->setInfo($this->lng->txt('qpl_settings_general_form_property_online_description'));
182  $online->setChecked($this->poolOBJ->getOnline());
183  $form->addItem($online);
184 
185  // show taxonomies
186 
187  $showTax = new ilCheckboxInputGUI($this->lng->txt('qpl_settings_general_form_property_show_taxonomies'), 'show_taxonomies');
188  $showTax->setInfo($this->lng->txt('qpl_settings_general_form_prop_show_tax_desc'));
189  $showTax->setChecked($this->poolOBJ->getShowTaxonomies());
190  $form->addItem($showTax);
191 
192  $taxSelectOptions = $this->getTaxonomySelectInputOptions();
193 
194  // pool navigation taxonomy
195 
196  $navTax = new ilSelectInputGUI($this->lng->txt('qpl_settings_general_form_property_nav_taxonomy'), 'nav_taxonomy');
197  $navTax->setInfo($this->lng->txt('qpl_settings_general_form_property_nav_taxonomy_description'));
198  $navTax->setValue($this->poolOBJ->getNavTaxonomyId());
199  $navTax->setOptions($taxSelectOptions);
200  $showTax->addSubItem($navTax);
201 
202  return $form;
203  }
204 
205  private function getTaxonomySelectInputOptions()
206  {
207  $taxSelectOptions = array(
208  '0' => $this->lng->txt('qpl_settings_general_form_property_opt_notax_selected')
209  );
210 
211  foreach($this->poolOBJ->getTaxonomyIds() as $taxId)
212  {
213  $taxSelectOptions[$taxId] = ilObject::_lookupTitle($taxId);
214  }
215 
216  return $taxSelectOptions;
217  }
218 }