ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ConditionTriggerProvider.php
Go to the documentation of this file.
1 <?php
2 
4 
10 use ilObject;
12 use ilLanguage;
14 
16 {
17  private int $target_ref_id;
18  private int $target_obj_id;
19  private string $target_type;
20 
21  private array $data = [];
22 
23  private StaticURL\Services $static_url_service;
25 
26  private ilLanguage $lng;
27 
28 
29  public function __construct(int $target_ref_id, int $target_obj_id, string $target_type)
30  {
31  global $DIC;
32 
33  $this->static_url_service = $DIC['static_url'];
34  $this->ui_factory = $DIC->ui()->factory();
35  $this->lng = $DIC->language();
36  $this->lng->loadLanguageModule('rbac');
37 
38  $this->target_ref_id = $target_ref_id;
39  $this->target_obj_id = $target_obj_id;
40  $this->target_type = $target_type;
41  $this->read();
42  }
43 
44  protected function read(): void
45  {
47  $this->target_ref_id,
48  $this->target_obj_id,
49  $this->target_type
50  );
51 
52  foreach ($conditions as $condition) {
53  $row = [];
54  $row['id'] = $condition['id'];
55 
56  $link = $this->static_url_service->builder()->build(
57  ilObject::_lookupType($condition['trigger_ref_id'], true),
58  new ReferenceId($condition['trigger_ref_id'])
59  );
60  $row['trigger'] = $this->ui_factory->link()->standard(
61  ilObject::_lookupTitle($condition['trigger_obj_id']),
62  $link
63  );
64  $row['condition'] = ilConditionHandlerGUI::translateOperator(
65  $condition['trigger_obj_id'],
66  $condition['operator'],
67  $condition['value']
68  );
69 
70  if ($condition['obligatory']) {
71  $row['obligatory'] = $this->ui_factory->symbol()->icon()->custom(
72  'assets/images/standard/icon_checked.svg',
73  '',
74  'small'
75  );
76  }
77  $this->data[] = $row;
78  }
79  }
80 
81  public function getData(): array
82  {
83  return $this->data;
84  }
85 
86  public function sortData(Order $order): array
87  {
88  $data = $this->getData();
89  [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
90  usort($data, fn($a, $b) => $a[$order_field] <=> $b[$order_field]);
91  if ($order_direction === 'DESC') {
92  $data = array_reverse($data);
93  }
94  return $data;
95  }
96 
97  public function limitData(Range $range, Order $order): array
98  {
99  return array_slice($this->sortData($order), $range->getStart(), $range->getLength());
100  }
101 
102 }
__construct(int $target_ref_id, int $target_obj_id, string $target_type)
join($init, callable $fn)
Definition: Order.php:59
static translateOperator(int $a_obj_id, string $a_operator, string $value='')
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupTitle(int $obj_id)
global $DIC
Definition: shib_login.php:25
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
static _lookupType(int $id, bool $reference=false)
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:28
static _getPersistedConditionsOfTarget(int $a_target_ref_id, int $a_target_obj_id, string $a_target_type="")
get all persisted conditions of target object