ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilForumStatisticsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
28  private bool $has_active_lp = false;
29  private bool $has_general_lp_access;
31  private ilObjUser $actor;
33  private array $completed = [];
35  private array $failed = [];
37  private array $in_progress = [];
38 
39  public function __construct(
40  ilObjForumGUI $a_parent_obj,
41  string $a_parent_cmd,
42  ilObjForum $forum,
43  ilObjUser $actor,
44  bool $has_general_lp_access,
45  bool $has_rbac_or_position_access
46  ) {
47  parent::__construct($a_parent_obj, $a_parent_cmd);
48 
49  $lp = ilObjectLP::getInstance($forum->getId());
50  if ($lp->isActive()) {
51  $this->has_active_lp = true;
52  }
53  $this->has_general_lp_access = $has_general_lp_access;
54  $this->has_rbac_or_position_access = $has_rbac_or_position_access;
55  $this->actor = $actor;
56 
57  $this->setRowTemplate('tpl.statistics_table_row.html', 'Modules/Forum');
58 
59  $columns = $this->getColumnDefinition();
60  foreach ($columns as $index => $column) {
61  $this->addColumn(
62  $column['txt'],
63  isset($column['sortable']) && $column['sortable'] ? $column['field'] : '',
64  ((string) ceil((100 / count($columns)))) . '%s'
65  );
66  }
67 
68  if ($this->has_active_lp && $this->has_general_lp_access) {
69  $this->lng->loadLanguageModule('trac');
70  $this->completed = ilLPStatusWrapper::_lookupCompletedForObject($forum->getId());
71  $this->in_progress = ilLPStatusWrapper::_lookupInProgressForObject($forum->getId());
72  $this->failed = ilLPStatusWrapper::_lookupFailedForObject($forum->getId());
73  }
74 
75  $this->setDefaultOrderField('ranking');
76  $this->setDefaultOrderDirection('desc');
77 
78  $this->enable('hits');
79  $this->enable('sort');
80  }
81 
85  protected function getColumnDefinition(): array
86  {
87  $i = 0;
88 
89  $columns = [];
90 
91  $columns[++$i] = [
92  'field' => 'ranking',
93  'txt' => $this->lng->txt('frm_statistics_ranking'),
94  'sortable' => true,
95  ];
96  $columns[++$i] = [
97  'field' => 'login',
98  'txt' => $this->lng->txt('login'),
99  'sortable' => true,
100  ];
101  $columns[++$i] = [
102  'field' => 'lastname',
103  'txt' => $this->lng->txt('lastname'),
104  'sortable' => true,
105  ];
106  $columns[++$i] = [
107  'field' => 'firstname',
108  'txt' => $this->lng->txt('firstname'),
109  'sortable' => true,
110  ];
111  if ($this->has_active_lp && $this->has_general_lp_access) {
112  $columns[++$i] = [
113  'field' => 'progress',
114  'txt' => $this->lng->txt('learning_progress'),
115  'sortable' => false,
116  ];
117  }
118 
119  return $columns;
120  }
121 
122  protected function fillRow(array $a_set): void
123  {
124  parent::fillRow($a_set);
125 
127 
128  if ($this->has_active_lp && $this->has_general_lp_access) {
129  if ($this->has_rbac_or_position_access || $this->actor->getId() === (int) $a_set['usr_id']) {
130  $this->tpl->setCurrentBlock('val_lp');
131  switch (true) {
132  case in_array($a_set['usr_id'], $this->completed, false):
133  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt(ilLPStatus::LP_STATUS_COMPLETED));
134  $this->tpl->setVariable(
135  'LP_STATUS_ICON',
136  $icons->renderIconForStatus(ilLPStatus::LP_STATUS_COMPLETED_NUM)
137  );
138  break;
139 
140  case in_array($a_set['usr_id'], $this->in_progress, false):
141  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt(ilLPStatus::LP_STATUS_IN_PROGRESS));
142  $this->tpl->setVariable(
143  'LP_STATUS_ICON',
144  $icons->renderIconForStatus(ilLPStatus::LP_STATUS_IN_PROGRESS_NUM)
145  );
146  break;
147 
148  case in_array($a_set['usr_id'], $this->failed, false):
149  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt(ilLPStatus::LP_STATUS_FAILED));
150  $this->tpl->setVariable(
151  'LP_STATUS_ICON',
152  $icons->renderIconForStatus(ilLPStatus::LP_STATUS_FAILED_NUM)
153  );
154  break;
155 
156  default:
157  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt(ilLPStatus::LP_STATUS_NOT_ATTEMPTED));
158  $this->tpl->setVariable(
159  'LP_STATUS_ICON',
160  $icons->renderIconForStatus(ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM)
161  );
162  break;
163  }
164  $this->tpl->parseCurrentBlock();
165  } else {
166  $this->tpl->touchBlock('no_lp');
167  }
168  }
169  }
170 
171  public function numericOrdering(string $a_field): bool
172  {
173  switch ($a_field) {
174  case 'ranking':
175  return true;
176 
177  default:
178  return false;
179  }
180  }
181 }
const LP_STATUS_COMPLETED_NUM
Class ilForumStatisticsTableGUI.
__construct(ilObjForumGUI $a_parent_obj, string $a_parent_cmd, ilObjForum $forum, ilObjUser $actor, bool $has_general_lp_access, bool $has_rbac_or_position_access)
enable(string $a_module_name)
const LP_STATUS_NOT_ATTEMPTED
static _lookupInProgressForObject(int $a_obj_id, ?array $a_user_ids=null)
const LP_STATUS_IN_PROGRESS_NUM
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
$index
Definition: metadata.php:145
const LP_STATUS_IN_PROGRESS
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
const LP_STATUS_FAILED
setDefaultOrderField(string $a_defaultorderfield)
Class ilObjForumGUI.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
const LP_STATUS_NOT_ATTEMPTED_NUM
__construct(Container $dic, ilPlugin $plugin)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
static _lookupFailedForObject(int $a_obj_id, ?array $a_user_ids=null)
Class ilObjForum.
const LP_STATUS_COMPLETED
static getInstance(int $obj_id)
const LP_STATUS_FAILED_NUM
$i
Definition: metadata.php:41