ILIAS  trunk Revision v12.0_alpha-16-g3e876e53c80
class.ilLOTestAssignmentTableDataRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
21use ILIAS\UI\Component\Table\DataRetrieval as ilTableDataRetrievalInterface;
22use ILIAS\DI\UIServices as ilUIServices;
23
24class ilLOTestAssignmentTableDataRetrieval implements ilTableDataRetrievalInterface
25{
26 protected array $data;
27
28 public function __construct(
29 protected ilLanguage $lng,
30 protected ilDBInterface $db,
31 protected ilUIServices $ui_services,
32 protected ilCtrl $ctrl,
33 protected int $assignment_type
34 ) {
35 }
36
37 public function getRows(
38 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
39 array $visible_column_ids,
40 \ILIAS\Data\Range $range,
41 \ILIAS\Data\Order $order,
42 mixed $additional_viewcontrol_data,
43 mixed $filter_data,
44 mixed $additional_parameters
45 ): Generator {
46 [$column_name, $direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
48 uasort($this->data, function ($a, $b) {
49 return strcmp($a['title'], $b['title']);
50 });
51 }
52 if ($direction === 'DESC') {
53 $rows = array_reverse($this->data);
54 } else {
55 $rows = $this->data;
56 }
57 foreach ($rows as $row) {
59 ? $row['assignment_id']
60 : $row['ref_id'];
61 $type = '';
62 switch ($row['ttype']) {
64 $type = $this->lng->txt('tst_question_set_type_fixed');
65 break;
66
68 $type = $this->lng->txt('tst_question_set_type_random');
69 break;
70 }
71 $this->ctrl->setParameterByClass('ilobjtestgui', 'ref_id', $row['ref_id']);
72 $this->ctrl->setParameterByClass('ilobjtestgui', 'cmd', 'questionsTabGateway');
73 $title_link = $this->ui_services->factory()->link()->standard($row['title'], $this->ctrl->getLinkTargetByClass('ilobjtestgui'));
74 $data = [];
76 if ($this->assignment_type === ilLOTestAssignmentTableGUI::TYPE_MULTIPLE_ASSIGNMENTS) {
78 }
81
82 if (isset($row['qpls']) && count($row['qpls']) > 0) {
83 $data[ilLOTestAssignmentTableGUI::TABLE_COL_QESTIONS] .= '<br>' . implode('<br>', $row['qpls']);
84 }
85
86 yield $row_builder->buildDataRow(
87 $id . '',
88 $data
89 );
90 }
91 }
92
93 public function getTotalRowCount(
94 mixed $additional_viewcontrol_data,
95 mixed $filter_data,
96 mixed $additional_parameters
97 ): ?int {
98 return count($this->data);
99 }
100
101 protected function doParse(
102 int $a_tst_ref_id,
103 int $a_objective_id = 0
104 ): array {
105 $tst = ilObjectFactory::getInstanceByRefId($a_tst_ref_id, false);
106 if (!$tst instanceof ilObjTest) {
107 throw new ilLOInvalidConfigurationException('No valid test given');
108 }
109 $tst_data['ref_id'] = $tst->getRefId();
110 $tst_data['title'] = $tst->getTitle();
111 $tst_data['description'] = $tst->getLongDescription();
112 $tst_data['ttype'] = $tst->getQuestionSetType();
113 if ($this->assignment_type == ilLOTestAssignmentTableGUI::TYPE_MULTIPLE_ASSIGNMENTS) {
114 $tst_data['objective'] = ilCourseObjective::lookupObjectiveTitle($a_objective_id);
115 }
116 switch ($tst->getQuestionSetType()) {
118 $tst_data['qst_info'] = $this->lng->txt('crs_loc_tst_num_qst');
119 $tst_data['qst_info'] .= (' ' . count($tst->getAllQuestions()));
120 break;
121 default:
122 // get available assiged question pools
124 $GLOBALS['DIC']['ilDB'],
125 $tst,
127 $GLOBALS['DIC']['ilDB'],
128 $tst
129 )
130 );
131 $list->loadDefinitions();
132 // tax translations
133 $translator = new ilTestQuestionFilterLabelTranslator($this->db, $this->lng);
134 $translator->loadLabels($list);
135 $tst_data['qst_info'] = $this->lng->txt('crs_loc_tst_qpls');
136 $num = 0;
137 foreach ($list as $definition) {
138 $title = $definition->getPoolTitle();
139 $filterTitle = [];
140 $filterTitle[] = $translator->getTaxonomyFilterLabel($definition->getMappedTaxonomyFilter());
141 $filterTitle[] = $translator->getTypeFilterLabel($definition->getTypeFilter());
142 if (!empty($filterTitle)) {
143 $title .= ' -> ' . implode(' / ', $filterTitle);
144 }
145 $tst_data['qpls'][] = $title;
146 ++$num;
147 }
148 if ($num === 0) {
149 $tst_data['qst_info'] .= (' ' . 0);
150 }
151 break;
152 }
153 return $tst_data;
154 }
155
156 public function parseSingleAssignment(
157 int $a_tst_ref_id,
158 int $a_objective_id = 0
159 ): void {
160 $this->data = [$this->doParse($a_tst_ref_id, $a_objective_id)];
161 }
162
164 int $container_id,
165 int $test_type
166 ): void {
167 $assignments = ilLOTestAssignments::getInstance($container_id);
168 $available = $assignments->getAssignmentsByType($test_type);
169 $data = [];
170 foreach ($available as $assignment) {
171 try {
172 $tmp = $this->doParse($assignment->getTestRefId(), $assignment->getObjectiveId());
174 $assignment->delete();
175 continue;
176 }
177 if ($tmp !== []) {
178 // add assignment id
179 $tmp['assignment_id'] = $assignment->getAssignmentId();
180 $data[] = $tmp;
181 }
182 }
183 $this->data = $data;
184 }
185
186 public function allIds(): array
187 {
188 $ids = [];
189 foreach ($this->data as $assignment) {
191 ? $assignment['assignment_id']
192 : $assignment['ref_id'];
193 $ids[] = $id;
194 }
195 return $ids;
196 }
197}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parseSingleAssignment(int $a_tst_ref_id, int $a_objective_id=0)
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, \ILIAS\Data\Range $range, \ILIAS\Data\Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
getTotalRowCount(mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
__construct(protected ilLanguage $lng, protected ilDBInterface $db, protected ilUIServices $ui_services, protected ilCtrl $ctrl, protected int $assignment_type)
Settings for LO courses.
getAssignmentsByType(int $a_type)
Get assignments by type.
language handling
const QUESTION_SET_TYPE_RANDOM
const QUESTION_SET_TYPE_FIXED
Class ilObjectFactory This class offers methods to get instances of the type-specific object classes ...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $lng
Definition: privfeed.php:31
$GLOBALS["DIC"]
Definition: wac.php:54