ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLanguageStatisticsTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
27{
28 protected ?ilObject $object = null;
30 protected ilLanguage $lng;
31
32 public function __construct(
34 ILIAS\UI\Factory $ui_factory,
36 ) {
37 $this->object = $object;
38 $this->ui_factory = $ui_factory;
39 $this->lng = $lng;
40 }
41
42 public function getTable(): DataTable\Data
43 {
44 return $this->ui_factory->table()->data(
45 $this,
46 '',
47 $this->getColums(),
48 );
49 }
50
51 protected function getColums(): array
52 {
53 $f = $this->ui_factory->table()->column();
54 return [
55 'module' => $f->text(ucfirst($this->lng->txt("module"))),
56 'all' => $f->number($this->lng->txt("language_scope_global")),
57 'changed' => $f->number($this->lng->txt("language_scope_local")),
58 'unchanged' => $f->number($this->lng->txt("language_scope_unchanged")),
59 ];
60 }
61
62 public function getItems(?Range $range = null, ?Order $order = null): array
63 {
64 $modules = ilObjLanguageExt::_getModules($this->object->key);
65
66 $data = [];
67 $total = [];
68 foreach ($modules as $module) {
69 $row = [];
70 $row["module"] = $module;
71 $row["all"] = count($this->object->getAllValues([$module]));
72 $row["changed"] = count($this->object->getChangedValues([$module]));
73 $row["unchanged"] = $row["all"] - $row["changed"];
74 isset($total["all"]) ? $total["all"] += $row["all"] : $total["all"] = $row["all"];
75 isset($total["changed"]) ? $total["changed"] += $row["changed"] : $total["changed"] = $row["changed"];
76 isset($total["unchanged"]) ? $total["unchanged"] += $row["unchanged"] : $total["unchanged"] = $row["unchanged"];
77 $data[] = $row;
78 }
79 $total["module"] = $this->lng->txt("language_all_modules");
80 $total["all"] = $total["all"];
81 $total["changed"] = $total["changed"];
82 $total["unchanged"] = $total["unchanged"];
83 array_unshift($data, $total);
84
85 if($order) {
86 list($order_field, $order_direction) = $order->join([], fn($ret, $key, $value) => [$key, $value]);
87 usort(
88 $data,
89 static function ($a, $b) use ($order_field) {
90 switch ($order_field) {
91 case 'module':
92 $a_aspect = $a["module"];
93 $b_aspect = $b["module"];
94 break;
95 case 'all':
96 $a_aspect = $a["all"];
97 $b_aspect = $b["all"];
98 break;
99 case 'changed':
100 $a_aspect = $a["changed"];
101 $b_aspect = $b["changed"];
102 break;
103 case 'unchanged':
104 $a_aspect = $a["unchanged"];
105 $b_aspect = $b["unchanged"];
106 break;
107 }
108 return $a_aspect <=> $b_aspect;
109 }
110 );
111 if ($order_direction === 'DESC') {
112 $data = array_reverse($data);
113 }
114 }
115
116 if ($range) {
117 $data = array_slice($data, $range->getStart(), $range->getLength());
118 }
119
120 return $data;
121 }
122
126 public function getRows(
127 \ILIAS\UI\Component\Table\DataRowBuilder $row_builder,
128 array $visible_column_ids,
129 \ILIAS\Data\Range $range,
130 \ILIAS\Data\Order $order,
131 ?array $filter_data,
132 ?array $additional_parameters
133 ): Generator {
134 foreach ($this->getItems($range, $order) as $idx => $record) {
135 $obj_id = (string) $idx;
136 $record['module'] = $record['module'];
137 $record['all'] = $record['all'];
138 $record['changed'] = $record['changed'];
139 $record['unchanged'] = $record['unchanged'];
140
141 yield $row_builder->buildDataRow($obj_id, $record);
142 }
143 }
144
148 public function getTotalRowCount(?array $filter_data, ?array $additional_parameters): ?int
149 {
150 return count($this->getItems());
151 }
152}
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
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
getItems(?Range $range=null, ?Order $order=null)
getRows(\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, \ILIAS\Data\Range $range, \ILIAS\Data\Order $order, ?array $filter_data, ?array $additional_parameters)
@inheritDoc
__construct(?ilObject $object, ILIAS\UI\Factory $ui_factory, ilLanguage $lng,)
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
@inheritDoc
language handling
static _getModules(string $a_lang_key)
Get all modules of a language.
Class ilObject Basic functions for all objects.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples