ILIAS  trunk Revision v12.0_alpha-1230-g1dde937972f
ILIAS\Forum\Statistics\ForumStatisticsTable Class Reference
+ Inheritance diagram for ILIAS\Forum\Statistics\ForumStatisticsTable:
+ Collaboration diagram for ILIAS\Forum\Statistics\ForumStatisticsTable:

Public Member Functions

 __construct (private readonly ilObjForum $forum, private readonly ilForumProperties $obj_properties, private readonly bool $has_general_lp_access, private readonly bool $has_rbac_or_position_access, private readonly ilObjUser $actor, private readonly UIFactory $ui_factory, private readonly HttpRequest $request, private readonly ilLanguage $lng,)
 
 getComponent ()
 
 getRows (\ILIAS\UI\Component\Table\DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters,)
 
 getTotalRowCount (mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 
- Public Member Functions inherited from ILIAS\UI\Component\Table\DataRetrieval
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
 getTotalRowCount (mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 

Private Member Functions

 getColumns ()
 
 initRecords ()
 
 sortedRecords (array $records, Order $order)
 
 getRecords (Range $range, Order $order)
 
 limitRecords (array $records, Range $range)
 
 getProgressStatus (int $user_id)
 

Private Attributes

bool $has_active_lp = false
 
array $completed = []
 
array $failed = []
 
array $in_progress = []
 
array $records = null
 
readonly ilLPStatusIcons $icons
 

Detailed Description

Definition at line 39 of file ForumStatisticsTable.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Forum\Statistics\ForumStatisticsTable::__construct ( private readonly ilObjForum  $forum,
private readonly ilForumProperties  $obj_properties,
private readonly bool  $has_general_lp_access,
private readonly bool  $has_rbac_or_position_access,
private readonly ilObjUser  $actor,
private readonly UIFactory  $ui_factory,
private readonly HttpRequest  $request,
private readonly ilLanguage  $lng 
)

Definition at line 54 of file ForumStatisticsTable.php.

63 {
65
66 $lp = ilObjectLP::getInstance($forum->getId());
67 if ($lp->isActive()) {
68 $this->has_active_lp = true;
69 }
70
71 if ($this->has_active_lp && $this->has_general_lp_access) {
72 $this->lng->loadLanguageModule('trac');
73 $this->completed = ilLPStatusWrapper::_lookupCompletedForObject($forum->getId());
74 $this->in_progress = ilLPStatusWrapper::_lookupInProgressForObject($forum->getId());
75 $this->failed = ilLPStatusWrapper::_lookupFailedForObject($forum->getId());
76 }
77 }
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
static _lookupFailedForObject(int $a_obj_id, ?array $a_user_ids=null)
static _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
static getInstance(int $obj_id)

References ilLPStatusWrapper\_lookupCompletedForObject(), ilLPStatusWrapper\_lookupFailedForObject(), ilLPStatusWrapper\_lookupInProgressForObject(), ilObjectLP\getInstance(), ilLPStatusIcons\getInstance(), ilLPStatusIcons\ICON_VARIANT_LONG, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ getColumns()

ILIAS\Forum\Statistics\ForumStatisticsTable::getColumns ( )
private
Returns
array<string, \ILIAS\UI\Component\Table\Column\Column>

Definition at line 96 of file ForumStatisticsTable.php.

96 : array
97 {
98 $columns = [
99 'ranking' => $this->ui_factory->table()->column()->number(
100 $this->lng->txt('frm_statistics_ranking')
101 )->withIsSortable(true),
102 'login' => $this->ui_factory->table()->column()->text(
103 $this->lng->txt('login')
104 )->withIsSortable(true),
105 'lastname' => $this->ui_factory->table()->column()->text(
106 $this->lng->txt('lastname')
107 )->withIsSortable(true),
108 'firstname' => $this->ui_factory->table()->column()->text(
109 $this->lng->txt('firstname')
110 )->withIsSortable(true),
111 ];
112 if ($this->has_active_lp && $this->has_general_lp_access) {
113 $columns['progress'] = $this->ui_factory->table()->column()->status(
114 $this->lng->txt('learning_progress')
115 )->withIsSortable(false);
116 }
117
118 return $columns;
119 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getComponent()

ILIAS\Forum\Statistics\ForumStatisticsTable::getComponent ( )

Definition at line 79 of file ForumStatisticsTable.php.

79 : DataTable
80 {
81 return $this->ui_factory
82 ->table()
83 ->data(
84 $this,
85 $this->lng->txt('frm_moderators'),
86 $this->getColumns()
87 )
88 ->withId(str_replace('\\', '', self::class) . '_' . $this->forum->getId())
89 ->withRange(new Range(0, 50))
90 ->withRequest($this->request);
91 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getProgressStatus()

ILIAS\Forum\Statistics\ForumStatisticsTable::getProgressStatus ( int  $user_id)
private

Definition at line 210 of file ForumStatisticsTable.php.

210 : string
211 {
212 $icon = '';
213 if ($this->has_active_lp &&
214 $this->has_general_lp_access &&
215 ($this->has_rbac_or_position_access || $this->actor->getId() === $user_id)) {
216 $icon = match (true) {
217 \in_array($user_id, $this->completed, false) => $this->icons->renderIconForStatus(
219 ),
220 \in_array($user_id, $this->in_progress, false) => $this->icons->renderIconForStatus(
222 ),
223 \in_array($user_id, $this->failed, false) => $this->icons->renderIconForStatus(
225 ),
226 default => $this->icons->renderIconForStatus(ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM),
227 };
228 }
229
230 return $icon;
231 }
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM

References $user_id, ilLPStatus\LP_STATUS_COMPLETED_NUM, ilLPStatus\LP_STATUS_FAILED_NUM, ilLPStatus\LP_STATUS_IN_PROGRESS_NUM, and ilLPStatus\LP_STATUS_NOT_ATTEMPTED_NUM.

Referenced by ILIAS\Forum\Statistics\ForumStatisticsTable\initRecords().

+ Here is the caller graph for this function:

◆ getRecords()

ILIAS\Forum\Statistics\ForumStatisticsTable::getRecords ( Range  $range,
Order  $order 
)
private

◆ getRows()

ILIAS\Forum\Statistics\ForumStatisticsTable::getRows ( \ILIAS\UI\Component\Table\DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

Definition at line 184 of file ForumStatisticsTable.php.

192 : \Generator {
193 $records = $this->getRecords($range, $order);
194 foreach ($records as $record) {
195 $row_id = (string) $record['usr_id'];
196 yield $row_builder->buildDataRow($row_id, $record);
197 }
198 }

◆ getTotalRowCount()

ILIAS\Forum\Statistics\ForumStatisticsTable::getTotalRowCount ( mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

Mainly for the purpose of pagination-support, it is important to know about the total number of records available.

Given the nature of a DataTable, which is, opposite to a PresentationTable, rather administrative than explorative, this information will increase user experience quite a bit. However, you may return null, if the call is to costly, but expect the View Control to look a little different in this case.

Make sure that potential filters or user restrictions are being applied to the count.

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 200 of file ForumStatisticsTable.php.

204 : ?int {
205 $this->initRecords();
206
207 return \count($this->records);
208 }

◆ initRecords()

ILIAS\Forum\Statistics\ForumStatisticsTable::initRecords ( )
private

Definition at line 121 of file ForumStatisticsTable.php.

121 : void
122 {
123 if ($this->records === null) {
124 $this->records = [];
125 $data = $this->forum->Forum->getUserStatistics($this->obj_properties->isPostActivationEnabled());
126 $counter = 0;
127 foreach ($data as $row) {
128 $this->records[$counter]['usr_id'] = $row['usr_id'];
129 $this->records[$counter]['ranking'] = $row['num_postings'];
130 $this->records[$counter]['login'] = $row['login'];
131 $this->records[$counter]['lastname'] = $row['lastname'];
132 $this->records[$counter]['firstname'] = $row['firstname'];
133 if ($this->has_active_lp && $this->has_general_lp_access) {
134 $this->records[$counter]['progress'] = $this->getProgressStatus($row['usr_id']);
135 }
136 ++$counter;
137 }
138 }
139 }
$counter

References $counter, $data, and ILIAS\Forum\Statistics\ForumStatisticsTable\getProgressStatus().

Referenced by ILIAS\Forum\Statistics\ForumStatisticsTable\getRecords().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ limitRecords()

ILIAS\Forum\Statistics\ForumStatisticsTable::limitRecords ( array  $records,
Range  $range 
)
private
Parameters
list<array<string,mixed>>$records
Returns
list<array<string, mixed>>

Definition at line 179 of file ForumStatisticsTable.php.

179 : array
180 {
181 return \array_slice($records, $range->getStart(), $range->getLength());
182 }

References ILIAS\UI\Implementation\Component\Table\$range, ILIAS\Forum\Statistics\ForumStatisticsTable\$records, ILIAS\Data\Range\getLength(), and ILIAS\Data\Range\getStart().

Referenced by ILIAS\Forum\Statistics\ForumStatisticsTable\getRecords().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sortedRecords()

ILIAS\Forum\Statistics\ForumStatisticsTable::sortedRecords ( array  $records,
Order  $order 
)
private
Parameters
list<array<string,mixed>>$records
Returns
list<array<string, mixed>>

Definition at line 145 of file ForumStatisticsTable.php.

145 : array
146 {
147 [$order_field, $order_direction] = $order->join([], fn($ret, $key, $value) => [$key, $value]);
148
149 usort($records, static function ($left, $right) use ($order_field): int {
150 if ($order_field === 'ranking') {
151 return $left[$order_field] <=> $right[$order_field];
152 }
153
154 return ilStr::strCmp($left[$order_field], $right[$order_field]);
155 });
156
157 if ($order_direction === 'DESC') {
158 $records = array_reverse($records);
159 }
160
161 return $records;
162 }
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87

References ILIAS\Forum\Statistics\ForumStatisticsTable\$records, ILIAS\Data\Order\join(), and ilStr\strCmp().

Referenced by ILIAS\Forum\Statistics\ForumStatisticsTable\getRecords().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $completed

array ILIAS\Forum\Statistics\ForumStatisticsTable::$completed = []
private

Definition at line 43 of file ForumStatisticsTable.php.

◆ $failed

array ILIAS\Forum\Statistics\ForumStatisticsTable::$failed = []
private

Definition at line 45 of file ForumStatisticsTable.php.

◆ $has_active_lp

bool ILIAS\Forum\Statistics\ForumStatisticsTable::$has_active_lp = false
private

Definition at line 41 of file ForumStatisticsTable.php.

◆ $icons

readonly ilLPStatusIcons ILIAS\Forum\Statistics\ForumStatisticsTable::$icons
private

Definition at line 52 of file ForumStatisticsTable.php.

◆ $in_progress

array ILIAS\Forum\Statistics\ForumStatisticsTable::$in_progress = []
private

Definition at line 47 of file ForumStatisticsTable.php.

◆ $records

array ILIAS\Forum\Statistics\ForumStatisticsTable::$records = null
private

The documentation for this class was generated from the following file: