18 declare(strict_types=1);
52 private readonly \ILIAS\ResourceStorage\Services
$irss;
68 public function __construct(
int $parent_obj_id,
string $parent_obj_type,
protected bool $has_write =
false)
72 $this->
lng = $DIC->language();
73 $this->tpl = $DIC->ui()->mainTemplate();
74 $this->factory = $DIC->ui()->factory();
75 $this->renderer = $DIC->ui()->renderer();
77 $this->request = $DIC->http()->request();
78 $this->
http = $DIC->http();
79 $this->irss = $DIC->resourceStorage();
81 $this->parent_id = $parent_obj_id;
82 $this->parent_type = $parent_obj_type;
86 $DIC->ui()->mainTemplate()
102 if ($this->cached_records !== null) {
109 'id' => $badge->getId(),
111 'active' => $badge->isActive(),
112 'type' => $this->parent_type !==
'bdga' 114 : $badge->getTypeInstance()->getCaption(),
115 'manual' => !$badge->getTypeInstance() instanceof
ilBadgeAuto,
116 'title_sortable' => $badge->getTitle()
120 $this->cached_records = $rows;
147 $badge = $record[
'badge'];
154 $image_src = $this->badge_image_service->getImageFromBadge($badge);
155 if ($image_src !==
'') {
156 $images[
'rendered'] = $this->renderer->render(
157 $this->factory->image()->responsive(
163 $image_src_large = $this->badge_image_service->getImageFromBadge(
167 if ($image_src_large !==
'') {
168 $images[
'large'] = $this->factory->image()->responsive(
179 'description' => $badge->getDescription(),
180 'badge_criteria' => $badge->getCriteria(),
184 $record[
'image'] = $images[
'rendered']
187 $record[
'title'] = implode(
'', [
197 DataRowBuilder $row_builder,
198 array $visible_column_ids,
202 ?array $additional_parameters
207 [$order_field, $order_direction] = $order->join(
209 fn($ret, $key, $value) => [$key, $value]
212 usort($records,
static function (array $left, array $right) use ($order_field):
int {
213 if (\in_array($order_field, [
'title',
'type'],
true)) {
214 if ($order_field ===
'title') {
215 $order_field .=
'_sortable';
218 return \ilStr::strCmp(
224 if ($order_field ===
'active') {
225 return $right[$order_field] <=> $left[$order_field];
228 return $left[$order_field] <=> $right[$order_field];
232 $records = array_reverse($records);
237 $records = \array_slice($records, $range->getStart(), $range->getLength());
240 $identifications = [];
241 foreach ($records as $record) {
242 if ($record[
'badge']->getImageRid() !== null && $record[
'badge']->getImageRid() !==
'') {
243 $identifications[] = $record[
'badge']->getImageRid();
247 $this->irss->preload($identifications);
250 foreach ($records as $record) {
251 $record = $this->
enrichRecord($modal_container, $record);
254 ->buildDataRow((
string) $record[
'id'], $record)
255 ->withDisabledAction(
256 'award_revoke_badge',
257 !$record[
'manual'] || !$record[
'active']
264 ?array $additional_parameters
275 'image' => $this->factory->table()->column()->text($this->
lng->txt(
'image'))->withIsSortable(
false),
276 'title' => $this->factory->table()->column()->text($this->
lng->txt(
'title')),
277 'type' => $this->factory->table()->column()->text($this->
lng->txt(
'type')),
278 'active' => $this->factory->table()->column()->boolean(
279 $this->
lng->txt(
'active'),
280 $this->
lng->txt(
'yes'),
281 $this->
lng->txt(
'no')
282 )->withOrderingLabels(
283 $this->
lng->txt(
'badge_sort_active_badges_first'),
284 $this->
lng->txt(
'badge_sort_active_badges_last')
293 URLBuilder $url_builder,
294 URLBuilderToken $action_parameter_token,
295 URLBuilderToken $row_id_token,
297 return $this->has_write ? [
298 'badge_table_activate' =>
299 $this->factory->table()->action()->multi(
300 $this->
lng->txt(
'activate'),
301 $url_builder->withParameter($action_parameter_token,
'badge_table_activate'),
304 'badge_table_deactivate' =>
305 $this->factory->table()->action()->multi(
306 $this->
lng->txt(
'deactivate'),
307 $url_builder->withParameter($action_parameter_token,
'badge_table_deactivate'),
310 'badge_table_edit' => $this->factory->table()->action()->single(
311 $this->
lng->txt(
'edit'),
312 $url_builder->withParameter($action_parameter_token,
'badge_table_edit'),
315 'badge_table_delete' =>
316 $this->factory->table()->action()->standard(
317 $this->
lng->txt(
'delete'),
318 $url_builder->withParameter($action_parameter_token,
'badge_table_delete'),
321 'award_revoke_badge' =>
322 $this->factory->table()->action()->single(
323 $this->
lng->txt(
'badge_award_revoke'),
324 $url_builder->withParameter($action_parameter_token,
'award_revoke_badge'),
332 $df = new \ILIAS\Data\Factory();
334 $table_uri = $df->uri($url);
335 $url_builder =
new URLBuilder($table_uri);
336 $query_params_namespace = [
'tid'];
338 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
339 $query_params_namespace,
344 $table = $this->factory
346 ->data($this->
lng->txt(
'obj_bdga'), $this->
getColumns(), $this)
347 ->withId(self::class .
'_' . $this->parent_id)
349 ->withActions($this->
getActions($url_builder, $action_parameter_token, $row_id_token))
350 ->withRequest($this->request);
353 $query = $this->
http->wrapper()->query();
355 if ($query->has($action_parameter_token->getName())) {
356 $action = $query->retrieve($action_parameter_token->getName(), $this->
refinery->to()->string());
357 $ids = $query->retrieve($row_id_token->getName(), $this->
refinery->custom()->transformation(fn($v) => $v));
359 if ($action ===
'delete') {
361 foreach ($ids as
$id) {
362 $items[] = $this->factory->modal()->interruptiveItem()->keyValue(
364 $row_id_token->getName(),
369 $this->
http->saveResponse(
374 $this->factory->modal()->interruptive(
375 $this->
lng->txt(
'badge_deletion'),
376 $this->
lng->txt(
'badge_deletion_confirmation'),
378 )->withAffectedItems($items)
382 $this->
http->sendResponse();
383 $this->
http->close();
387 $this->tpl->setContent($this->renderer->render(
$out));
constructModal(?Image $badge_image, string $badge_title, array $badge_properties=[])
readonly ilGlobalTemplateInterface $tpl
readonly Renderer $renderer
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token,)
renderModal(Modal $modal)
__construct(int $parent_obj_id, string $parent_obj_type, protected bool $has_write=false)
readonly ILIAS Refinery Factory $refinery
readonly ilBadgeImage $badge_image_service
readonly string $parent_type
static http()
Fetches the global http state from ILIAS.
static getExtendedTypeCaption(ilBadgeType $a_type)
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...
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
static getInstancesByParentId(int $a_parent_id, array $a_filter=null)
readonly Factory $factory
static ofString(string $string)
Creates a new stream with an initial value.
readonly ServerRequestInterface RequestInterface $request
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
enrichRecord(ModalBuilder $modal_builder, array $record)
renderShyButton(string $label, Modal $modal)
readonly ILIAS ResourceStorage Services $irss