ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 {
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 {
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
192 $form = new ilAddAnswerModalFormGUI();
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}
An exception for terminatinating execution or to throw for unit testing.
__construct($a_parent_obj, $a_parent_cmd="", $question)
ilAnswerFrequencyStatisticTableGUI constructor.
static getInstance()
Get instance.
Class ilTable2GUI.
getParentObject()
Get parent object.
setPrefix($a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
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.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
special template class to simplify handling of ITX/PEAR
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc