ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ?array $filter_data,
62 ?array $additional_parameters
63 ): Generator {
64 $records = $this->getRecords($order, $range);
65 foreach ($records as $record) {
66 $row = $row_builder->buildDataRow((string) $record['template_id'], $record);
67 if ($record['automatically_generated']) {
68 $row = $row->withDisabledAction('didactic_do_export');
69 }
70 yield $row;
71 }
72 }
73
74 public function getTotalRowCount(
75 ?array $filter_data,
76 ?array $additional_parameters
77 ): ?int {
78 return count($this->getTemplates());
79 }
80
84 protected function getTemplates(): array
85 {
87 $tpls->readInactive();
88 return $this->filter->filter($tpls->getTemplates());
89 }
90
91 protected function getRecords(Order $order, Range $range): array
92 {
93 $records = [];
94 foreach ($this->getTemplates() as $tpl) {
95 /* @var $tpl ilDidacticTemplateSetting */
96 $atxt = '';
97 foreach ($tpl->getAssignments() as $obj_type) {
98 $atxt .= ($this->lng->txt('objs_' . $obj_type) . '<br/>');
99 }
100 $title_desc = $tpl->getPresentationTitle()
101 . "<br><br>"
102 . $tpl->getPresentationDescription()
103 . (trim($tpl->getInfo()) ? "<br><br>" . $tpl->getInfo() : '')
104 . ($tpl->isAutoGenerated() ? "<br><br>" . $this->lng->txt("didactic_auto_generated") : '');
105
106 $scope_str = '';
107 if (count($tpl->getEffectiveFrom()) > 0) {
108 $scope_str .= $this->lng->txt('didactic_scope_list_header');
109 foreach ($tpl->getEffectiveFrom() as $ref_id) {
110 $link = $this->ui_renderer->render($this->ui_factory->link()->standard(
112 (string) $this->static_url->builder()->build(
114 $this->data_factory->refId($ref_id)
115 )
116 ));
117 $scope_str .= "<br>";
118 $scope_str .= $link;
119 }
120 } else {
121 $scope_str .= (isset($a_set['local']) ? $this->lng->txt('meta_local') : $this->lng->txt('meta_global'));
122 }
123 $scope_str .= "<br>";
124
125 $icon_label = '';
126 $icon_path = $tpl->getIconHandler()->getAbsolutePath();
127 foreach ($tpl->getAssignments() as $obj_type) {
128 $icon_label = $this->lng->txt('objs_' . $obj_type);
129 }
130 if ($icon_path) {
131 $icon = $this->ui_factory->symbol()->icon()->custom(
132 $icon_path,
133 $icon_label
134 );
135 }
136
137 $icon_active = $this->ui_factory->symbol()->icon()->custom(
138 $tpl->isEnabled() ?
139 ilUtil::getImagePath('standard/icon_ok.svg') :
140 ilUtil::getImagePath('standard/icon_not_ok.svg'),
141 $tpl->isEnabled() ? $this->lng->txt('active') : $this->lng->txt('inactive'),
142 Icon::MEDIUM
143 );
144
145 $record = [
146 'template_id' => $tpl->getId(),
147 'title' => $title_desc,
148 'applicable' => $atxt,
149 'scope' => $scope_str,
150 'enabled' => $icon_active,
151 'automatically_generated' => $tpl->isAutoGenerated()
152 ];
153 if (isset($icon)) {
154 $record['icon'] = $icon;
155 }
156 $records[] = $record;
157 }
158 list($order_field, $order_direction) = $order->join([], fn($ret, $key, $value) => [$key, $value]);
159 usort($records, fn($a, $b) => $a[$order_field] <=> $b[$order_field]);
160 if (
161 $order_direction === 'DESC'
162 ) {
163 $records = array_reverse($records);
164 }
165 $selected_records = array_slice(
166 $records,
167 $range->getStart(),
169 );
170 return $selected_records;
171 }
172}
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
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(ilDidacticTemplateSettingsTableFilter $filter, ilLanguage $lng, UIFactory $ui_factory, UIRenderer $ui_renderer, StaticURLService $static_url, DataFactory $data_factory)
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, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples