ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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;
30  private array $completed = [];
32  private array $failed = [];
34  private array $in_progress = [];
35 
36  public function __construct(
37  ilObjForumGUI $a_parent_obj,
38  string $a_parent_cmd,
39  ilObjForum $forum,
40  private ilObjUser $actor,
41  private bool $has_general_lp_access,
42  private bool $has_rbac_or_position_access
43  ) {
44  parent::__construct($a_parent_obj, $a_parent_cmd);
45 
46  $lp = ilObjectLP::getInstance($forum->getId());
47  if ($lp->isActive()) {
48  $this->has_active_lp = true;
49  }
50 
51  $this->setRowTemplate('tpl.statistics_table_row.html', 'Modules/Forum');
52 
53  $columns = $this->getColumnDefinition();
54  foreach ($columns as $column) {
55  $this->addColumn(
56  $column['txt'],
57  isset($column['sortable']) && $column['sortable'] ? $column['field'] : '',
58  (ceil((100 / count($columns)))) . '%'
59  );
60  }
61 
62  if ($this->has_active_lp && $this->has_general_lp_access) {
63  $this->lng->loadLanguageModule('trac');
64  $this->completed = ilLPStatusWrapper::_lookupCompletedForObject($forum->getId());
65  $this->in_progress = ilLPStatusWrapper::_lookupInProgressForObject($forum->getId());
66  $this->failed = ilLPStatusWrapper::_lookupFailedForObject($forum->getId());
67  }
68 
69  $this->setDefaultOrderField('ranking');
70  $this->setDefaultOrderDirection('desc');
71 
72  $this->enable('hits');
73  $this->enable('sort');
74  }
75 
79  protected function getColumnDefinition(): array
80  {
81  $i = 0;
82 
83  $columns = [];
84 
85  $columns[++$i] = [
86  'field' => 'ranking',
87  'txt' => $this->lng->txt('frm_statistics_ranking'),
88  'sortable' => true,
89  ];
90  $columns[++$i] = [
91  'field' => 'login',
92  'txt' => $this->lng->txt('login'),
93  'sortable' => true,
94  ];
95  $columns[++$i] = [
96  'field' => 'lastname',
97  'txt' => $this->lng->txt('lastname'),
98  'sortable' => true,
99  ];
100  $columns[++$i] = [
101  'field' => 'firstname',
102  'txt' => $this->lng->txt('firstname'),
103  'sortable' => true,
104  ];
105  if ($this->has_active_lp && $this->has_general_lp_access) {
106  $columns[++$i] = [
107  'field' => 'progress',
108  'txt' => $this->lng->txt('learning_progress'),
109  'sortable' => false,
110  ];
111  }
112 
113  return $columns;
114  }
115 
116  protected function fillRow(array $a_set): void
117  {
118  parent::fillRow($a_set);
119 
121 
122  if ($this->has_active_lp && $this->has_general_lp_access) {
123  if ($this->has_rbac_or_position_access || $this->actor->getId() === (int) $a_set['usr_id']) {
124  $this->tpl->setCurrentBlock('val_lp');
125  switch (true) {
126  case in_array($a_set['usr_id'], $this->completed, false):
127  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt(ilLPStatus::LP_STATUS_COMPLETED));
128  $this->tpl->setVariable(
129  'LP_STATUS_ICON',
130  $icons->renderIconForStatus(ilLPStatus::LP_STATUS_COMPLETED_NUM)
131  );
132  break;
133 
134  case in_array($a_set['usr_id'], $this->in_progress, false):
135  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt(ilLPStatus::LP_STATUS_IN_PROGRESS));
136  $this->tpl->setVariable(
137  'LP_STATUS_ICON',
138  $icons->renderIconForStatus(ilLPStatus::LP_STATUS_IN_PROGRESS_NUM)
139  );
140  break;
141 
142  case in_array($a_set['usr_id'], $this->failed, false):
143  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt(ilLPStatus::LP_STATUS_FAILED));
144  $this->tpl->setVariable(
145  'LP_STATUS_ICON',
146  $icons->renderIconForStatus(ilLPStatus::LP_STATUS_FAILED_NUM)
147  );
148  break;
149 
150  default:
151  $this->tpl->setVariable('LP_STATUS_ALT', $this->lng->txt(ilLPStatus::LP_STATUS_NOT_ATTEMPTED));
152  $this->tpl->setVariable(
153  'LP_STATUS_ICON',
154  $icons->renderIconForStatus(ilLPStatus::LP_STATUS_NOT_ATTEMPTED_NUM)
155  );
156  break;
157  }
158  $this->tpl->parseCurrentBlock();
159  } else {
160  $this->tpl->touchBlock('no_lp');
161  }
162  }
163  }
164 
165  public function numericOrdering(string $a_field): bool
166  {
167  return match ($a_field) {
168  'ranking' => true,
169  default => false,
170  };
171  }
172 }
const LP_STATUS_COMPLETED_NUM
Class ilForumStatisticsTableGUI.
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)
const LP_STATUS_IN_PROGRESS
static _lookupCompletedForObject(int $a_obj_id, ?array $a_user_ids=null)
__construct(ilObjForumGUI $a_parent_obj, string $a_parent_cmd, ilObjForum $forum, private ilObjUser $actor, private bool $has_general_lp_access, private bool $has_rbac_or_position_access)
__construct(VocabulariesInterface $vocabularies)
const LP_STATUS_FAILED
setDefaultOrderField(string $a_defaultorderfield)
ilObjForumGUI: ilPermissionGUI, ilForumExportGUI, ilInfoScreenGUI ilObjForumGUI: ilColumnGUI...
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
const LP_STATUS_NOT_ATTEMPTED_NUM
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