19declare(strict_types=1);
28use Psr\Http\Message\ServerRequestInterface;
42 private readonly ServerRequestInterface $http_request,
44 private readonly UIFactory $ui_factory,
45 private readonly Uri $table_uri,
47 private readonly
bool $read_only =
false,
54 array $visible_column_ids,
57 mixed $additional_viewcontrol_data,
59 mixed $additional_parameters
63 yield $row_builder->buildDataRow($record[
'tpl_id'], $record)
65 'setAsContextDefault',
66 isset($record[
'is_default']) && $record[
'is_default']
69 'unsetAsContextDefault',
70 !isset($record[
'is_default']) || !$record[
'is_default']
77 if ($this->records ===
null) {
79 foreach ($this->service->listAllTemplatesAsArray() as $item) {
81 'tpl_id' => (string) $item[
'tpl_id'],
82 'title' => $item[
'title'],
83 'context' => $this->getContext($item[
'context'], $item[
'is_default'] ??
false),
84 'is_default' => $item[
'is_default'] ??
false,
92 $query_params_namespace = [
'mail',
'template'];
93 $url_builder =
new URLBuilder($this->table_uri);
94 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
95 $query_params_namespace,
100 return $this->ui_factory->table()
103 $this->
lng->txt(
'mail_templates'),
106 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
110 ->withOrder(
new Order(
'title', Order::ASC))
111 ->withRequest($this->http_request);
114 public function getContext(
string $value,
bool $default =
false): string
116 if (isset($this->contexts[$value])) {
117 $is_default_suffix =
'';
119 $is_default_suffix = $this->
lng->txt(
'mail_template_default');
123 $this->contexts[$value]->
getTitle(),
128 return $this->
lng->txt(
'mail_template_orphaned_context');
132 mixed $additional_viewcontrol_data,
134 mixed $additional_parameters
136 $this->initRecords();
138 return count((array) $this->records);
146 $this->initRecords();
147 $records = $this->records;
150 $records = $this->orderRecords($records, $order);
154 $records = $this->limitRecords($records,
$range);
166 if ($this->contexts !== []) {
167 $actions[
'edit'] = $this->ui_factory->table()->action()->single(
168 $this->
lng->txt(
'edit'),
169 $url_builder->
withParameter($action_parameter_token,
'showEditTemplateForm'),
173 $actions[
'view'] = $this->ui_factory->table()->action()->single(
174 $this->
lng->txt(
'view'),
175 $url_builder->
withParameter($action_parameter_token,
'showEditTemplateForm'),
180 if (!$this->read_only) {
181 $actions[
'delete'] = $this->ui_factory->table()->action()->standard(
182 $this->
lng->txt(
'delete'),
183 $url_builder->
withParameter($action_parameter_token,
'confirmDeleteTemplate'),
188 $actions[
'unsetAsContextDefault'] = $this->ui_factory->table()->action()->single(
189 $this->
lng->txt(
'mail_template_unset_as_default'),
190 $url_builder->
withParameter($action_parameter_token,
'unsetAsContextDefault'),
194 $actions[
'setAsContextDefault'] = $this->ui_factory->table()->action()->single(
195 $this->
lng->txt(
'mail_template_set_as_default'),
196 $url_builder->
withParameter($action_parameter_token,
'setAsContextDefault'),
218 [$order_field, $order_direction] = $order->
join(
220 fn($ret, $key, $value) => [$key, $value]
222 usort($records,
static fn(array $left, array $right):
int =>
ilStr::strCmp(
223 $left[$order_field] ??
'',
224 $right[$order_field] ??
''
227 if ($order_direction === Order::DESC) {
228 $records = array_reverse($records);
243 'title' => $this->ui_factory->table()->column()
244 ->text($this->
lng->txt(
'title')),
245 'context' => $this->ui_factory->table()->column()
246 ->text($this->
lng->txt(
'mail_template_context'))
Builds a Color from either hex- or rgb values.
Both the subject and the direction need to be specified when expressing an order.
join($init, callable $fn)
A simple class to express a naive range of whole positive numbers.
The scope of this class is split ilias-conform URI's into components.
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id.
getRecords(Range $range, Order $order)
getRows(ILIAS\UI\Component\Table\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....
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...
orderRecords(array $records, Order $order)
__construct(private readonly ServerRequestInterface $http_request, private readonly ilLanguage $lng, private readonly UIFactory $ui_factory, private readonly Uri $table_uri, private readonly ilMailTemplateService $service, private readonly bool $read_only=false,)
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
limitRecords(array $records, Range $range)
getContext(string $value, bool $default=false)
static strCmp(string $a, string $b)
This describes a Data Table.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.