ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilDidacticTemplateSettingsTableDataRetrieval.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25use ILIAS\UI\Factory as UIFactory;
26use ILIAS\UI\Renderer as UIRenderer;
28use ILIAS\StaticURL\Services as StaticURLService;
29use ILIAS\Data\Factory as DataFactory;
30
32{
34 protected ilLanguage $lng;
35 protected UIFactory $ui_factory;
36 protected UIRenderer $ui_renderer;
37 protected StaticURLService $static_url;
38 protected DataFactory $data_factory;
39
40 public function __construct(
43 UIFactory $ui_factory,
44 UIRenderer $ui_renderer,
45 StaticURLService $static_url,
46 DataFactory $data_factory
47 ) {
48 $this->filter = $filter;
49 $this->lng = $lng;
50 $this->ui_factory = $ui_factory;
51 $this->ui_renderer = $ui_renderer;
52 $this->static_url = $static_url;
53 $this->data_factory = $data_factory;
54 }
55
56 public function getRows(
57 DataRowBuilder $row_builder,
58 array $visible_column_ids,
60 Order $order,
61 mixed $additional_viewcontrol_data,
62 mixed $filter_data,
63 mixed $additional_parameters
64 ): Generator {
65 $records = $this->getRecords($order, $range);
66 foreach ($records as $record) {
67 $row = $row_builder->buildDataRow((string) $record['template_id'], $record);
68 if ($record['automatically_generated']) {
69 $row = $row->withDisabledAction('didactic_do_export');
70 }
71 yield $row;
72 }
73 }
74
75 public function getTotalRowCount(
76 mixed $additional_viewcontrol_data,
77 mixed $filter_data,
78 mixed $additional_parameters
79 ): ?int {
80 return count($this->getTemplates());
81 }
82
86 protected function getTemplates(): array
87 {
89 $tpls->readInactive();
90 return $this->filter->filter($tpls->getTemplates());
91 }
92
93 protected function getRecords(Order $order, Range $range): array
94 {
95 $records = [];
96 foreach ($this->getTemplates() as $tpl) {
97 /* @var $tpl ilDidacticTemplateSetting */
98 $atxt = '';
99 foreach ($tpl->getAssignments() as $obj_type) {
100 $atxt .= ($this->lng->txt('objs_' . $obj_type) . '<br/>');
101 }
102 $title_desc = $tpl->getPresentationTitle()
103 . "<br><br>"
104 . $tpl->getPresentationDescription()
105 . (trim($tpl->getInfo()) ? "<br><br>" . $tpl->getInfo() : '')
106 . ($tpl->isAutoGenerated() ? "<br><br>" . $this->lng->txt("didactic_auto_generated") : '');
107
108 $scope_str = '';
109 if (count($tpl->getEffectiveFrom()) > 0) {
110 $scope_str .= $this->lng->txt('didactic_scope_list_header');
111 foreach ($tpl->getEffectiveFrom() as $ref_id) {
112 $link = $this->ui_renderer->render($this->ui_factory->link()->standard(
114 (string) $this->static_url->builder()->build(
116 $this->data_factory->refId($ref_id)
117 )
118 ));
119 $scope_str .= "<br>";
120 $scope_str .= $link;
121 }
122 } else {
123 $scope_str .= (isset($a_set['local']) ? $this->lng->txt('meta_local') : $this->lng->txt('meta_global'));
124 }
125 $scope_str .= "<br>";
126
127 $icon_label = '';
128 $icon_path = $tpl->getIconHandler()->getAbsolutePath();
129 foreach ($tpl->getAssignments() as $obj_type) {
130 $icon_label = $this->lng->txt('objs_' . $obj_type);
131 }
132 if ($icon_path) {
133 $icon = $this->ui_factory->symbol()->icon()->custom(
134 $icon_path,
135 $icon_label
136 );
137 }
138
139 $icon_active = $this->ui_factory->symbol()->icon()->custom(
140 $tpl->isEnabled() ?
141 ilUtil::getImagePath('standard/icon_ok.svg') :
142 ilUtil::getImagePath('standard/icon_not_ok.svg'),
143 $tpl->isEnabled() ? $this->lng->txt('active') : $this->lng->txt('inactive'),
144 Icon::MEDIUM
145 );
146
147 $record = [
148 'template_id' => $tpl->getId(),
149 'title' => $title_desc,
150 'applicable' => $atxt,
151 'scope' => $scope_str,
152 'enabled' => $icon_active,
153 'automatically_generated' => $tpl->isAutoGenerated()
154 ];
155 if (isset($icon)) {
156 $record['icon'] = $icon;
157 }
158 $records[] = $record;
159 }
160 list($order_field, $order_direction) = $order->join([], fn($ret, $key, $value) => [$key, $value]);
161 usort($records, fn($a, $b) => $a[$order_field] <=> $b[$order_field]);
162 if (
163 $order_direction === 'DESC'
164 ) {
165 $records = array_reverse($records);
166 }
167 $selected_records = array_slice(
168 $records,
169 $range->getStart(),
171 );
172 return $selected_records;
173 }
174}
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
join($init, callable $fn)
Definition: Order.php:75
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
Class Services.
Definition: Services.php:38
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(ilDidacticTemplateSettingsTableFilter $filter, ilLanguage $lng, UIFactory $ui_factory, UIRenderer $ui_renderer, StaticURLService $static_url, DataFactory $data_factory)
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....
language handling
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes how an icon could be modified during construction of UI.
Definition: Icon.php:29
buildDataRow(string $id, array $record)
An entity that renders components to a string output.
Definition: Renderer.php:31
$ref_id
Definition: ltiauth.php:66
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples