ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
AssignmentRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use Generator;
28use ilUtil;
29use ilObject;
30use ilObjUser;
31use ilTree;
32use ILIAS\Data\Factory as DataFactory;
34use ILIAS\UI\Factory as UIFactory;
35use ilLanguage;
37
39{
40 public function __construct(
41 protected int $content_obj_id,
42 protected ilObjCourseGrouping $grouping,
43 protected ilObjUser $user,
44 protected ilTree $tree,
45 protected UIFactory $ui_factory,
46 protected ilLanguage $lng,
47 protected DataFactory $data_factory
48 ) {
49 }
50
51 public function getRows(
52 DataRowBuilder $row_builder,
53 array $visible_column_ids,
55 Order $order,
56 mixed $additional_viewcontrol_data,
57 mixed $filter_data,
58 mixed $additional_parameters
59 ): Generator {
60 $ref_ids = $this->getAllEligibleRefIDs();
61
62 $assigned = $this->grouping->getAssignedItems();
63 $assigned_ref_ids = [];
64 foreach ($assigned as $item) {
65 $assigned_ref_ids[] = $item['target_ref_id'];
66 }
67
68 $ok_icon = $this->ui_factory->symbol()->icon()->custom(
69 'assets/images/standard/icon_ok.svg',
70 $this->lng->txt('assigned')
71 );
72
73 $records = [];
74 foreach ($ref_ids as $ref_id) {
75 $record = [
77 AssignmentHandler::COL_PATH => $this->buildPath($ref_id),
78 ];
79 if (in_array($ref_id->toInt(), $assigned_ref_ids)) {
80 $record[AssignmentHandler::COL_ASSIGNED] = $ok_icon;
81 }
82 $records[$ref_id->toInt()] = $record;
83 }
84
85 $records = $this->sortRecords($records, $order);
86 $records = array_slice($records, $range->getStart(), $range->getLength(), true);
87
88 foreach ($records as $ref_id => $record) {
89 yield $row_builder->buildDataRow((string) $ref_id, $record);
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->getAllEligibleRefIDs());
99 }
100
104 public function getAllEligibleRefIDs(): array
105 {
106 $type = ilObject::_lookupType($this->content_obj_id);
107 $item_ref_ids = ilUtil::_getObjectsByOperations(
108 $type,
109 'write',
110 $this->user->getId(),
111 -1
112 );
113
114 $filtered_ref_ids = [];
115 foreach ($item_ref_ids as $item_ref_id) {
116 if ($this->tree->checkForParentType($item_ref_id, 'adm')) {
117 continue;
118 }
119 $filtered_ref_ids[] = $this->data_factory->refId($item_ref_id);
120 }
121 return $filtered_ref_ids;
122 }
123
124 protected function buildPath(ReferenceId $ref_id): string
125 {
126 $titles = [];
127 foreach ($this->tree->getPathFull($ref_id->toInt()) as $step) {
128 $titles[] = $step['title'];
129 }
130 return implode(' > ', $titles);
131 }
132
133 protected function sortRecords(array $records, Order $order): array
134 {
135 $order_field = array_keys($order->get())[0] ?? AssignmentHandler::COL_TITLE;
136 $order_direction = $order->get()[$order_field] ?? Order::ASC;
137
138 $ordering_callable_without_direction = match ($order_field) {
139 AssignmentHandler::COL_TITLE, AssignmentHandler::COL_PATH =>
140 fn($a, $b) => ($a[$order_field] ?? '') <=> ($b[$order_field] ?? ''),
141 AssignmentHandler::COL_ASSIGNED =>
142 fn($a, $b) => isset($a[$order_field]) <=> isset($b[$order_field])
143 };
144 $ordering_callable = fn($a, $b) => $order_direction === Order::ASC ?
145 $ordering_callable_without_direction($a, $b) :
146 $ordering_callable_without_direction($b, $a);
147
148 uasort($records, $ordering_callable);
149 return $records;
150 }
151}
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...
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
__construct(protected int $content_obj_id, protected ilObjCourseGrouping $grouping, protected ilObjUser $user, protected ilTree $tree, protected UIFactory $ui_factory, protected ilLanguage $lng, protected DataFactory $data_factory)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
language handling
Class ilObj<module_name>
User class.
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Util class various functions, usage as namespace.
static _getObjectsByOperations( $a_obj_type, string $a_operation, int $a_usr_id=0, int $limit=0)
Get all objects of a specific type and check access This function is not recursive,...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildDataRow(string $id, array $record)
$ref_id
Definition: ltiauth.php:66
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $lng
Definition: privfeed.php:31