ILIAS  release_8 Revision v8.24
class.ilAssQuestionSkillAssignmentsTableGUI.php
Go to the documentation of this file.
1<?php
2
26{
31
36
41
43 {
44 $this->skillQuestionAssignmentList = $assignmentList;
45 }
46
50 public function areManipulationsEnabled(): bool
51 {
53 }
54
59 {
60 $this->manipulationsEnabled = $manipulationsEnabled;
61 }
62
63 public function __construct($parentOBJ, $parentCmd, ilCtrl $ctrl, ilLanguage $lng)
64 {
65 parent::__construct($parentOBJ, $parentCmd);
66
67 $this->lng = $lng;
68 $this->ctrl = $ctrl;
69
70 $this->setId('assQstSkl');
71 $this->setPrefix('assQstSkl');
72
73 $this->setStyle('table', 'fullwidth');
74
75 $this->setRowTemplate("tpl.tst_skl_qst_assignment_row.html", "Modules/Test");
76
77 $this->enable('header');
78 $this->disable('sort');
79 $this->disable('select_all');
80 }
81
82 public function init(): void
83 {
84 $this->initColumns();
85
86 if ($this->areManipulationsEnabled()) {
87 $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
88
89 $this->addCommandButton(
91 $this->lng->txt('tst_save_comp_points')
92 );
93 }
94 }
95
100 {
102 }
103
104 private function initColumns(): void
105 {
106 $this->addColumn($this->lng->txt('tst_question'), 'question', '25%');
107 $this->addColumn($this->lng->txt('tst_competence'), 'competence', '');
108 $this->addColumn($this->lng->txt('tst_comp_eval_mode'), 'eval_mode', '13%');
109 $this->addColumn($this->lng->txt('tst_comp_points'), 'points', '12%');
110 $this->addColumn($this->lng->txt('actions'), 'actions', '20%');
111 }
112
113 public function fillRow(array $a_set): void
114 {
115 $assignments = $this->skillQuestionAssignmentList->getAssignmentsByQuestionId($a_set['question_id']);
116
117 $this->ctrl->setParameter($this->parent_obj, 'question_id', $a_set['question_id']);
118
119 $this->tpl->setCurrentBlock('question_title');
120 $this->tpl->setVariable('ROWSPAN', $this->getRowspan($assignments));
121 $this->tpl->setVariable('QUESTION_TITLE', $a_set['title']);
122 $this->tpl->setVariable('QUESTION_DESCRIPTION', $a_set['description']);
123 $this->tpl->parseCurrentBlock();
124
125 $this->tpl->setCurrentBlock('tbl_content');
126
127 for ($i = 0, $numAssigns = count($assignments); $i < $numAssigns; $i++) {
128 /* @var ilAssQuestionSkillAssignment $assignment */
129 $assignment = $assignments[$i];
130
131 $this->tpl->setCurrentBlock('actions_col');
132 $this->tpl->setVariable('ACTION', $this->getCompetenceAssignPropertiesFormLink($assignment));
133 $this->tpl->parseCurrentBlock();
134
135 $this->tpl->setCurrentBlock('tbl_content');
136
137 $this->tpl->setVariable('COMPETENCE', $assignment->getSkillTitle());
138 $this->tpl->setVariable('COMPETENCE_PATH', $assignment->getSkillPath());
139 $this->tpl->setVariable('EVAL_MODE', $this->getEvalModeLabel($assignment));
140
141 if ($this->isSkillPointInputRequired($assignment)) {
142 $this->tpl->setVariable('SKILL_POINTS', $this->buildSkillPointsInput($assignment));
143 } else {
144 $this->tpl->setVariable('SKILL_POINTS', $assignment->getMaxSkillPoints());
145 }
146
147 if ($this->areManipulationsEnabled() || ($i + 1) < $numAssigns) {
148 $this->tpl->parseCurrentBlock();
149
150 $this->tpl->setCurrentBlock('tbl_content');
151 $this->tpl->setVariable("CSS_ROW", $this->css_row);
152 }
153 }
154
155 if ($this->areManipulationsEnabled()) {
156 $this->tpl->setCurrentBlock('actions_col');
157 $this->tpl->setVariable('ACTION', $this->getManageCompetenceAssignsActionLink());
158 $this->tpl->parseCurrentBlock();
159
160 $this->tpl->setCurrentBlock('tbl_content');
161 } elseif (!$numAssigns) {
162 $this->tpl->setCurrentBlock('actions_col');
163 $this->tpl->setVariable('ACTION', '&nbsp;');
164 $this->tpl->parseCurrentBlock();
165
166 $this->tpl->setCurrentBlock('tbl_content');
167 }
168 }
169
170 private function getRowspan($assignments): int
171 {
172 $cnt = count($assignments);
173
174 if ($cnt == 0) {
175 return 1;
176 }
177
178 if ($this->areManipulationsEnabled()) {
179 $cnt++;
180 }
181
182 return $cnt;
183 }
184
185 private function getManageCompetenceAssignsActionLink(): string
186 {
187 $href = $this->ctrl->getLinkTarget(
188 $this->parent_obj,
190 );
191
192 $label = $this->lng->txt('tst_manage_competence_assigns');
193
194 return $this->buildActionLink($href, $label);
195 }
196
198 {
199 $this->ctrl->setParameter($this->parent_obj, 'skill_base_id', $assignment->getSkillBaseId());
200 $this->ctrl->setParameter($this->parent_obj, 'skill_tref_id', $assignment->getSkillTrefId());
201
202 $href = $this->ctrl->getLinkTarget(
203 $this->parent_obj,
205 );
206
207 if ($this->areManipulationsEnabled()) {
208 $label = $this->lng->txt('tst_edit_competence_assign');
209 } else {
210 $label = $this->lng->txt('tst_view_competence_assign');
211 }
212
213 $this->ctrl->setParameter($this->parent_obj, 'skill_base_id', null);
214 $this->ctrl->setParameter($this->parent_obj, 'skill_tref_id', null);
215
216 return $this->buildActionLink($href, $label);
217 }
218
219 private function buildActionLink($href, $label): string
220 {
221 return "<a href=\"{$href}\" title=\"{$label}\">{$label}</a>";
222 }
223
224 private function buildActionColumnHTML($assignments): string
225 {
226 $actions = array();
227
228 /* PHP8: This appears to be an incomplete feature: Removal of skill assignment is nowhere found other than
229 here, ilAssQuestionSkillAssignmentsGUI::CMD_REMOVE_SKILL_QUEST_ASSIGN is undefined. Defusing for now.
230
231 foreach ($assignments as $assignment) {
232 $this->ctrl->setParameter($this->parent_obj, 'skill_base_id', $assignment->getSkillBaseId());
233 $this->ctrl->setParameter($this->parent_obj, 'skill_tref_id', $assignment->getSkillTrefId());
234
235 $href = $this->ctrl->getLinkTarget(
236 $this->parent_obj,
237 ilAssQuestionSkillAssignmentsGUI::CMD_REMOVE_SKILL_QUEST_ASSIGN
238 );
239
240 $label = $this->lng->txt('tst_remove_competence');
241
242 $actions[] = $this->buildActionLink($href, $label);
243 }
244 */
245
246 $href = $this->ctrl->getLinkTarget(
247 $this->parent_obj,
249 );
250
251 $label = $this->lng->txt('tst_assign_competence');
252 $actions[] = $this->buildActionLink($href, $label);
253
254 return implode('<br />', $actions);
255 }
256
257 private function getEvalModeLabel(ilAssQuestionSkillAssignment $assignment): string
258 {
259 if ($assignment->hasEvalModeBySolution()) {
260 return $this->lng->txt('qpl_skill_point_eval_mode_solution_compare');
261 }
262
263 return $this->lng->txt('qpl_skill_point_eval_mode_quest_result');
264 }
265
266 private function buildSkillPointsInput(ilAssQuestionSkillAssignment $assignment): string
267 {
268 $assignmentKey = implode(':', array(
269 $assignment->getSkillBaseId(), $assignment->getSkillTrefId(), $assignment->getQuestionId()
270 ));
271
272 if ($this->loadSkillPointsFromRequest) {
273 $points = isset($_POST['skill_points'][$assignmentKey]) ? ilUtil::stripSlashes($_POST['skill_points'][$assignmentKey]) : '';
274 } else {
275 $points = $assignment->getSkillPoints();
276 }
277
278 return "<input type\"text\" size=\"2\" name=\"skill_points[{$assignmentKey}]\" value=\"{$points}\" />";
279 }
280
281 private function isSkillPointInputRequired(ilAssQuestionSkillAssignment $assignment): bool
282 {
283 if (!$this->areManipulationsEnabled()) {
284 return false;
285 }
286
287 if ($assignment->hasEvalModeBySolution()) {
288 return false;
289 }
290
291 return true;
292 }
293}
getCompetenceAssignPropertiesFormLink(ilAssQuestionSkillAssignment $assignment)
setSkillQuestionAssignmentList(ilAssQuestionSkillAssignmentList $assignmentList)
buildSkillPointsInput(ilAssQuestionSkillAssignment $assignment)
getEvalModeLabel(ilAssQuestionSkillAssignment $assignment)
isSkillPointInputRequired(ilAssQuestionSkillAssignment $assignment)
__construct($parentOBJ, $parentCmd, ilCtrl $ctrl, ilLanguage $lng)
Class ilCtrl provides processing control methods.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
ilLanguage $lng
enable(string $a_module_name)
setStyle(string $a_element, string $a_style)
disable(string $a_module_name)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc