ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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('TYPE_FILTER', $this->taxonomyLabelTranslater->getTypeFilterLabel($set['type_filter']));
139  // fau.
140  }
141 
142  private function getSelectionCheckboxHTML($sourcePoolDefinitionId)
143  {
144  return '<input type="checkbox" value="' . $sourcePoolDefinitionId . '" name="src_pool_def_ids[]" />';
145  }
146 
147  private function getDefinitionOrderInputHTML($srcPoolDefId, $defOrderNumber)
148  {
149  return '<input type="text" size="2" value="' . $defOrderNumber . '" name="def_order[' . $srcPoolDefId . ']" />';
150  }
151 
152  private function getQuestionAmountInputHTML($srcPoolDefId, $questionAmount)
153  {
154  return '<input type="text" size="4" value="' . $questionAmount . '" name="quest_amount[' . $srcPoolDefId . ']" />';
155  }
156 
157  private function getActionsHTML($sourcePoolDefinitionId)
158  {
159  require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
160 
161  $selectionList = new ilAdvancedSelectionListGUI();
162 
163  $selectionList->setId('sourcePoolDefinitionActions_' . $sourcePoolDefinitionId);
164  $selectionList->setListTitle($this->lng->txt("actions"));
165 
166  $selectionList->addItem($this->lng->txt('edit'), '', $this->getEditHref($sourcePoolDefinitionId));
167  $selectionList->addItem($this->lng->txt('delete'), '', $this->getDeleteHref($sourcePoolDefinitionId));
168 
169  return $selectionList->getHTML();
170  }
171 
172  private function getEditHref($sourcePoolDefinitionId)
173  {
174  $href = $this->ctrl->getLinkTarget(
175  $this->parent_obj,
177  );
178 
179  $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=" . $sourcePoolDefinitionId, true);
180 
181  return $href;
182  }
183 
184  private function getDeleteHref($sourcePoolDefinitionId)
185  {
186  $href = $this->ctrl->getLinkTarget(
187  $this->parent_obj,
189  );
190 
191  $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=" . $sourcePoolDefinitionId, true);
192 
193  return $href;
194  }
195 
196  private function getOrderNumberForSequencePosition($sequencePosition)
197  {
198  return ($sequencePosition * 10);
199  }
200 
201  private function getTaxonomyTreeLabel($taxonomyTreeId)
202  {
203  if (!$taxonomyTreeId) {
204  return '';
205  }
206 
207  return $this->taxonomyLabelTranslater->getTaxonomyTreeLabel($taxonomyTreeId);
208  }
209 
210  private function getTaxonomyNodeLabel($taxonomyNodeId)
211  {
212  if (!$taxonomyNodeId) {
213  return '';
214  }
215 
216  return $this->taxonomyLabelTranslater->getTaxonomyNodeLabel($taxonomyNodeId);
217  }
218 
219  public function build()
220  {
221  $this->setTableIdentifiers();
222 
223  $this->setTitle($this->lng->txt('tst_src_quest_pool_def_list_table'));
224 
225  $this->setRowTemplate("tpl.il_tst_rnd_quest_set_src_pool_def_row.html", "Modules/Test");
226 
227  $this->enable('header');
228  $this->disable('sort');
229 
230  $this->enable('select_all');
231  $this->setSelectAllCheckbox('src_pool_def_ids[]');
232 
233  $this->setExternalSegmentation(true);
234  $this->setLimit(PHP_INT_MAX);
235 
236  $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
237 
238  $this->addCommands();
239  $this->addColumns();
240  }
241 
242  private function setTableIdentifiers()
243  {
244  $this->setId(self::IDENTIFIER);
245  $this->setPrefix(self::IDENTIFIER);
246  $this->setFormName(self::IDENTIFIER);
247  }
248 
249  private function addCommands()
250  {
251  if ($this->isDefinitionEditModeEnabled()) {
254  }
255  }
256 
257  private function addColumns()
258  {
259  if ($this->isDefinitionEditModeEnabled()) {
260  $this->addColumn('', 'select', '1%', true);
261  $this->addColumn('', 'order', '1%', true);
262  }
263  // fau: taxFilter/typeFilter - show order position to easily identify the filter in the database
264  else {
265  $this->addColumn($this->lng->txt("position"));
266  }
267  // fau.
268 
269  $this->addColumn($this->lng->txt("tst_source_question_pool"), 'source_question_pool', '');
270  // fau: taxFilter/typeFilter - add one column for taxonomy and nodes and one for type filter
271  $this->addColumn($this->lng->txt("tst_filter_taxonomy") . ' / ' . $this->lng->txt("tst_filter_tax_node"), 'tst_filter_taxonomy', '');
272  #$this->addColumn($this->lng->txt("tst_filter_taxonomy"),'tst_filter_taxonomy', '');
273  #$this->addColumn($this->lng->txt("tst_filter_tax_node"),'tst_filter_tax_node', '');
274  $this->addColumn($this->lng->txt("tst_filter_question_type"), 'tst_filter_question_type', '');
275  // fau.
276 
277  if ($this->isQuestionAmountColumnEnabled()) {
278  $this->addColumn($this->lng->txt("tst_question_amount"), 'tst_question_amount', '');
279  }
280 
281  if ($this->isDefinitionEditModeEnabled()) {
282  $this->addColumn($this->lng->txt("actions"), 'actions', '');
283  }
284  }
285 
286  public function init(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
287  {
288  $rows = array();
289 
290  foreach ($sourcePoolDefinitionList as $sourcePoolDefinition) {
293  $set = array();
294 
295  $set['def_id'] = $sourcePoolDefinition->getId();
296  $set['sequence_position'] = $sourcePoolDefinition->getSequencePosition();
297  $set['source_pool_label'] = $sourcePoolDefinition->getPoolTitle();
298  // fau: taxFilter/typeFilter - get the type and taxonomy filter for display
299  if ($this->showMappedTaxonomyFilter) {
300  // mapped filter will be used after synchronisation
301  $set['taxonomy_filter'] = $sourcePoolDefinition->getMappedTaxonomyFilter();
302  } else {
303  // original filter will be used before synchronisation
304  $set['taxonomy_filter'] = $sourcePoolDefinition->getOriginalTaxonomyFilter();
305  }
306  #$set['filter_taxonomy'] = $sourcePoolDefinition->getMappedFilterTaxId();
307  #$set['filter_tax_node'] = $sourcePoolDefinition->getMappedFilterTaxNodeId();
308  $set['type_filter'] = $sourcePoolDefinition->getTypeFilter();
309  // fau.
310  $set['question_amount'] = $sourcePoolDefinition->getQuestionAmount();
311 
312  $rows[] = $set;
313  }
314 
315  $this->setData($rows);
316  }
317 
318  public function applySubmit(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
319  {
320  foreach ($sourcePoolDefinitionList as $sourcePoolDefinition) {
323  $orderNumber = $this->fetchOrderNumberParameter($sourcePoolDefinition);
324  $sourcePoolDefinition->setSequencePosition($orderNumber);
325 
326  if ($this->isQuestionAmountColumnEnabled()) {
327  $questionAmount = $this->fetchQuestionAmountParameter($sourcePoolDefinition);
328  $sourcePoolDefinition->setQuestionAmount($questionAmount);
329  } else {
330  $sourcePoolDefinition->setQuestionAmount(null);
331  }
332  }
333  }
334 
336  {
337  return (int) $_POST['def_order'][$definition->getId()];
338  }
339 
341  {
342  return (int) $_POST['quest_amount'][$definition->getId()];
343  }
344 }
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
Class ilTable2GUI.
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.
Create styles array
The data for the language used.
$rows
Definition: xhr_table.php:10
User interface class for advanced drop-down selection lists.
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.
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
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
$_POST["username"]
setLimit($a_limit=0, $a_default_limit=0)