ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilBadgePersonalTableGUI Class Reference
+ Inheritance diagram for ilBadgePersonalTableGUI:
+ Collaboration diagram for ilBadgePersonalTableGUI:

Public Member Functions

 __construct ()
 
 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.g. More...
 
 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...
 
 renderTable ()
 

Protected Member Functions

 getActions (URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
 

Private Member Functions

 getRecords ()
 
 getColumns (\ILIAS\Data\DateFormat\DateFormat $date_format)
 

Private Attributes

readonly Factory $factory
 
readonly Renderer $renderer
 
readonly ServerRequestInterface RequestInterface $request
 
readonly ilLanguage $lng
 
readonly ilGlobalTemplateInterface $tpl
 
readonly ILIAS DI Container $dic
 
readonly ilObjUser $user
 
readonly ilAccessHandler $access
 
readonly Tile $tile
 
array $cached_records = null
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilBadgePersonalTableGUI::__construct ( )

Definition at line 63 of file class.ilBadgePersonalTableGUI.php.

References $DIC, ILIAS\Repository\access(), factory(), ILIAS\Repository\lng(), renderer(), and ILIAS\Repository\user().

64  {
65  global $DIC;
66  $this->dic = $DIC;
67  $this->lng = $DIC->language();
68  $this->tpl = $DIC->ui()->mainTemplate();
69  $this->factory = $DIC->ui()->factory();
70  $this->renderer = $DIC->ui()->renderer();
71  $this->request = $DIC->http()->request();
72  $this->user = $DIC->user();
73  $this->access = $DIC->access();
74  $this->tile = new Tile($DIC);
75  }
factory()
renderer()
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ getActions()

ilBadgePersonalTableGUI::getActions ( URLBuilder  $url_builder,
URLBuilderToken  $action_parameter_token,
URLBuilderToken  $row_id_token 
)
protected
Returns
array<string,>

Definition at line 248 of file class.ilBadgePersonalTableGUI.php.

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

Referenced by renderTable().

252  : array {
253  return [
254  'obj_badge_activate' => $this->factory->table()->action()->multi(
255  $this->lng->txt('badge_add_to_profile'),
256  $url_builder->withParameter($action_parameter_token, 'obj_badge_activate'),
257  $row_id_token
258  ),
259  'obj_badge_deactivate' =>
260  $this->factory->table()->action()->multi(
261  $this->lng->txt('badge_remove_from_profile'),
262  $url_builder->withParameter($action_parameter_token, 'obj_badge_deactivate'),
263  $row_id_token
264  )
265  ];
266  }
factory()
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter&#39;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()

ilBadgePersonalTableGUI::getColumns ( \ILIAS\Data\DateFormat\DateFormat  $date_format)
private
Returns
array<string, Column>

Definition at line 224 of file class.ilBadgePersonalTableGUI.php.

References factory(), and ILIAS\Repository\lng().

Referenced by renderTable().

224  : array
225  {
226  return [
227  'image' => $this->factory->table()->column()->text($this->lng->txt('image'))->withIsSortable(false),
228  'title' => $this->factory->table()->column()->text($this->lng->txt('title')),
229  'awarded_by' => $this->factory->table()->column()->text($this->lng->txt('awarded_by')),
230  'badge_issued_on' => $this->factory->table()->column()->date(
231  $this->lng->txt('badge_issued_on'),
232  $date_format
233  ),
234  'active' => $this->factory->table()->column()->boolean(
235  $this->lng->txt('badge_in_profile'),
236  $this->lng->txt('yes'),
237  $this->lng->txt('no')
238  )->withOrderingLabels(
239  $this->lng->txt('badge_sort_added_to_profile_first'),
240  $this->lng->txt('badge_sort_excluded_from_profile_first')
241  )
242  ];
243  }
factory()
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRecords()

ilBadgePersonalTableGUI::getRecords ( )
private
Returns
list<array{ id: int, active: bool, image: string, awarded_by: string, awarded_by_sortable: string, badge_issued_on: DateTimeImmutable, title: string, title_sortable: string }>

Definition at line 145 of file class.ilBadgePersonalTableGUI.php.

References $cached_records, $ref_id, ilObject\_getAllReferences(), ILIAS\Repository\access(), ilBadgeAssignment\getInstancesByUserId(), ilBadge\getParentMeta(), null, renderer(), and ILIAS\Repository\user().

Referenced by getRows(), and getTotalRowCount().

145  : array
146  {
147  if ($this->cached_records !== null) {
148  return $this->cached_records;
149  }
150 
151  $rows = [];
152  $a_user_id = $this->user->getId();
153 
154  foreach (ilBadgeAssignment::getInstancesByUserId($a_user_id) as $ass) {
155  $badge = new ilBadge($ass->getBadgeId());
156 
157  $parent = null;
158  if ($badge->getParentId()) {
159  $parent = $badge->getParentMeta();
160  if ($parent['type'] === 'bdga') {
161  $parent = null;
162  }
163  }
164 
165  $awarded_by = '';
166  $awarded_by_sortable = '';
167  if ($parent !== null) {
168  $ref_ids = ilObject::_getAllReferences($parent['id']);
169  $ref_id = current($ref_ids);
170 
171  $awarded_by = $parent['title'];
172  $awarded_by_sortable = $parent['title'];
173  if ($ref_id && $this->access->checkAccess('read', '', $ref_id)) {
174  $awarded_by = $this->renderer->render(
175  new Standard(
176  $awarded_by,
177  (string) new URI(ilLink::_getLink($ref_id))
178  )
179  );
180  }
181 
182  $awarded_by = implode(' ', [
183  $this->renderer->render(
184  $this->factory->symbol()->icon()->standard(
185  $parent['type'],
186  $parent['title']
187  )
188  ),
189  $awarded_by
190  ]);
191  }
192 
193  $rows[] = [
194  'id' => $badge->getId(),
195  'image' => $this->renderer->render(
196  $this->tile->asImage(
197  $this->tile->modalContentWithAssignment($badge, $ass),
198  ilBadgeImage::IMAGE_SIZE_XS
199  )
200  ),
201  'title' => $this->renderer->render(
202  $this->tile->asTitle(
203  $this->tile->modalContentWithAssignment($badge, $ass)
204  )
205  ),
206  'title_sortable' => $badge->getTitle(),
207  'badge_issued_on' => (new DateTimeImmutable())
208  ->setTimestamp($ass->getTimestamp())
209  ->setTimezone(new DateTimeZone($this->user->getTimeZone())),
210  'awarded_by' => $awarded_by,
211  'awarded_by_sortable' => $awarded_by_sortable,
212  'active' => (bool) $ass->getPosition()
213  ];
214  }
215 
216  $this->cached_records = $rows;
217 
218  return $rows;
219  }
static getInstancesByUserId(int $a_user_id)
static _getAllReferences(int $id)
get all reference ids for object ID
renderer()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRows()

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

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

Parameters
string[]$visible_column_ids

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 77 of file class.ilBadgePersonalTableGUI.php.

References ILIAS\UI\Component\Table\DataRowBuilder\buildDataRow(), ILIAS\Data\Range\getLength(), getRecords(), ILIAS\Data\Range\getStart(), ILIAS\Data\Order\join(), and ilStr\strCmp().

84  : Generator {
85  $records = $this->getRecords();
86 
87  if ($order) {
88  [$order_field, $order_direction] = $order->join(
89  [],
90  fn($ret, $key, $value) => [$key, $value]
91  );
92 
93  usort($records, static function (array $left, array $right) use ($order_field): int {
94  if (in_array($order_field, ['title', 'awarded_by'], true)) {
95  if (in_array($order_field, ['title', 'awarded_by'], true)) {
96  $order_field .= '_sortable';
97  }
98 
99  return ilStr::strCmp(
100  $left[$order_field],
101  $right[$order_field]
102  );
103  }
104 
105  if ($order_field === 'active') {
106  return $right[$order_field] <=> $left[$order_field];
107  }
108 
109  return $left[$order_field] <=> $right[$order_field];
110  });
111 
112  if ($order_direction === Order::DESC) {
113  $records = array_reverse($records);
114  }
115  }
116 
117  if ($range) {
118  $records = \array_slice($records, $range->getStart(), $range->getLength());
119  }
120 
121  foreach ($records as $record) {
122  yield $row_builder->buildDataRow((string) $record['id'], $record);
123  }
124  }
join($init, callable $fn)
Definition: Order.php:75
buildDataRow(string $id, array $record)
static strCmp(string $a, string $b)
Definition: class.ilStr.php:90
+ Here is the call graph for this function:

◆ getTotalRowCount()

ilBadgePersonalTableGUI::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 126 of file class.ilBadgePersonalTableGUI.php.

References getRecords().

129  : ?int {
130  return count($this->getRecords());
131  }
+ Here is the call graph for this function:

◆ renderTable()

ilBadgePersonalTableGUI::renderTable ( )

Definition at line 268 of file class.ilBadgePersonalTableGUI.php.

References factory(), getActions(), getColumns(), ILIAS\Repository\lng(), renderer(), ilCalendarSettings\TIME_FORMAT_12, and ILIAS\Repository\user().

268  : void
269  {
270  $df = new \ILIAS\Data\Factory();
271  if ((int) $this->user->getTimeFormat() === ilCalendarSettings::TIME_FORMAT_12) {
272  $date_format = $df->dateFormat()->withTime12($this->user->getDateFormat());
273  } else {
274  $date_format = $df->dateFormat()->withTime24($this->user->getDateFormat());
275  }
276 
277  $table_uri = $df->uri($this->request->getUri()->__toString());
278  $url_builder = new URLBuilder($table_uri);
279  $query_params_namespace = ['badge'];
280 
281  [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
282  $query_params_namespace,
283  'table_action',
284  'id',
285  );
286 
287  $table = $this->factory
288  ->table()
289  ->data(
290  $this,
291  $this->lng->txt('badge_personal_badges'),
292  $this->getColumns($date_format),
293  )
294  ->withId(self::class)
295  ->withOrder(new Order('title', Order::ASC))
296  ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
297  ->withRequest($this->request);
298 
299  $pres = new PresentationHeader($this->dic, ilBadgeProfileGUI::class);
300  $pres->show($this->lng->txt('table_view'));
301 
302  $this->tpl->setContent($this->renderer->render($table));
303  }
factory()
renderer()
getColumns(\ILIAS\Data\DateFormat\DateFormat $date_format)
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:

Field Documentation

◆ $access

readonly ilAccessHandler ilBadgePersonalTableGUI::$access
private

Definition at line 47 of file class.ilBadgePersonalTableGUI.php.

◆ $cached_records

array ilBadgePersonalTableGUI::$cached_records = null
private
Returns
null|list<array{ id: int, active: bool, image: string, awarded_by: string, awarded_by_sortable: string, badge_issued_on: DateTimeImmutable, title: string, title_sortable: string }>

Definition at line 61 of file class.ilBadgePersonalTableGUI.php.

Referenced by getRecords().

◆ $dic

readonly ILIAS DI Container ilBadgePersonalTableGUI::$dic
private

Definition at line 45 of file class.ilBadgePersonalTableGUI.php.

◆ $factory

readonly Factory ilBadgePersonalTableGUI::$factory
private

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

◆ $lng

readonly ilLanguage ilBadgePersonalTableGUI::$lng
private

Definition at line 43 of file class.ilBadgePersonalTableGUI.php.

◆ $renderer

readonly Renderer ilBadgePersonalTableGUI::$renderer
private

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

◆ $request

readonly ServerRequestInterface RequestInterface ilBadgePersonalTableGUI::$request
private

Definition at line 42 of file class.ilBadgePersonalTableGUI.php.

◆ $tile

readonly Tile ilBadgePersonalTableGUI::$tile
private

Definition at line 48 of file class.ilBadgePersonalTableGUI.php.

◆ $tpl

readonly ilGlobalTemplateInterface ilBadgePersonalTableGUI::$tpl
private

Definition at line 44 of file class.ilBadgePersonalTableGUI.php.

◆ $user

readonly ilObjUser ilBadgePersonalTableGUI::$user
private

Definition at line 46 of file class.ilBadgePersonalTableGUI.php.


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