ILIAS  release_8 Revision v8.24
class.ilCourseObjectiveQuestionsTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=0);
20use ILIAS\HTTP\Services as HTTPServices;
21use ILIAS\Refinery\Factory as Refinery;
22
29{
30 protected HTTPServices $http;
31 protected Refinery $refinery;
33
34
35 public function __construct(object $a_parent_obj, ilObject $a_course_obj)
36 {
37 global $DIC;
38
39 $this->course_obj = $a_course_obj;
40 parent::__construct($a_parent_obj, 'questionOverview');
41
42 $this->http = $DIC->http();
43 $this->refinery = $DIC->refinery();
44
45 $this->lng->loadLanguageModule('crs');
46 $this->setFormName('questions');
47 $this->addColumn($this->lng->txt('title'), 'title', '33%');
48 $this->addColumn($this->lng->txt('crs_objective_self_assessment'), 'self', '33%%');
49 $this->addColumn($this->lng->txt('crs_objective_final_test'), 'final', '33%');
50
51 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj));
52 $this->setRowTemplate("tpl.crs_questions_table_row.html", "Modules/Course");
53 $this->disable('sort');
54 $this->enable('header');
55 $this->disable('numinfo');
56 $this->enable('select_all');
57 $this->setLimit(200);
58 $this->addCommandButton('saveQuestionOverview', $this->lng->txt('save'));
59 }
60
61 protected function fillRow(array $a_set): void
62 {
63 static $row_counter = 1;
64
65 $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
66 if (strlen($a_set['description']) !== 0) {
67 $this->tpl->setVariable('VAL_DESC', $a_set['description']);
68 }
69
70 foreach ($a_set['self_tests'] as $tst) {
71 foreach ($tst['questions'] as $qst) {
72 $this->tpl->setCurrentBlock('self_qst');
73 $this->tpl->setVariable('SELF_QST_TITLE', $qst['title']);
74 if (strlen($qst['description']) !== 0) {
75 $this->tpl->setVariable('SELF_QST_DESCRIPTION', $qst['description']);
76 }
77 $this->tpl->setVariable('SELF_QST_POINTS', $qst['points']);
78 $this->tpl->setVariable('SELF_QST_TXT_POINTS', $this->lng->txt('crs_objective_points'));
79 $this->tpl->parseCurrentBlock();
80 }
81 $this->tpl->setCurrentBlock('self_tst');
82 $this->tpl->setVariable('SELF_TST_TITLE', $tst['title']);
83 if (strlen($tst['description']) !== 0) {
84 $this->tpl->setVariable('SELF_TST_DESC', $tst['description']);
85 }
86 $this->tpl->setVariable('SELF_TYPE_IMG', ilUtil::getImagePath('icon_tst.svg'));
87 $this->tpl->setVariable('SELF_TYPE_ALT', $this->lng->txt('obj_tst'));
88 $this->tpl->parseCurrentBlock();
89 }
90 if (count($a_set['self_tests']) > 0) {
91 $this->tpl->setVariable('SELF_TXT_ALL_POINTS', $this->lng->txt('crs_objective_all_points'));
92 $this->tpl->setVariable('SELF_TXT_POINTS', $this->lng->txt('crs_objective_points'));
93 $this->tpl->setVariable('SELF_TXT_REQ_POINTS', $this->lng->txt('crs_obj_required_points'));
94 $this->tpl->setVariable('SELF_POINTS', $a_set['self_max_points']);
95 $this->tpl->setVariable('SELF_ID', $a_set['id']);
96 $this->tpl->setVariable('SELF_LIMIT', $a_set['self_limit']);
97 }
98
99 foreach ($a_set['final_tests'] as $tst) {
100 foreach ($tst['questions'] as $qst) {
101 $this->tpl->setCurrentBlock('final_qst');
102 $this->tpl->setVariable('FINAL_QST_TITLE', $qst['title']);
103 if (strlen($qst['description']) !== 0) {
104 $this->tpl->setVariable('FINAL_QST_DESCRIPTION', $qst['description']);
105 }
106 $this->tpl->setVariable('FINAL_QST_POINTS', $qst['points']);
107 $this->tpl->setVariable('FINAL_QST_TXT_POINTS', $this->lng->txt('crs_objective_points'));
108 $this->tpl->parseCurrentBlock();
109 }
110 $this->tpl->setCurrentBlock('final_tst');
111 $this->tpl->setVariable('FINAL_TST_TITLE', $tst['title']);
112 if (strlen($tst['description']) !== 0) {
113 $this->tpl->setVariable('FINAL_TST_DESC', $tst['description']);
114 }
115 $this->tpl->setVariable('FINAL_TYPE_IMG', ilUtil::getImagePath('icon_tst.svg'));
116 $this->tpl->setVariable('FINAL_TYPE_ALT', $this->lng->txt('obj_tst'));
117 $this->tpl->parseCurrentBlock();
118 }
119 if (count($a_set['final_tests']) > 0) {
120 $this->tpl->setVariable('FINAL_TXT_ALL_POINTS', $this->lng->txt('crs_objective_all_points'));
121 $this->tpl->setVariable('FINAL_TXT_POINTS', $this->lng->txt('crs_objective_points'));
122 $this->tpl->setVariable('FINAL_TXT_REQ_POINTS', $this->lng->txt('crs_obj_required_points'));
123 $this->tpl->setVariable('FINAL_POINTS', $a_set['final_max_points']);
124 $this->tpl->setVariable('FINAL_ID', $a_set['id']);
125 $this->tpl->setVariable('FINAL_LIMIT', $a_set['final_limit']);
126 }
127 }
128
129 public function parse(array $a_objective_ids): void
130 {
131 $post_self_limits = [];
132 if ($this->http->wrapper()->post()->has('self')) {
133 $post_self_limits = $this->http->wrapper()->post()->retrieve(
134 'self',
135 $this->refinery->kindlyTo()->dictOf(
136 $this->refinery->kindlyTo()->float()
137 )
138 );
139 }
140 $post_final_limits = [];
141 if ($this->http->wrapper()->post()->has('final')) {
142 $post_final_limits = $this->http->wrapper()->post()->retrieve(
143 'final',
144 $this->refinery->kindlyTo()->dictOf(
145 $this->refinery->kindlyTo()->float()
146 )
147 );
148 }
149
150 $objectives = array();
151 foreach ($a_objective_ids as $objective_id) {
152 $objective = new ilCourseObjective($this->course_obj, $objective_id);
153
154 // Self assessment tests
155 $question_obj = new ilCourseObjectiveQuestion($objective_id);
156
157 $tests = array();
158 foreach ($question_obj->getSelfAssessmentTests() as $tmp_test) {
159 if (isset($post_self_limits[$objective_id])) {
160 $objective_data['self_limit'] = (float) $post_self_limits[$objective_id];
161 } else {
162 $objective_data['self_limit'] = $tmp_test['limit'];
163 }
164 $questions = array();
165 foreach ($question_obj->getQuestionsOfTest($tmp_test['obj_id']) as $tmp_question) {
166 $qst['title'] = $tmp_question['title'];
167 $qst['description'] = $tmp_question['description'];
168 $qst['points'] = $tmp_question['points'];
169
170 $questions[] = $qst;
171 }
172 $tst['questions'] = $questions;
173 $tst['title'] = ilObject::_lookupTitle($tmp_test['obj_id']);
174 $tst['description'] = ilObject::_lookupDescription($tmp_test['obj_id']);
175
176 $tests[] = $tst;
177 }
178 $objective_data['self_tests'] = $tests;
179 $objective_data['self_max_points'] = $question_obj->getSelfAssessmentPoints();
180
181 // Final tests
182 $tests = array();
183 foreach ($question_obj->getFinalTests() as $tmp_test) {
184 if (isset($post_final_limits[$objective_id])) {
185 $objective_data['final_limit'] = (float) $post_final_limits[$objective_id];
186 } else {
187 $objective_data['final_limit'] = $tmp_test['limit'];
188 }
189
190 $questions = array();
191 foreach ($question_obj->getQuestionsOfTest($tmp_test['obj_id']) as $tmp_question) {
192 $qst['title'] = $tmp_question['title'];
193 $qst['description'] = $tmp_question['description'];
194 $qst['points'] = $tmp_question['points'];
195
196 $questions[] = $qst;
197 }
198 $tst['questions'] = $questions;
199 $tst['title'] = ilObject::_lookupTitle($tmp_test['obj_id']);
200 $tst['description'] = ilObject::_lookupDescription($tmp_test['obj_id']);
201
202 $tests[] = $tst;
203 }
204
205 $objective_data['final_tests'] = $tests;
206 $objective_data['final_max_points'] = $question_obj->getFinalTestPoints();
207
208 $objective_data['id'] = $objective_id;
209 $objective_data['title'] = $objective->getTitle();
210
211 $objective_data['description'] = $objective->getDescription();
212
213 $objectives[] = $objective_data;
214 }
215 $this->setData($objectives);
216 }
217}
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
class ilcourseobjectiveQuestion
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(object $a_parent_obj, ilObject $a_course_obj)
fillRow(array $a_set)
Standard Version of Fill Row.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setFormName(string $a_name="")
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.
setData(array $a_data)
Set table data.
enable(string $a_module_name)
disable(string $a_module_name)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$objectives