ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilAnswerFrequencyStatisticTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
14 {
18  protected $DIC;
19 
23  protected $question;
24 
28  protected $questionIndex;
29 
33  protected $actionsColumnEnabled = false;
34 
38  protected $additionalHtml = '';
39 
46  public function __construct($a_parent_obj, $a_parent_cmd = "", $question)
47  {
48  global $DIC; /* @var ILIAS\DI\Container $this->DIC */
49 
50  $this->DIC = $DIC;
51 
52  $this->question = $question;
53 
54  $this->setId('tstAnswerStatistic');
55  $this->setPrefix('tstAnswerStatistic');
56  $this->setTitle($this->DIC->language()->txt('tst_corrections_answers_tbl'));
57 
58  $this->setRowTemplate('tpl.tst_corrections_answer_row.html', 'Modules/Test');
59 
60  parent::__construct($a_parent_obj, $a_parent_cmd, $a_template_context = '');
61 
62  $this->setDefaultOrderDirection('asc');
63  $this->setDefaultOrderField('answer');
64  }
65 
69  public function isActionsColumnEnabled() : bool
70  {
72  }
73 
78  {
79  $this->actionsColumnEnabled = $actionsColumnEnabled;
80  }
81 
85  public function getAdditionalHtml() : string
86  {
87  return $this->additionalHtml;
88  }
89 
93  public function setAdditionalHtml(string $additionalHtml)
94  {
95  $this->additionalHtml = $additionalHtml;
96  }
97 
101  public function addAdditionalHtml(string $additionalHtml)
102  {
103  $this->additionalHtml .= $additionalHtml;
104  }
105 
109  public function getQuestionIndex() : int
110  {
111  return $this->questionIndex;
112  }
113 
117  public function setQuestionIndex(int $questionIndex)
118  {
119  $this->questionIndex = $questionIndex;
120  }
121 
122  public function initColumns()
123  {
124  $this->addColumn($this->DIC->language()->txt('tst_corr_answ_stat_tbl_header_answer'), '');
125  $this->addColumn($this->DIC->language()->txt('tst_corr_answ_stat_tbl_header_frequency'), '');
126 
127  foreach ($this->getData() as $row) {
128  if (isset($row['addable'])) {
129  $this->setActionsColumnEnabled(true);
130  $this->addColumn('', '', '1%');
131  break;
132  }
133  }
134  }
135 
136  public function fillRow($data)
137  {
138  $this->tpl->setCurrentBlock('answer');
139  $this->tpl->setVariable('ANSWER', \ilUtil::prepareFormOutput($data['answer']));
140  $this->tpl->parseCurrentBlock();
141 
142  $this->tpl->setCurrentBlock('frequency');
143  $this->tpl->setVariable('FREQUENCY', $data['frequency']);
144  $this->tpl->parseCurrentBlock();
145 
146  if ($this->isActionsColumnEnabled()) {
147  if (isset($data['addable'])) {
148  $this->tpl->setCurrentBlock('actions');
149  $this->tpl->setVariable('ACTIONS', $this->buildAddAnswerAction($data));
150  $this->tpl->parseCurrentBlock();
151  } else {
152  $this->tpl->setCurrentBlock('actions');
153  $this->tpl->touchBlock('actions');
154  $this->tpl->parseCurrentBlock();
155  }
156  }
157  }
158 
159  protected function buildAddAnswerAction($data)
160  {
161  $uid = md5($this->getQuestionIndex() . $data['answer']);
162 
163  $modal = $this->buildAddAnswerModalGui($uid, $data);
164 
165  $showModalButton = ilJsLinkButton::getInstance();
166  $showModalButton->setId('btnShow_' . $uid);
167  $showModalButton->setCaption('tst_corr_add_as_answer_btn');
168  $showModalButton->setOnClick("$('#{$modal->getId()}').modal('show')");
169 
170  // TODO: migrate stuff above to ui components when ui-form supports
171  // - presentation in ui-roundtrip
172  // - submit signals
173 
174  $uiFactory = $this->DIC->ui()->factory();
175  $uiRenderer = $this->DIC->ui()->renderer();
176 
177  $modal = $uiFactory->legacy($modal->getHTML());
178  $showModalButton = $uiFactory->legacy($showModalButton->render());
179 
180  $this->addAdditionalHtml($uiRenderer->render($modal));
181 
182  return $uiRenderer->render($showModalButton);
183  }
184 
185  protected function buildAddAnswerModalGui($uid, $data)
186  {
187  $formAction = $this->DIC->ctrl()->getFormAction(
188  $this->getParentObject(),
189  'addAnswerAsynch'
190  );
191 
193  $form->setId($uid);
194  $form->setFormAction($formAction);
195  $form->setQuestionId($this->question->getId());
196  $form->setQuestionIndex($this->getQuestionIndex());
197  $form->setAnswerValue($data['answer']);
198  $form->build();
199 
200  $bodyTpl = new ilTemplate('tpl.tst_corr_addanswermodal.html', true, true, 'Modules/TestQuestionPool');
201  $bodyTpl->setVariable('BODY_UID', $uid);
202  $bodyTpl->setVariable('FORM', $form->getHTML());
203  $bodyTpl->setVariable('JS_UID', $uid);
204 
205  $modal = ilModalGUI::getInstance();
206  $modal->setId('modal_' . $uid);
207  $modal->setHeading($this->DIC->language()->txt('tst_corr_add_as_answer_btn'));
208 
209  $modal->setBody($bodyTpl->get());
210 
211  return $modal;
212  }
213 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
getParentObject()
Get parent object.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
Class ilTable2GUI.
if(isset($_POST['submit'])) $form
special template class to simplify handling of ITX/PEAR
setPrefix($a_prefix)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
$row
__construct($a_parent_obj, $a_parent_cmd="", $question)
ilAnswerFrequencyStatisticTableGUI constructor.
static getInstance()
Get instance.
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.