ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilDidacticTemplateSettingsTableDataRetrieval.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 
30 {
32  protected ilLanguage $lng;
35 
36  public function __construct(
38  ilLanguage $lng,
39  UIFactory $ui_factory,
40  UIRenderer $ui_renderer,
41  ) {
42  $this->filter = $filter;
43  $this->lng = $lng;
44  $this->ui_factory = $ui_factory;
45  $this->ui_renderer = $ui_renderer;
46  }
47 
48  public function getRows(
49  DataRowBuilder $row_builder,
50  array $visible_column_ids,
51  Range $range,
52  Order $order,
53  ?array $filter_data,
54  ?array $additional_parameters
55  ): Generator {
56  $records = $this->getRecords($order, $range);
57  foreach ($records as $record) {
58  $row = $row_builder->buildDataRow((string) $record['template_id'], $record);
59  if ($record['automatically_generated']) {
60  $row = $row->withDisabledAction('didactic_do_export');
61  }
62  yield $row;
63  }
64  }
65 
66  public function getTotalRowCount(
67  ?array $filter_data,
68  ?array $additional_parameters
69  ): ?int {
70  return count($this->getTemplates());
71  }
72 
76  protected function getTemplates(): array
77  {
79  $tpls->readInactive();
80  return $this->filter->filter($tpls->getTemplates());
81  }
82 
83  protected function getRecords(Order $order, Range $range): array
84  {
85  $records = [];
86  foreach ($this->getTemplates() as $tpl) {
87  /* @var $tpl ilDidacticTemplateSetting */
88  $atxt = '';
89  foreach ($tpl->getAssignments() as $obj_type) {
90  $atxt .= ($this->lng->txt('objs_' . $obj_type) . '<br/>');
91  }
92  $title_desc = $tpl->getPresentationTitle()
93  . "<br><br>"
94  . $tpl->getPresentationDescription()
95  . (trim($tpl->getInfo()) ? "<br><br>" . $tpl->getInfo() : '')
96  . ($tpl->isAutoGenerated() ? "<br><br>" . $this->lng->txt("didactic_auto_generated") : '');
97 
98  $scope_str = '';
99  if (count($tpl->getEffectiveFrom()) > 0) {
100  $scope_str .= $this->lng->txt('didactic_scope_list_header');
101  foreach ($tpl->getEffectiveFrom() as $ref_id) {
102  $link = $this->ui_renderer->render($this->ui_factory->link()->standard(
104  ilLink::_getLink($ref_id)
105  ));
106  $scope_str .= "<br>";
107  $scope_str .= $link;
108  }
109  } else {
110  $scope_str .= (isset($a_set['local']) ? $this->lng->txt('meta_local') : $this->lng->txt('meta_global'));
111  }
112  $scope_str .= "<br>";
113 
114  $icon_label = '';
115  $icon_path = $tpl->getIconHandler()->getAbsolutePath();
116  foreach ($tpl->getAssignments() as $obj_type) {
117  $icon_label = $this->lng->txt('objs_' . $obj_type);
118  }
119  if ($icon_path) {
120  $icon = $this->ui_factory->symbol()->icon()->custom(
121  $icon_path,
122  $icon_label
123  );
124  }
125 
126  $icon_active = $this->ui_factory->symbol()->icon()->custom(
127  $tpl->isEnabled() ?
128  ilUtil::getImagePath('standard/icon_ok.svg') :
129  ilUtil::getImagePath('standard/icon_not_ok.svg'),
130  $tpl->isEnabled() ? $this->lng->txt('active') : $this->lng->txt('inactive'),
131  Icon::MEDIUM
132  );
133 
134  $record = [
135  'template_id' => $tpl->getId(),
136  'title' => $title_desc,
137  'applicable' => $atxt,
138  'scope' => $scope_str,
139  'enabled' => $icon_active,
140  'automatically_generated' => $tpl->isAutoGenerated()
141  ];
142  if (isset($icon)) {
143  $record['icon'] = $icon;
144  }
145  $records[] = $record;
146  }
147  list($order_field, $order_direction) = $order->join([], fn($ret, $key, $value) => [$key, $value]);
148  usort($records, fn($a, $b) => $a[$order_field] <=> $b[$order_field]);
149  if (
150  $order_direction === 'DESC'
151  ) {
152  $records = array_reverse($records);
153  }
154  $selected_records = array_slice(
155  $records,
156  $range->getStart(),
157  $range->getLength()
158  );
159  return $selected_records;
160  }
161 }
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...
join($init, callable $fn)
Definition: Order.php:59
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Both the subject and the direction need to be specified when expressing an order. ...
Definition: Order.php:12
static _lookupObjId(int $ref_id)
buildDataRow(string $id, array $record)
__construct(ilDidacticTemplateSettingsTableFilter $filter, ilLanguage $lng, UIFactory $ui_factory, UIRenderer $ui_renderer,)
$ref_id
Definition: ltiauth.php:67
static _lookupTitle(int $obj_id)
string $key
Consumer key/client ID value.
Definition: System.php:193
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
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...
A simple class to express a range of whole positive numbers.
Definition: Range.php:30