ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ConditionTriggerProvider.php
Go to the documentation of this file.
1<?php
2
20
25use ILIAS\UI\Factory as UIFactory;
26use ilObject;
28use ilLanguage;
30
32{
33 private int $target_ref_id;
34 private int $target_obj_id;
35 private string $target_type;
36
37 private array $data = [];
38
39 private StaticURL\Services $static_url_service;
40 private UIFactory $ui_factory;
41
43
44
45 public function __construct(int $target_ref_id, int $target_obj_id, string $target_type)
46 {
47 global $DIC;
48
49 $this->static_url_service = $DIC['static_url'];
50 $this->ui_factory = $DIC->ui()->factory();
51 $this->lng = $DIC->language();
52 $this->lng->loadLanguageModule('rbac');
53
54 $this->target_ref_id = $target_ref_id;
55 $this->target_obj_id = $target_obj_id;
56 $this->target_type = $target_type;
57 $this->read();
58 }
59
60 protected function read(): void
61 {
63 $this->target_ref_id,
64 $this->target_obj_id,
65 $this->target_type
66 );
67
68 foreach ($conditions as $condition) {
69 $row = [];
70 $row['id'] = $condition['id'];
71
72 $link = $this->static_url_service->builder()->build(
73 ilObject::_lookupType($condition['trigger_ref_id'], true),
74 new ReferenceId($condition['trigger_ref_id'])
75 );
76 $row['trigger'] = $this->ui_factory->link()->standard(
77 ilObject::_lookupTitle($condition['trigger_obj_id']),
78 $link
79 );
81 $condition['trigger_obj_id'],
82 $condition['operator'],
83 $condition['value']
84 );
85
86 if ($condition['obligatory']) {
87 $row['obligatory'] = $this->ui_factory->symbol()->icon()->custom(
88 'assets/images/standard/icon_checked.svg',
89 '',
90 'small'
91 );
92 }
93 $this->data[] = $row;
94 }
95 }
96
97 public function getData(): array
98 {
99 return $this->data;
100 }
101
102 public function sortData(Order $order): array
103 {
104 $data = $this->getData();
105 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
106 usort($data, fn($a, $b) => $a[$order_field] <=> $b[$order_field]);
107 if ($order_direction === 'DESC') {
108 $data = array_reverse($data);
109 }
110 return $data;
111 }
112
113 public function limitData(Range $range, Order $order): array
114 {
115 return array_slice($this->sortData($order), $range->getStart(), $range->getLength());
116 }
117
118}
__construct(int $target_ref_id, int $target_obj_id, string $target_type)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
join($init, callable $fn)
Definition: Order.php:75
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
class ilConditionHandlerGUI
static translateOperator(int $a_obj_id, string $a_operator, string $value='')
INTERNAL CLASS: Please do not use in consumer code.
static _getPersistedConditionsOfTarget(int $a_target_ref_id, int $a_target_obj_id, string $a_target_type="")
get all persisted conditions of target object
language handling
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26