ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
ILIAS\File\Versions\Table\DataRetrieval Class Reference
+ Inheritance diagram for ILIAS\File\Versions\Table\DataRetrieval:
+ Collaboration diagram for ILIAS\File\Versions\Table\DataRetrieval:

Public Member Functions

 __construct (private readonly \ilObjFile $file, private readonly int $current_version, private readonly bool $current_version_is_draft, private readonly int $amount_of_versions, private readonly \ilCtrlInterface $ctrl, private readonly \ilFileVersionsGUI $parent_gui, private readonly \ilLanguage $lng, private readonly UIFactory $ui_factory)
 
 getRows (I\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, 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 records available. More...
 
- Public Member Functions inherited from ILIAS\UI\Component\Table\DataRetrieval
 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.g. More...
 
 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 records available. More...
 

Data Fields

const string ACTION_DELETE = 'delete'
 
const string ACTION_ROLLBACK = 'rollback'
 
const string ACTION_PUBLISH = 'publish'
 
const string ACTION_UNPUBLISH = 'unpublish'
 

Private Member Functions

 getRecords (Order $order)
 
 mapRecord (array $record)
 

Detailed Description

Definition at line 29 of file DataRetrieval.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\File\Versions\Table\DataRetrieval::__construct ( private readonly \ilObjFile  $file,
private readonly int  $current_version,
private readonly bool  $current_version_is_draft,
private readonly int  $amount_of_versions,
private readonly \ilCtrlInterface  $ctrl,
private readonly \ilFileVersionsGUI  $parent_gui,
private readonly \ilLanguage  $lng,
private readonly UIFactory  $ui_factory 
)

Definition at line 36 of file DataRetrieval.php.

45 {
46 }

Member Function Documentation

◆ getRecords()

ILIAS\File\Versions\Table\DataRetrieval::getRecords ( Order  $order)
private
Returns
array<int, array<string, mixed>>

Definition at line 94 of file DataRetrieval.php.

94 : array
95 {
96 $records = [];
97 foreach ($this->file->getVersions() as $version) {
98 $records[] = $version->getArrayCopy();
99 }
100
101 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value): array => [$key, $value]);
102 if ($order_field === 'version') {
103 usort($records, static fn(array $a, array $b): int => (int) $a['version'] <=> (int) $b['version']);
104 } else {
105 usort($records, static fn(array $a, array $b): int => ($a[$order_field] ?? null) <=> ($b[$order_field] ?? null));
106 }
107 if ($order_direction === 'DESC') {
108 $records = array_reverse($records);
109 }
110 return $records;
111 }
$version
Definition: plugin.php:24
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, Vendor\Package\$b, $version, and ILIAS\Data\Order\join().

+ Here is the call graph for this function:

◆ getRows()

ILIAS\File\Versions\Table\DataRetrieval::getRows ( I\DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

Definition at line 48 of file DataRetrieval.php.

56 : \Generator {
57 $records = $this->getRecords($order);
58 foreach ($records as $record) {
59 $row_id = (string) $record['hist_entry_id'];
60 $version_number = (int) $record['version'];
61 $is_current = $version_number === $this->current_version;
62
63 yield $row_builder->buildDataRow($row_id, $this->mapRecord($record))
64 ->withDisabledAction(
65 self::ACTION_DELETE,
66 $this->current_version_is_draft
67 )
68 ->withDisabledAction(
69 self::ACTION_ROLLBACK,
70 $this->current_version_is_draft || $is_current
71 )
72 ->withDisabledAction(
73 self::ACTION_PUBLISH,
74 !($this->current_version_is_draft && $is_current)
75 )
76 ->withDisabledAction(
77 self::ACTION_UNPUBLISH,
78 $this->current_version_is_draft || !$is_current || $this->amount_of_versions <= 1
79 );
80 }
81 }

References ILIAS\Repository\int(), and ILIAS\File\Versions\Table\DataRetrieval\mapRecord().

+ Here is the call graph for this function:

◆ getTotalRowCount()

ILIAS\File\Versions\Table\DataRetrieval::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 records available.

Given the nature of a DataTable, which is, opposite to a PresentationTable, rather administrative than explorative, this information will increase user experience quite a bit. However, you may return null, if the call is to costly, but expect the View Control to look a little different in this case.

Make sure that potential filters or user restrictions are being applied to the count.

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 83 of file DataRetrieval.php.

87 : ?int {
88 return count($this->file->getVersions());
89 }

◆ mapRecord()

ILIAS\File\Versions\Table\DataRetrieval::mapRecord ( array  $record)
private
Parameters
array<string,mixed>$record
Returns
array<string, mixed>

Definition at line 117 of file DataRetrieval.php.

117 : array
118 {
119 $hist_id = (int) $record['hist_entry_id'];
120
121 $name = \ilObjUser::_lookupName((int) $record['user_id']);
122 $username = trim(($name['title'] ?? '') . ' ' . ($name['firstname'] ?? '') . ' ' . ($name['lastname'] ?? ''));
123
124 $action_label = $this->lng->txt('file_version_' . $record['action']);
125 if ($record['action'] === 'rollback') {
126 $rollback_name = \ilObjUser::_lookupName((int) $record['rollback_user_id']);
127 $rollback_username = trim(
128 ($rollback_name['title'] ?? '') . ' ' .
129 ($rollback_name['firstname'] ?? '') . ' ' .
130 ($rollback_name['lastname'] ?? '')
131 );
132 $action_label = sprintf($action_label, $record['rollback_version'], $rollback_username);
133 }
134
135 $this->ctrl->setParameter($this->parent_gui, \ilFileVersionsGUI::HIST_ID, $hist_id);
136 $download_url = $this->ctrl->getLinkTarget($this->parent_gui, \ilFileVersionsGUI::CMD_DOWNLOAD_VERSION);
137 $this->ctrl->setParameter($this->parent_gui, \ilFileVersionsGUI::HIST_ID, '');
138
139 $filename_link = $this->ui_factory->link()->standard((string) $record['filename'], $download_url);
140
141 $size = new DataSize((int) ($record['size'] ?? 0), DataSize::KB);
142
143 return [
144 'version' => (int) $record['version'],
145 'filename' => $filename_link,
146 'date' => new \DateTimeImmutable((string) $record['date']),
147 'uploaded_by' => $username,
148 'versionname' => (string) ($record['title'] ?? ''),
149 'filesize' => (string) $size,
150 'status' => $action_label,
151 ];
152 }
static _lookupName(int $a_user_id)

References ilObjUser\_lookupName(), ilFileVersionsGUI\CMD_DOWNLOAD_VERSION, ILIAS\Repository\ctrl(), ilFileVersionsGUI\HIST_ID, ILIAS\Repository\int(), and ILIAS\Repository\lng().

Referenced by ILIAS\File\Versions\Table\DataRetrieval\getRows().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ ACTION_DELETE

const string ILIAS\File\Versions\Table\DataRetrieval::ACTION_DELETE = 'delete'

Definition at line 31 of file DataRetrieval.php.

Referenced by ILIAS\File\Versions\Table\Table\initActions().

◆ ACTION_PUBLISH

const string ILIAS\File\Versions\Table\DataRetrieval::ACTION_PUBLISH = 'publish'

Definition at line 33 of file DataRetrieval.php.

Referenced by ILIAS\File\Versions\Table\Table\initActions().

◆ ACTION_ROLLBACK

const string ILIAS\File\Versions\Table\DataRetrieval::ACTION_ROLLBACK = 'rollback'

Definition at line 32 of file DataRetrieval.php.

Referenced by ILIAS\File\Versions\Table\Table\initActions().

◆ ACTION_UNPUBLISH

const string ILIAS\File\Versions\Table\DataRetrieval::ACTION_UNPUBLISH = 'unpublish'

Definition at line 34 of file DataRetrieval.php.

Referenced by ILIAS\File\Versions\Table\Table\initActions().


The documentation for this class was generated from the following file: