ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ?array $filter_data,
57 ?array $additional_parameters
58 ): Generator {
59 $ref_ids = $this->getAllEligibleRefIDs();
60
61 $assigned = $this->grouping->getAssignedItems();
62 $assigned_ref_ids = [];
63 foreach ($assigned as $item) {
64 $assigned_ref_ids[] = $item['target_ref_id'];
65 }
66
67 $ok_icon = $this->ui_factory->symbol()->icon()->custom(
68 'assets/images/standard/icon_ok.svg',
69 $this->lng->txt('assigned')
70 );
71
72 $records = [];
73 foreach ($ref_ids as $ref_id) {
74 $record = [
76 AssignmentHandler::COL_PATH => $this->buildPath($ref_id),
77 ];
78 if (in_array($ref_id->toInt(), $assigned_ref_ids)) {
79 $record[AssignmentHandler::COL_ASSIGNED] = $ok_icon;
80 }
81 $records[$ref_id->toInt()] = $record;
82 }
83
84 $records = $this->sortRecords($records, $order);
85 $records = array_slice($records, $range->getStart(), $range->getLength(), true);
86
87 foreach ($records as $ref_id => $record) {
88 yield $row_builder->buildDataRow((string) $ref_id, $record);
89 }
90 }
91
92 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
93 {
94 return count($this->getAllEligibleRefIDs());
95 }
96
100 public function getAllEligibleRefIDs(): array
101 {
102 $type = ilObject::_lookupType($this->content_obj_id);
103 $item_ref_ids = ilUtil::_getObjectsByOperations(
104 $type,
105 'write',
106 $this->user->getId(),
107 -1
108 );
109
110 $filtered_ref_ids = [];
111 foreach ($item_ref_ids as $item_ref_id) {
112 if ($this->tree->checkForParentType($item_ref_id, 'adm')) {
113 continue;
114 }
115 $filtered_ref_ids[] = $this->data_factory->refId($item_ref_id);
116 }
117 return $filtered_ref_ids;
118 }
119
120 protected function buildPath(ReferenceId $ref_id): string
121 {
122 $titles = [];
123 foreach ($this->tree->getPathFull($ref_id->toInt()) as $step) {
124 $titles[] = $step['title'];
125 }
126 return implode(' > ', $titles);
127 }
128
129 protected function sortRecords(array $records, Order $order): array
130 {
131 $order_field = array_keys($order->get())[0] ?? AssignmentHandler::COL_TITLE;
132 $order_direction = $order->get()[$order_field] ?? Order::ASC;
133
134 $ordering_callable_without_direction = match ($order_field) {
136 fn($a, $b) => $a[$order_field] ?? '' <=> $b[$order_field] ?? '',
138 fn($a, $b) => isset($a[$order_field]) <=> isset($b[$order_field])
139 };
140 $ordering_callable = fn($a, $b) => $order_direction === Order::ASC ?
141 $ordering_callable_without_direction($a, $b) :
142 $ordering_callable_without_direction($b, $a);
143
144 uasort($records, $ordering_callable);
145 return $records;
146 }
147}
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
This is called by the table to retrieve rows; map data-records to rows using the $row_builder e....
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...
__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,...
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