ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilMailTemplateTable Class Reference
+ Inheritance diagram for ilMailTemplateTable:
+ Collaboration diagram for ilMailTemplateTable:

Public Member Functions

 __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,)
 
 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.g. More...
 
 initRecords ()
 
 getComponent ()
 
 getContext (string $value, bool $default=false)
 
 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...
 
 getActions (URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
 
 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...
 

Protected Attributes

array $contexts = []
 

Private Member Functions

 getRecords (Range $range, Order $order)
 
 limitRecords (array $records, Range $range)
 
 orderRecords (array $records, Order $order)
 
 getColumns ()
 

Private Attributes

array $records = null
 

Detailed Description

Definition at line 33 of file class.ilMailTemplateTable.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateTable::__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 
)

Definition at line 41 of file class.ilMailTemplateTable.php.

48 {
50 }
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id.

References ilMailTemplateContextService\getTemplateContexts().

+ Here is the call graph for this function:

Member Function Documentation

◆ getActions()

ilMailTemplateTable::getActions ( URLBuilder  $url_builder,
URLBuilderToken  $action_parameter_token,
URLBuilderToken  $row_id_token 
)
Returns
Action[]

Definition at line 163 of file class.ilMailTemplateTable.php.

163 : array
164 {
165 $actions = [];
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'),
170 $row_id_token
171 );
172 } else {
173 $actions['view'] = $this->ui_factory->table()->action()->single(
174 $this->lng->txt('view'),
175 $url_builder->withParameter($action_parameter_token, 'showEditTemplateForm'),
176 $row_id_token
177 );
178 }
179
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'),
184 $row_id_token
185 );
186 }
187
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'),
191 $row_id_token
192 );
193
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'),
197 $row_id_token
198 );
199
200 return $actions;
201 }
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166

References ILIAS\Repository\lng(), and ILIAS\UI\URLBuilder\withParameter().

+ Here is the call graph for this function:

◆ getColumns()

ilMailTemplateTable::getColumns ( )
private
Returns
array{ title: \ILIAS\UI\Component\Table\Column\Text, context: \ILIAS\UI\Component\Table\Column\Text }

Definition at line 240 of file class.ilMailTemplateTable.php.

240 : array
241 {
242 return [
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'))
247 ];
248 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getComponent()

ilMailTemplateTable::getComponent ( )

Definition at line 90 of file class.ilMailTemplateTable.php.

90 : DataTable
91 {
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,
96 'table_action',
97 'tpl_ids'
98 );
99
100 return $this->ui_factory->table()
101 ->data(
102 $this,
103 $this->lng->txt('mail_templates'),
104 $this->getColumns()
105 )
106 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
107 ->withId(
108 'mail_man_tpl'
109 )
110 ->withOrder(new Order('title', Order::ASC))
111 ->withRequest($this->http_request);
112 }
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getContext()

ilMailTemplateTable::getContext ( string  $value,
bool  $default = false 
)

Definition at line 114 of file class.ilMailTemplateTable.php.

114 : string
115 {
116 if (isset($this->contexts[$value])) {
117 $is_default_suffix = '';
118 if ($default) {
119 $is_default_suffix = $this->lng->txt('mail_template_default');
120 }
121
122 return implode('', [
123 $this->contexts[$value]->getTitle(),
124 $is_default_suffix,
125 ]);
126 }
127
128 return $this->lng->txt('mail_template_orphaned_context');
129 }

References ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getRecords()

ilMailTemplateTable::getRecords ( Range  $range,
Order  $order 
)
private
Returns
list<array{tpl_id: int, title: string, context: string, is_default: bool}>

Definition at line 144 of file class.ilMailTemplateTable.php.

144 : array
145 {
146 $this->initRecords();
148
149 if ($order) {
150 $records = $this->orderRecords($records, $order);
151 }
152
153 if ($range) {
154 $records = $this->limitRecords($records, $range);
155 }
156
157 return $records;
158 }
orderRecords(array $records, Order $order)
limitRecords(array $records, Range $range)

References ILIAS\UI\Implementation\Component\Table\$range.

◆ getRows()

ilMailTemplateTable::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.g.

yield $row_builder->buildStandardRow($row_id, $record).

Parameters
string[]$visible_column_ids

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 52 of file class.ilMailTemplateTable.php.

60 : Generator {
61 $records = $this->getRecords($range, $order);
62 foreach ($records as $record) {
63 yield $row_builder->buildDataRow($record['tpl_id'], $record)
64 ->withDisabledAction(
65 'setAsContextDefault',
66 isset($record['is_default']) && $record['is_default']
67 )
68 ->withDisabledAction(
69 'unsetAsContextDefault',
70 !isset($record['is_default']) || !$record['is_default']
71 );
72 }
73 }
getRecords(Range $range, Order $order)

◆ getTotalRowCount()

ilMailTemplateTable::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 131 of file class.ilMailTemplateTable.php.

135 : ?int {
136 $this->initRecords();
137
138 return count((array) $this->records);
139 }

◆ initRecords()

ilMailTemplateTable::initRecords ( )

Definition at line 75 of file class.ilMailTemplateTable.php.

75 : void
76 {
77 if ($this->records === null) {
78 $this->records = [];
79 foreach ($this->service->listAllTemplatesAsArray() as $item) {
80 $this->records[] = [
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,
85 ];
86 }
87 }
88 }
getContext(string $value, bool $default=false)

◆ limitRecords()

ilMailTemplateTable::limitRecords ( array  $records,
Range  $range 
)
private
Parameters
list<array{tpl_idint, title: string, context: string, is_default: bool}> $records
Returns
list<array{tpl_id: int, title: string, context: string, is_default: bool}>

Definition at line 207 of file class.ilMailTemplateTable.php.

207 : array
208 {
209 return array_slice($records, $range->getStart(), $range->getLength());
210 }

References ILIAS\UI\Implementation\Component\Table\$range, ILIAS\Data\Range\getLength(), and ILIAS\Data\Range\getStart().

+ Here is the call graph for this function:

◆ orderRecords()

ilMailTemplateTable::orderRecords ( array  $records,
Order  $order 
)
private
Parameters
list<array{tpl_idint, title: string, context: string, is_default: bool}> $records
Returns
list<array{tpl_id: int, title: string, context: string, is_default: bool}>

Definition at line 216 of file class.ilMailTemplateTable.php.

216 : array
217 {
218 [$order_field, $order_direction] = $order->join(
219 [],
220 fn($ret, $key, $value) => [$key, $value]
221 );
222 usort($records, static fn(array $left, array $right): int => ilStr::strCmp(
223 $left[$order_field] ?? '',
224 $right[$order_field] ?? ''
225 ));
226
227 if ($order_direction === Order::DESC) {
228 $records = array_reverse($records);
229 }
230
231 return $records;
232 }
join($init, callable $fn)
Definition: Order.php:75
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87

References ILIAS\Data\Order\join(), and ilStr\strCmp().

+ Here is the call graph for this function:

Field Documentation

◆ $contexts

array ilMailTemplateTable::$contexts = []
protected

Definition at line 36 of file class.ilMailTemplateTable.php.

◆ $records

array ilMailTemplateTable::$records = null
private

Definition at line 39 of file class.ilMailTemplateTable.php.


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