ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
SkillsByQuestionOverviewTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use ILIAS\UI\Factory as UIFactory;
27
29{
30 public const string VIEW_CONTROL_QUERY_PARAM = 'mode';
31
32 private const string ROW_ID_PARAMETER = 'q_id';
33
34 public function __construct(
35 private readonly \ilAssQuestionList $question_list,
36 private readonly \ilAssQuestionSkillAssignmentList $assignment_list,
37 private readonly UIFactory $ui_factory,
38 private readonly \ilLanguage $lng,
39 private readonly \ilCtrl $ctrl
40 ) {
41 }
42
43 public function getComponents(URI $edit_uri, SkillAssignmentViewControlMode $skill_assignment_view_control_mode = SkillAssignmentViewControlMode::ALL): array
44 {
45 return [
46 $this->ui_factory->table()->presentation(
47 $this->lng->txt('qpl_skl_sub_tab_quest_assign'),
48 $this->getViewControls($skill_assignment_view_control_mode),
49 fn(PresentationRow $row, SkillAssignments $record): PresentationRow => $this->mapRow($row, $record, $edit_uri)
50 )
51 ->withData($this->retrieveRecords($skill_assignment_view_control_mode))
52 ];
53 }
54
55 private function mapRow(PresentationRow $row, SkillAssignments $record, URI $edit_uri): PresentationRow
56 {
57 $assignment_details = [];
58 foreach ($record->getSkillAssignments() as $skill_assignment) {
59 $assignment_details[$skill_assignment->getSkillTitle()] = $this->ui_factory
60 ->listing()
61 ->property()
62 ->withProperty($this->lng->txt('tree'), $skill_assignment->getSkillPath())
63 ->withProperty(
64 $this->lng->txt('tst_comp_eval_mode'),
65 $this->lng->txt(
66 $skill_assignment->hasEvalModeBySolution()
67 ? 'qpl_skill_point_eval_mode_solution_compare'
68 : 'qpl_skill_point_eval_mode_quest_result'
69 )
70 )
71 ->withProperty($this->lng->txt('tst_comp_points'), (string) $skill_assignment->getMaxSkillPoints());
72 }
73
74 $row = $row
75 ->withHeadline($record->getQuestion()['title'])
76 ->withSubheadline($record->getQuestion()['description'])
77 ->withLeadingSymbol(
78 $this->ui_factory->symbol()->icon()->standard('ques', '')
79 )
80 ->withContent(
81 $assignment_details !== []
82 ? $this->ui_factory->listing()->descriptive($assignment_details)
83 : $this->ui_factory->legacy()->content($this->lng->txt('ui_table_no_records'))
84 )
85 ->withAction(
86 $this->ui_factory->button()->standard(
87 $this->lng->txt('tst_manage_competence_assigns'),
88 (string) $edit_uri->withParameter(self::ROW_ID_PARAMETER, $record->getQuestion()['question_id'])
89 )
90 );
91
92 $assignments = $this->assignment_list->getAssignmentsByQuestionId($record->getQuestion()['question_id']);
93 if ($assignments === []) {
94 return $row;
95 }
96
97 return $row->withImportantFields([
98 $this->lng->txt('tst_competence') => implode(
99 ', ',
100 array_map(static fn(\ilAssQuestionSkillAssignment $a) => $a->getSkillTitle(), $assignments)
101 ),
102 ]);
103 }
104
108 public function retrieveRecords(SkillAssignmentViewControlMode $skill_assignment_view_control_mode = SkillAssignmentViewControlMode::ALL): array
109 {
110 $records = [];
111 foreach ($this->question_list->getQuestionDataArray() as $question_id => $question_data) {
112 $assignments_by_question_id = $this->assignment_list->getAssignmentsByQuestionId($question_id);
113 if (
114 $skill_assignment_view_control_mode === SkillAssignmentViewControlMode::ASSIGNED
115 && $assignments_by_question_id === []
116 ) {
117 continue;
118 }
119
120 if (
121 $skill_assignment_view_control_mode === SkillAssignmentViewControlMode::UNASSIGNED
122 && $assignments_by_question_id !== []
123 ) {
124 continue;
125 }
126
127 $records[] = new SkillAssignments($question_data, $assignments_by_question_id);
128 }
129
130 return $records;
131 }
132
136 private function getViewControls(SkillAssignmentViewControlMode $skill_assignment_view_control_mode = SkillAssignmentViewControlMode::ALL): array
137 {
138 $labeled_actions = [];
139 foreach (SkillAssignmentViewControlMode::cases() as $value) {
140 $this->ctrl->setParameterByClass(
141 \ilAssQuestionSkillAssignmentsGUI::class,
142 self::VIEW_CONTROL_QUERY_PARAM,
143 $value->value
144 );
145 $labeled_actions[$this->lng->txt($value->getLabel())] = $this->ctrl->getLinkTargetByClass(
146 \ilAssQuestionSkillAssignmentsGUI::class,
148 );
149 }
150
151 return [
152 $this->ui_factory->viewControl()->mode($labeled_actions, $this->lng->txt('qpl_skl_view_control_mode_aria'))
153 ->withActive($this->lng->txt($skill_assignment_view_control_mode->getLabel())),
154 ];
155 }
156}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
withParameter(string $key, $value)
Get URI with modified parameters.
Definition: URI.php:387
getComponents(URI $edit_uri, SkillAssignmentViewControlMode $skill_assignment_view_control_mode=SkillAssignmentViewControlMode::ALL)
__construct(private readonly \ilAssQuestionList $question_list, private readonly \ilAssQuestionSkillAssignmentList $assignment_list, private readonly UIFactory $ui_factory, private readonly \ilLanguage $lng, private readonly \ilCtrl $ctrl)
retrieveRecords(SkillAssignmentViewControlMode $skill_assignment_view_control_mode=SkillAssignmentViewControlMode::ALL)
mapRow(PresentationRow $row, SkillAssignments $record, URI $edit_uri)
getViewControls(SkillAssignmentViewControlMode $skill_assignment_view_control_mode=SkillAssignmentViewControlMode::ALL)
Class ilCtrl provides processing control methods.
language handling
@ ALL
event string being used if
This describes a Row used in Presentation Table.
withImportantFields(array $fields)
Get a row like this with the record-fields and labels to be shown in the collapsed row.
withHeadline(string $headline)
Get a row like this with the given headline.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $lng
Definition: privfeed.php:31