ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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, ?array $filter_data, ?array $additional_parameters,)
 
 getTotalRowCount (?array $filter_data, ?array $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, ?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.g. 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.

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

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 _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
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 getInstance(int $obj_id)
+ Here is the call graph for this function:

Member Function Documentation

◆ getColumns()

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

Definition at line 95 of file ForumStatisticsTable.php.

References ILIAS\Repository\lng().

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

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

◆ getComponent()

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

Definition at line 79 of file ForumStatisticsTable.php.

References ILIAS\Forum\Statistics\ForumStatisticsTable\getColumns(), and ILIAS\Repository\lng().

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(self::class . '_' . $this->forum->getId())
89  ->withRequest($this->request);
90  }
+ Here is the call graph for this function:

◆ getProgressStatus()

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

Definition at line 205 of file ForumStatisticsTable.php.

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().

205  : string
206  {
207  $icon = '';
208  if ($this->has_active_lp &&
209  $this->has_general_lp_access &&
210  ($this->has_rbac_or_position_access || $this->actor->getId() === $user_id)) {
211  $icon = match (true) {
212  \in_array($user_id, $this->completed, false) => $this->icons->renderIconForStatus(
214  ),
215  \in_array($user_id, $this->in_progress, false) => $this->icons->renderIconForStatus(
217  ),
218  \in_array($user_id, $this->failed, false) => $this->icons->renderIconForStatus(
220  ),
221  default => $this->icons->renderIconForStatus(ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM),
222  };
223  }
224 
225  return $icon;
226  }
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
+ Here is the caller graph for this function:

◆ getRecords()

ILIAS\Forum\Statistics\ForumStatisticsTable::getRecords ( Range  $range,
Order  $order 
)
private
Returns
list<array<string, mixed>>

Definition at line 166 of file ForumStatisticsTable.php.

References ILIAS\Forum\Statistics\ForumStatisticsTable\initRecords(), ILIAS\Forum\Statistics\ForumStatisticsTable\limitRecords(), and ILIAS\Forum\Statistics\ForumStatisticsTable\sortedRecords().

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

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

◆ getRows()

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

Definition at line 183 of file ForumStatisticsTable.php.

References ILIAS\Forum\Statistics\ForumStatisticsTable\getRecords().

190  : \Generator {
191  $records = $this->getRecords($range, $order);
192  foreach ($records as $record) {
193  $row_id = (string) $record['usr_id'];
194  yield $row_builder->buildDataRow($row_id, $record);
195  }
196  }
+ Here is the call graph for this function:

◆ getTotalRowCount()

ILIAS\Forum\Statistics\ForumStatisticsTable::getTotalRowCount ( ?array  $filter_data,
?array  $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 198 of file ForumStatisticsTable.php.

References ILIAS\Forum\Statistics\ForumStatisticsTable\initRecords().

198  : ?int
199  {
200  $this->initRecords();
201 
202  return \count($this->records);
203  }
+ Here is the call graph for this function:

◆ initRecords()

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

Definition at line 120 of file ForumStatisticsTable.php.

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

Referenced by ILIAS\Forum\Statistics\ForumStatisticsTable\getRecords(), and ILIAS\Forum\Statistics\ForumStatisticsTable\getTotalRowCount().

120  : void
121  {
122  if ($this->records === null) {
123  $this->records = [];
124  $data = $this->forum->Forum->getUserStatistics($this->obj_properties->isPostActivationEnabled());
125  $counter = 0;
126  foreach ($data as $row) {
127  $this->records[$counter]['usr_id'] = $row['usr_id'];
128  $this->records[$counter]['ranking'] = $row['num_postings'];
129  $this->records[$counter]['login'] = $row['login'];
130  $this->records[$counter]['lastname'] = $row['lastname'];
131  $this->records[$counter]['firstname'] = $row['firstname'];
132  if ($this->has_active_lp && $this->has_general_lp_access) {
133  $this->records[$counter]['progress'] = $this->getProgressStatus($row['usr_id']);
134  }
135  ++$counter;
136  }
137  }
138  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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 178 of file ForumStatisticsTable.php.

References 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 144 of file ForumStatisticsTable.php.

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

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

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