ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Table/classes/class.ilTable2GUI.php';
5 
14 {
15  const IDENTIFIER = 'tstRndPools';
16 
20  protected $ctrl = null;
21 
25  protected $lng = null;
26 
31 
36 
37  // fau: taxFilter/typeFilter - flag to show the mapped taxonomy filter instead of the original
41  private $showMappedTaxonomyFilter = false;
42  // fau.
43 
47  private $taxonomyLabelTranslater = null;
48 
49  public function __construct(ilCtrl $ctrl, ilLanguage $lng, $parentGUI, $parentCMD)
50  {
51  parent::__construct($parentGUI, $parentCMD);
52 
53  $this->ctrl = $ctrl;
54  $this->lng = $lng;
55 
56  $this->definitionEditModeEnabled = false;
57  $this->questionAmountColumnEnabled = false;
58  }
59 
61  {
62  $this->taxonomyLabelTranslater = $translater;
63  }
64 
66  {
67  $this->definitionEditModeEnabled = $definitionEditModeEnabled;
68  }
69 
70  public function isDefinitionEditModeEnabled()
71  {
73  }
74 
76  {
77  $this->questionAmountColumnEnabled = $questionAmountColumnEnabled;
78  }
79 
81  {
83  }
84 
85  // fau: taxFilter - set flag to show the mapped tayonomy filter instead of original
87  {
88  $this->showMappedTaxonomyFilter = $showMappedTaxonomyFilter;
89  }
90  // fau.
91 
92  public function fillRow($set)
93  {
94  if ($this->isDefinitionEditModeEnabled()) {
95  $this->tpl->setCurrentBlock('col_selection_checkbox');
96  $this->tpl->setVariable('SELECTION_CHECKBOX_HTML', $this->getSelectionCheckboxHTML($set['def_id']));
97  $this->tpl->parseCurrentBlock();
98 
99  $this->tpl->setCurrentBlock('col_actions');
100  $this->tpl->setVariable('ACTIONS_HTML', $this->getActionsHTML($set['def_id']));
101  $this->tpl->parseCurrentBlock();
102 
103  $this->tpl->setCurrentBlock('col_order_checkbox');
104  $this->tpl->setVariable('ORDER_INPUT_HTML', $this->getDefinitionOrderInputHTML(
105  $set['def_id'],
106  $this->getOrderNumberForSequencePosition($set['sequence_position'])
107  ));
108  $this->tpl->parseCurrentBlock();
109  }
110  // fau: taxFilter/typeFilter - show sequence position to identify the filter in the database
111  else {
112  $this->tpl->setCurrentBlock('col_order_checkbox');
113  $this->tpl->setVariable('ORDER_INPUT_HTML', $set['sequence_position']);
114  $this->tpl->parseCurrentBlock();
115  }
116  // fau.
117 
118  if ($this->isQuestionAmountColumnEnabled()) {
119  if ($this->isDefinitionEditModeEnabled()) {
120  $questionAmountHTML = $this->getQuestionAmountInputHTML(
121  $set['def_id'],
122  $set['question_amount']
123  );
124  } else {
125  $questionAmountHTML = $set['question_amount'];
126  }
127 
128  $this->tpl->setCurrentBlock('col_question_amount');
129  $this->tpl->setVariable('QUESTION_AMOUNT_INPUT_HTML', $questionAmountHTML);
130  $this->tpl->parseCurrentBlock();
131  }
132 
133  $this->tpl->setVariable('SOURCE_POOL_LABEL', $set['source_pool_label']);
134  // fau: taxFilter/typeFilter - set taxonomy/type filter label in a single coulumn each
135  $this->tpl->setVariable('TAXONOMY_FILTER', $this->taxonomyLabelTranslater->getTaxonomyFilterLabel($set['taxonomy_filter'], '<br />'));
136  #$this->tpl->setVariable('FILTER_TAXONOMY', $this->getTaxonomyTreeLabel($set['filter_taxonomy']));
137  #$this->tpl->setVariable('FILTER_TAX_NODE', $this->getTaxonomyNodeLabel($set['filter_tax_node']));
138  $this->tpl->setVariable('LIFECYCLE_FILTER', $this->taxonomyLabelTranslater->getLifecycleFilterLabel($set['lifecycle_filter']));
139  $this->tpl->setVariable('TYPE_FILTER', $this->taxonomyLabelTranslater->getTypeFilterLabel($set['type_filter']));
140  // fau.
141  }
142 
143  private function getSelectionCheckboxHTML($sourcePoolDefinitionId)
144  {
145  return '<input type="checkbox" value="' . $sourcePoolDefinitionId . '" name="src_pool_def_ids[]" />';
146  }
147 
148  private function getDefinitionOrderInputHTML($srcPoolDefId, $defOrderNumber)
149  {
150  return '<input type="text" size="2" value="' . $defOrderNumber . '" name="def_order[' . $srcPoolDefId . ']" />';
151  }
152 
153  private function getQuestionAmountInputHTML($srcPoolDefId, $questionAmount)
154  {
155  return '<input type="text" size="4" value="' . $questionAmount . '" name="quest_amount[' . $srcPoolDefId . ']" />';
156  }
157 
158  private function getActionsHTML($sourcePoolDefinitionId)
159  {
160  require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
161 
162  $selectionList = new ilAdvancedSelectionListGUI();
163 
164  $selectionList->setId('sourcePoolDefinitionActions_' . $sourcePoolDefinitionId);
165  $selectionList->setListTitle($this->lng->txt("actions"));
166 
167  $selectionList->addItem($this->lng->txt('edit'), '', $this->getEditHref($sourcePoolDefinitionId));
168  $selectionList->addItem($this->lng->txt('delete'), '', $this->getDeleteHref($sourcePoolDefinitionId));
169 
170  return $selectionList->getHTML();
171  }
172 
173  private function getEditHref($sourcePoolDefinitionId)
174  {
175  $href = $this->ctrl->getLinkTarget(
176  $this->parent_obj,
178  );
179 
180  $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=" . $sourcePoolDefinitionId, true);
181 
182  return $href;
183  }
184 
185  private function getDeleteHref($sourcePoolDefinitionId)
186  {
187  $href = $this->ctrl->getLinkTarget(
188  $this->parent_obj,
190  );
191 
192  $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=" . $sourcePoolDefinitionId, true);
193 
194  return $href;
195  }
196 
197  private function getOrderNumberForSequencePosition($sequencePosition)
198  {
199  return ($sequencePosition * 10);
200  }
201 
202  private function getTaxonomyTreeLabel($taxonomyTreeId)
203  {
204  if (!$taxonomyTreeId) {
205  return '';
206  }
207 
208  return $this->taxonomyLabelTranslater->getTaxonomyTreeLabel($taxonomyTreeId);
209  }
210 
211  private function getTaxonomyNodeLabel($taxonomyNodeId)
212  {
213  if (!$taxonomyNodeId) {
214  return '';
215  }
216 
217  return $this->taxonomyLabelTranslater->getTaxonomyNodeLabel($taxonomyNodeId);
218  }
219 
220  public function build()
221  {
222  $this->setTableIdentifiers();
223 
224  $this->setTitle($this->lng->txt('tst_src_quest_pool_def_list_table'));
225 
226  $this->setRowTemplate("tpl.il_tst_rnd_quest_set_src_pool_def_row.html", "Modules/Test");
227 
228  $this->enable('header');
229  $this->disable('sort');
230 
231  $this->enable('select_all');
232  $this->setSelectAllCheckbox('src_pool_def_ids[]');
233 
234  $this->setExternalSegmentation(true);
235  $this->setLimit(PHP_INT_MAX);
236 
237  $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
238 
239  $this->addCommands();
240  $this->addColumns();
241  }
242 
243  private function setTableIdentifiers()
244  {
245  $this->setId(self::IDENTIFIER);
246  $this->setPrefix(self::IDENTIFIER);
247  $this->setFormName(self::IDENTIFIER);
248  }
249 
250  private function addCommands()
251  {
252  if ($this->isDefinitionEditModeEnabled()) {
255  }
256  }
257 
258  private function addColumns()
259  {
260  if ($this->isDefinitionEditModeEnabled()) {
261  $this->addColumn('', 'select', '1%', true);
262  $this->addColumn('', 'order', '1%', true);
263  }
264  // fau: taxFilter/typeFilter - show order position to easily identify the filter in the database
265  else {
266  $this->addColumn($this->lng->txt("position"));
267  }
268  // fau.
269 
270  $this->addColumn($this->lng->txt("tst_source_question_pool"), 'source_question_pool', '');
271  // fau: taxFilter/typeFilter - add one column for taxonomy and nodes and one for type filter
272  $this->addColumn($this->lng->txt("tst_filter_taxonomy") . ' / ' . $this->lng->txt("tst_filter_tax_node"), 'tst_filter_taxonomy', '');
273  #$this->addColumn($this->lng->txt("tst_filter_taxonomy"),'tst_filter_taxonomy', '');
274  #$this->addColumn($this->lng->txt("tst_filter_tax_node"),'tst_filter_tax_node', '');
275  $this->addColumn($this->lng->txt("qst_lifecycle"), 'tst_filter_lifecycle', '');
276  $this->addColumn($this->lng->txt("tst_filter_question_type"), 'tst_filter_question_type', '');
277  // fau.
278 
279  if ($this->isQuestionAmountColumnEnabled()) {
280  $this->addColumn($this->lng->txt("tst_question_amount"), 'tst_question_amount', '');
281  }
282 
283  if ($this->isDefinitionEditModeEnabled()) {
284  $this->addColumn($this->lng->txt("actions"), 'actions', '');
285  }
286  }
287 
288  public function init(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
289  {
290  $rows = array();
291 
292  foreach ($sourcePoolDefinitionList as $sourcePoolDefinition) {
295  $set = array();
296 
297  $set['def_id'] = $sourcePoolDefinition->getId();
298  $set['sequence_position'] = $sourcePoolDefinition->getSequencePosition();
299  $set['source_pool_label'] = $sourcePoolDefinition->getPoolTitle();
300  // fau: taxFilter/typeFilter - get the type and taxonomy filter for display
301  if ($this->showMappedTaxonomyFilter) {
302  // mapped filter will be used after synchronisation
303  $set['taxonomy_filter'] = $sourcePoolDefinition->getMappedTaxonomyFilter();
304  } else {
305  // original filter will be used before synchronisation
306  $set['taxonomy_filter'] = $sourcePoolDefinition->getOriginalTaxonomyFilter();
307  }
308  #$set['filter_taxonomy'] = $sourcePoolDefinition->getMappedFilterTaxId();
309  #$set['filter_tax_node'] = $sourcePoolDefinition->getMappedFilterTaxNodeId();
310  $set['lifecycle_filter'] = $sourcePoolDefinition->getLifecycleFilter();
311  $set['type_filter'] = $sourcePoolDefinition->getTypeFilter();
312  // fau.
313  $set['question_amount'] = $sourcePoolDefinition->getQuestionAmount();
314 
315  $rows[] = $set;
316  }
317 
318  $this->setData($rows);
319  }
320 
321  public function applySubmit(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
322  {
323  foreach ($sourcePoolDefinitionList as $sourcePoolDefinition) {
326  $orderNumber = $this->fetchOrderNumberParameter($sourcePoolDefinition);
327  $sourcePoolDefinition->setSequencePosition($orderNumber);
328 
329  if ($this->isQuestionAmountColumnEnabled()) {
330  $questionAmount = $this->fetchQuestionAmountParameter($sourcePoolDefinition);
331  $sourcePoolDefinition->setQuestionAmount($questionAmount);
332  } else {
333  $sourcePoolDefinition->setQuestionAmount(null);
334  }
335  }
336  }
337 
339  {
340  return (int) $_POST['def_order'][$definition->getId()];
341  }
342 
344  {
345  return (int) $_POST['quest_amount'][$definition->getId()];
346  }
347 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
This class provides processing control methods.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
addMultiCommand($a_cmd, $a_text)
Add Command button.
enable($a_module_name)
enables particular modules of table
setPrefix($a_prefix)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
$rows
Definition: xhr_table.php:10
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
setFormName($a_formname="")
Set Form name.
__construct(Container $dic, ilPlugin $plugin)
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
language handling
$_POST["username"]
setLimit($a_limit=0, $a_default_limit=0)