ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 
40  private $taxonomyLabelTranslater = null;
41 
42  public function __construct(ilCtrl $ctrl, ilLanguage $lng, $parentGUI, $parentCMD)
43  {
44  parent::__construct($parentGUI, $parentCMD);
45 
46  $this->ctrl = $ctrl;
47  $this->lng = $lng;
48 
49  $this->definitionEditModeEnabled = false;
50  $this->questionAmountColumnEnabled = false;
51  }
52 
54  {
55  $this->taxonomyLabelTranslater = $translater;
56  }
57 
59  {
60  $this->definitionEditModeEnabled = $definitionEditModeEnabled;
61  }
62 
63  public function isDefinitionEditModeEnabled()
64  {
66  }
67 
69  {
70  $this->questionAmountColumnEnabled = $questionAmountColumnEnabled;
71  }
72 
74  {
76  }
77 
78  public function fillRow($set)
79  {
80  if( $this->isDefinitionEditModeEnabled() )
81  {
82  $this->tpl->setCurrentBlock('col_selection_checkbox');
83  $this->tpl->setVariable('SELECTION_CHECKBOX_HTML', $this->getSelectionCheckboxHTML($set['def_id']));
84  $this->tpl->parseCurrentBlock();
85 
86  $this->tpl->setCurrentBlock('col_actions');
87  $this->tpl->setVariable('ACTIONS_HTML', $this->getActionsHTML($set['def_id']));
88  $this->tpl->parseCurrentBlock();
89 
90  $this->tpl->setCurrentBlock('col_order_checkbox');
91  $this->tpl->setVariable('ORDER_INPUT_HTML', $this->getDefinitionOrderInputHTML(
92  $set['def_id'], $this->getOrderNumberForSequencePosition($set['sequence_position'])
93  ));
94  $this->tpl->parseCurrentBlock();
95  }
96 
97  if( $this->isQuestionAmountColumnEnabled() )
98  {
99  if( $this->isDefinitionEditModeEnabled() )
100  {
101  $questionAmountHTML = $this->getQuestionAmountInputHTML(
102  $set['def_id'], $set['question_amount']
103  );
104  }
105  else
106  {
107  $questionAmountHTML = $set['question_amount'];
108  }
109 
110  $this->tpl->setCurrentBlock('col_question_amount');
111  $this->tpl->setVariable('QUESTION_AMOUNT_INPUT_HTML', $questionAmountHTML);
112  $this->tpl->parseCurrentBlock();
113  }
114 
115  $this->tpl->setVariable('SOURCE_POOL_LABEL', $set['source_pool_label']);
116  $this->tpl->setVariable('FILTER_TAXONOMY', $this->getTaxonomyTreeLabel($set['filter_taxonomy']));
117  $this->tpl->setVariable('FILTER_TAX_NODE', $this->getTaxonomyNodeLabel($set['filter_tax_node']));
118  }
119 
120  private function getSelectionCheckboxHTML($sourcePoolDefinitionId)
121  {
122  return '<input type="checkbox" value="'.$sourcePoolDefinitionId.'" name="src_pool_def_ids[]" />';
123  }
124 
125  private function getDefinitionOrderInputHTML($srcPoolDefId, $defOrderNumber)
126  {
127  return '<input type="text" size="2" value="'.$defOrderNumber.'" name="def_order['.$srcPoolDefId.']" />';
128  }
129 
130  private function getQuestionAmountInputHTML($srcPoolDefId, $questionAmount)
131  {
132  return '<input type="text" size="4" value="'.$questionAmount.'" name="quest_amount['.$srcPoolDefId.']" />';
133  }
134 
135  private function getActionsHTML($sourcePoolDefinitionId)
136  {
137  require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
138 
139  $selectionList = new ilAdvancedSelectionListGUI();
140 
141  $selectionList->setId('sourcePoolDefinitionActions_'.$sourcePoolDefinitionId);
142  $selectionList->setListTitle($this->lng->txt("actions"));
143 
144  $selectionList->addItem($this->lng->txt('edit'), '', $this->getEditHref($sourcePoolDefinitionId));
145  $selectionList->addItem($this->lng->txt('delete'), '', $this->getDeleteHref($sourcePoolDefinitionId));
146 
147  return $selectionList->getHTML();
148  }
149 
150  private function getEditHref($sourcePoolDefinitionId)
151  {
152  $href = $this->ctrl->getLinkTarget(
154  );
155 
156  $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=".$sourcePoolDefinitionId, true);
157 
158  return $href;
159  }
160 
161  private function getDeleteHref($sourcePoolDefinitionId)
162  {
163  $href = $this->ctrl->getLinkTarget(
165  );
166 
167  $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=".$sourcePoolDefinitionId, true);
168 
169  return $href;
170  }
171 
172  private function getOrderNumberForSequencePosition($sequencePosition)
173  {
174  return ( $sequencePosition * 10 );
175  }
176 
177  private function getTaxonomyTreeLabel($taxonomyTreeId)
178  {
179  if( !$taxonomyTreeId )
180  {
181  return '';
182  }
183 
184  return $this->taxonomyLabelTranslater->getTaxonomyTreeLabel($taxonomyTreeId);
185  }
186 
187  private function getTaxonomyNodeLabel($taxonomyNodeId)
188  {
189  if( !$taxonomyNodeId )
190  {
191  return '';
192  }
193 
194  return $this->taxonomyLabelTranslater->getTaxonomyNodeLabel($taxonomyNodeId);
195  }
196 
197  public function build()
198  {
199  $this->setTableIdentifiers();
200 
201  $this->setTitle($this->lng->txt('tst_src_quest_pool_def_list_table'));
202 
203  $this->setRowTemplate("tpl.il_tst_rnd_quest_set_src_pool_def_row.html", "Modules/Test");
204 
205  $this->enable('header');
206  $this->disable('sort');
207 
208  $this->enable('select_all');
209  $this->setSelectAllCheckbox('src_pool_def_ids[]');
210 
211  $this->setExternalSegmentation(true);
212  $this->setLimit(PHP_INT_MAX);
213 
214  $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
215 
216  $this->addCommands();
217  $this->addColumns();
218  }
219 
220  private function setTableIdentifiers()
221  {
222  $this->setId(self::IDENTIFIER);
223  $this->setPrefix(self::IDENTIFIER);
224  $this->setFormName(self::IDENTIFIER);
225  }
226 
227  private function addCommands()
228  {
229  if( $this->isDefinitionEditModeEnabled() )
230  {
233  }
234  }
235 
236  private function addColumns()
237  {
238  if( $this->isDefinitionEditModeEnabled() )
239  {
240  $this->addColumn('', 'select', '1%', true);
241  $this->addColumn('', 'order', '1%', true);
242  }
243 
244  $this->addColumn($this->lng->txt("tst_source_question_pool"),'source_question_pool', '');
245  $this->addColumn($this->lng->txt("tst_filter_taxonomy"),'tst_filter_taxonomy', '');
246  $this->addColumn($this->lng->txt("tst_filter_tax_node"),'tst_filter_tax_node', '');
247 
248  if( $this->isQuestionAmountColumnEnabled() )
249  {
250  $this->addColumn($this->lng->txt("tst_question_amount"),'tst_question_amount', '');
251  }
252 
253  if( $this->isDefinitionEditModeEnabled() )
254  {
255  $this->addColumn($this->lng->txt("actions"),'actions', '');
256  }
257  }
258 
259  public function init(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
260  {
261  $rows = array();
262 
263  foreach($sourcePoolDefinitionList as $sourcePoolDefinition)
264  {
267  $set = array();
268 
269  $set['def_id'] = $sourcePoolDefinition->getId();
270  $set['sequence_position'] = $sourcePoolDefinition->getSequencePosition();
271  $set['source_pool_label'] = $sourcePoolDefinition->getPoolTitle();
272  $set['filter_taxonomy'] = $sourcePoolDefinition->getMappedFilterTaxId();
273  $set['filter_tax_node'] = $sourcePoolDefinition->getMappedFilterTaxNodeId();
274  $set['question_amount'] = $sourcePoolDefinition->getQuestionAmount();
275 
276  $rows[] = $set;
277  }
278 
279  $this->setData($rows);
280  }
281 
282  public function applySubmit(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList)
283  {
284  foreach($sourcePoolDefinitionList as $sourcePoolDefinition)
285  {
288  $orderNumber = $this->fetchOrderNumberParameter($sourcePoolDefinition);
289  $sourcePoolDefinition->setSequencePosition($orderNumber);
290 
291  if( $this->isQuestionAmountColumnEnabled())
292  {
293  $questionAmount = $this->fetchQuestionAmountParameter($sourcePoolDefinition);
294  $sourcePoolDefinition->setQuestionAmount($questionAmount);
295  }
296  else
297  {
298  $sourcePoolDefinition->setQuestionAmount(null);
299  }
300  }
301  }
302 
304  {
305  return (int)$_POST['def_order'][$definition->getId()];
306  }
307 
309  {
310  return (int)$_POST['quest_amount'][$definition->getId()];
311  }
312 }
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
setFormName($a_formname)
Set Form name.
This class provides processing control methods.
$_POST['username']
Definition: cron.php:12
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.
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
language handling
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
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.
setLimit($a_limit=0, $a_default_limit=0)