ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
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 DataFactory $data_factory, 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, ?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.g. More...
 
 initRecords ()
 
 getComponent ()
 
 getContext (string $value, bool $default=false)
 
 getTotalRowCount (?array $filter_data, ?array $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)
 

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 32 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 DataFactory  $data_factory,
private readonly ilMailTemplateService  $service,
private readonly bool  $read_only = false 
)

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

References ilMailTemplateContextService\getTemplateContexts().

47  {
49  }
static getTemplateContexts(?array $a_id=null)
Returns an array of mail template contexts, the key of each entry matches its id. ...
+ 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 159 of file class.ilMailTemplateTable.php.

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

Referenced by getComponent().

159  : array
160  {
161  $actions = [];
162  if ($this->contexts !== []) {
163  $actions['edit'] = $this->ui_factory->table()->action()->single(
164  $this->lng->txt('edit'),
165  $url_builder->withParameter($action_parameter_token, 'showEditTemplateForm'),
166  $row_id_token
167  );
168  } else {
169  $actions['view'] = $this->ui_factory->table()->action()->single(
170  $this->lng->txt('view'),
171  $url_builder->withParameter($action_parameter_token, 'showEditTemplateForm'),
172  $row_id_token
173  );
174  }
175 
176  if (!$this->read_only) {
177  $actions['delete'] = $this->ui_factory->table()->action()->standard(
178  $this->lng->txt('delete'),
179  $url_builder->withParameter($action_parameter_token, 'confirmDeleteTemplate'),
180  $row_id_token
181  );
182  }
183 
184  $actions['unsetAsContextDefault'] = $this->ui_factory->table()->action()->single(
185  $this->lng->txt('mail_template_unset_as_default'),
186  $url_builder->withParameter($action_parameter_token, 'unsetAsContextDefault'),
187  $row_id_token
188  );
189 
190  $actions['setAsContextDefault'] = $this->ui_factory->table()->action()->single(
191  $this->lng->txt('mail_template_set_as_default'),
192  $url_builder->withParameter($action_parameter_token, 'setAsContextDefault'),
193  $row_id_token
194  );
195 
196  return $actions;
197  }
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getColumns()

ilMailTemplateTable::getColumns ( )
private
Returns
array{ title: , context: }

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

References ILIAS\Repository\lng().

Referenced by getComponent().

236  : array
237  {
238  return [
239  'title' => $this->ui_factory->table()->column()
240  ->text($this->lng->txt('title')),
241  'context' => $this->ui_factory->table()->column()
242  ->text($this->lng->txt('mail_template_context'))
243  ];
244  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getComponent()

ilMailTemplateTable::getComponent ( )

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

References getActions(), getColumns(), and ILIAS\Repository\lng().

88  : DataTable
89  {
90  $query_params_namespace = ['mail', 'template'];
91  $table_uri = $this->data_factory->uri($this->http_request->getUri()->__toString());
92  $url_builder = new URLBuilder($table_uri);
93  [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
94  $query_params_namespace,
95  'table_action',
96  'tpl_ids'
97  );
98 
99  return $this->ui_factory->table()
100  ->data(
101  $this,
102  $this->lng->txt('mail_templates'),
103  $this->getColumns()
104  )
105  ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
106  ->withId(
107  'mail_man_tpl'
108  )
109  ->withOrder(new Order('title', Order::ASC))
110  ->withRequest($this->http_request);
111  }
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:28
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
URLBuilder.
Definition: URLBuilder.php:40
+ Here is the call graph for this function:

◆ getContext()

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

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

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

Referenced by initRecords().

113  : string
114  {
115  if (isset($this->contexts[$value])) {
116  $is_default_suffix = '';
117  if ($default) {
118  $is_default_suffix = $this->lng->txt('mail_template_default');
119  }
120 
121  return implode('', [
122  $this->contexts[$value]->getTitle(),
123  $is_default_suffix,
124  ]);
125  }
126 
127  return $this->lng->txt('mail_template_orphaned_context');
128  }
+ Here is the call graph for this function:
+ Here is the caller 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 140 of file class.ilMailTemplateTable.php.

References $records, initRecords(), limitRecords(), and orderRecords().

Referenced by getRows().

140  : array
141  {
142  $this->initRecords();
144 
145  if ($order) {
146  $records = $this->orderRecords($records, $order);
147  }
148 
149  if ($range) {
150  $records = $this->limitRecords($records, $range);
151  }
152 
153  return $records;
154  }
limitRecords(array $records, Range $range)
orderRecords(array $records, Order $order)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRows()

ilMailTemplateTable::getRows ( ILIAS\UI\Component\Table\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.g.

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

Parameters
string[]$visible_column_ids

Implements ILIAS\UI\Component\Table\DataRetrieval.

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

References getRecords().

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

◆ getTotalRowCount()

ilMailTemplateTable::getTotalRowCount ( ?array  $filter_data,
?array  $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 130 of file class.ilMailTemplateTable.php.

References initRecords().

130  : ?int
131  {
132  $this->initRecords();
133 
134  return count((array) $this->records);
135  }
+ Here is the call graph for this function:

◆ initRecords()

ilMailTemplateTable::initRecords ( )

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

References getContext(), and null.

Referenced by getRecords(), and getTotalRowCount().

73  : void
74  {
75  if ($this->records === null) {
76  $this->records = [];
77  foreach ($this->service->listAllTemplatesAsArray() as $item) {
78  $this->records[] = [
79  'tpl_id' => (string) $item['tpl_id'],
80  'title' => $item['title'],
81  'context' => $this->getContext($item['context'], $item['is_default'] ?? false),
82  'is_default' => $item['is_default'] ?? false,
83  ];
84  }
85  }
86  }
getContext(string $value, bool $default=false)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 203 of file class.ilMailTemplateTable.php.

References ILIAS\Data\Range\getLength(), and ILIAS\Data\Range\getStart().

Referenced by getRecords().

203  : array
204  {
205  return array_slice($records, $range->getStart(), $range->getLength());
206  }
+ Here is the call graph for this function:
+ Here is the caller 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 212 of file class.ilMailTemplateTable.php.

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

Referenced by getRecords().

212  : array
213  {
214  [$order_field, $order_direction] = $order->join(
215  [],
216  fn($ret, $key, $value) => [$key, $value]
217  );
218  usort($records, static fn(array $left, array $right): int => ilStr::strCmp(
219  $left[$order_field] ?? '',
220  $right[$order_field] ?? ''
221  ));
222 
223  if ($order_direction === Order::DESC) {
224  $records = array_reverse($records);
225  }
226 
227  return $records;
228  }
join($init, callable $fn)
Definition: Order.php:75
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $contexts

array ilMailTemplateTable::$contexts = []
protected

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

◆ $records

array ilMailTemplateTable::$records = null
private

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

Referenced by getRecords(), and orderRecords().


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