ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMStListCertificatesTableGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
6 use Closure;
8 use ilCSVWriter;
9 use ilDateTime;
10 use ilExcel;
15 use ilTable2GUI;
16 use ilTextInputGUI;
18 
25 {
26 
30  protected $filter = array();
38  protected $usr_orgu_names = [];
42  protected $access;
43 
44 
50  {
51  global $DIC;
52 
53  $this->access = ilMyStaffAccess::getInstance();
54 
55  $this->setPrefix('myst_lcrt');
56  $this->setFormName('myst_lcrt');
57  $this->setId('myst_lcrt');
58 
59  parent::__construct($parent_obj, $parent_cmd, '');
60 
61  $this->setRowTemplate('tpl.list_courses_row.html', "Services/MyStaff");
62  $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
63  $this->setDefaultOrderDirection('desc');
64 
65  $this->setShowRowsSelector(true);
66 
67  $this->setEnableTitle(true);
68  $this->setDisableFilterHiding(true);
69  $this->setEnableNumInfo(true);
70 
71  $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
72 
73  $this->setFilterCols(5);
74  $this->initFilter();
75 
76  $this->addColumns();
77 
78  $this->parseData();
79  }
80 
81 
85  protected function parseData() : void
86  {
87  global $DIC;
88 
89  $this->setExternalSorting(true);
90  $this->setExternalSegmentation(true);
91  $this->setDefaultOrderField('obj_title');
92 
93  $this->determineLimit();
94  $this->determineOffsetAndOrder();
95 
96  $options = array(
97  'filters' => $this->filter,
98  'limit' => array(
99  'start' => $this->getOffset(),
100  'end' => $this->getLimit(),
101  ),
102  'count' => true,
103  'sort' => array(
104  'field' => $this->getOrderField(),
105  'direction' => $this->getOrderDirection(),
106  ),
107  );
108 
109  $certificates_fetcher = new ilMStListCertificates($DIC);
110  $data = $certificates_fetcher->getData($options);
111 
112  $this->setData($data);
113 
114  $options['limit'] = array(
115  'start' => null,
116  'end' => null,
117  );
118  $max_data = $certificates_fetcher->getData($options);
119  $this->setMaxCount(count($max_data));
120  }
121 
122 
123  public function initFilter()
124  {
125  global $DIC;
126 
127  $item = new ilTextInputGUI($DIC->language()->txt("title"), "obj_title");
128  $this->addFilterItem($item);
129  $item->readFromSession();
130  $this->filter['obj_title'] = $item->getValue();
131 
132  //user
133  $item = new ilTextInputGUI(
134  $DIC->language()->txt("login")
135  . "/" . $DIC->language()->txt("email")
136  . "/" . $DIC->language()->txt("name"),
137  "user"
138  );
139 
140  $this->addFilterItem($item);
141  $item->readFromSession();
142  $this->filter['user'] = $item->getValue();
143 
144  if (ilUserSearchOptions::_isEnabled('org_units')) {
146  $options[0] = $DIC->language()->txt('mst_opt_all');
147  foreach ($paths as $org_ref_id => $path) {
148  $options[$org_ref_id] = $path;
149  }
150  $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
151  $item->setOptions($options);
152  $this->addFilterItem($item);
153  $item->readFromSession();
154  $this->filter['org_unit'] = $item->getValue();
155  }
156  }
157 
158  public function getSelectableColumns() : array
159  {
160  if ($this->selectable_columns_cached) {
162  }
163 
164  return $this->selectable_columns_cached = $this->initSelectableColumns();
165  }
166 
167  protected function initSelectableColumns() : array
168  {
169  global $DIC;
170 
171  $cols = array();
172 
173  $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
174 
175  $cols['objectTitle'] = array(
176  'txt' => $DIC->language()->txt('title'),
177  'default' => true,
178  'width' => 'auto',
179  'sort_field' => 'objectTitle',
180  );
181  $cols['issuedOnTimestamp'] = array(
182  'txt' => $DIC->language()->txt('mst_cert_issued_on'),
183  'default' => true,
184  'width' => 'auto',
185  'sort_field' => 'issuedOnTimestamp',
186  );
187  if ($arr_searchable_user_columns['login']) {
188  $cols['userLogin'] = array(
189  'txt' => $DIC->language()->txt('login'),
190  'default' => true,
191  'width' => 'auto',
192  'sort_field' => 'userLogin',
193  );
194  }
195  if ($arr_searchable_user_columns['firstname']) {
196  $cols['userFirstName'] = array(
197  'txt' => $DIC->language()->txt('firstname'),
198  'default' => true,
199  'width' => 'auto',
200  'sort_field' => 'userFirstName',
201  );
202  }
203  if ($arr_searchable_user_columns['lastname']) {
204  $cols['userLastName'] = array(
205  'txt' => $DIC->language()->txt('lastname'),
206  'default' => true,
207  'width' => 'auto',
208  'sort_field' => 'userLastName',
209  );
210  }
211 
212  if ($arr_searchable_user_columns['email']) {
213  $cols['userEmail'] = array(
214  'txt' => $DIC->language()->txt('email'),
215  'default' => true,
216  'width' => 'auto',
217  'sort_field' => 'userEmail',
218  );
219  }
220  if ($arr_searchable_user_columns['org_units']) {
221  $cols['usr_assinged_orgus'] = array(
222  'txt' => $DIC->language()->txt('objs_orgu'),
223  'default' => true,
224  'width' => 'auto',
225  );
226  }
227 
228  return $cols;
229  }
230 
231 
235  private function addColumns()
236  {
237  global $DIC;
238 
239  foreach ($this->getSelectableColumns() as $k => $v) {
240  if ($this->isColumnSelected($k)) {
241  if (isset($v['sort_field'])) {
242  $sort = $v['sort_field'];
243  } else {
244  $sort = null;
245  }
246  $this->addColumn($v['txt'], $sort, $v['width']);
247  }
248  }
249 
250  //Actions
251  if (!$this->getExportMode()) {
252  $this->addColumn($DIC->language()->txt('actions'));
253  }
254  }
255 
256  protected function getTextRepresentationOfUsersOrgUnits(int $user_id) : string
257  {
258  if (isset($this->usr_orgu_names[$user_id])) {
259  return $this->usr_orgu_names[$user_id];
260  }
261 
262  return $this->usr_orgu_names[$user_id] = \ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
263  }
264 
268  public function fillRow($user_certificate_dto)
269  {
270  global $DIC;
271 
272  $propGetter = Closure::bind(function ($prop) {
273  return $this->$prop;
274  }, $user_certificate_dto, $user_certificate_dto);
275 
276  foreach ($this->getSelectedColumns() as $k => $v) {
277  switch ($k) {
278  case 'usr_assinged_orgus':
279  $this->tpl->setCurrentBlock('td');
280  $this->tpl->setVariable('VALUE', $this->getTextRepresentationOfUsersOrgUnits($user_certificate_dto->getUserId()));
281  $this->tpl->parseCurrentBlock();
282  break;
283  case 'issuedOnTimestamp':
284  $date_time = new ilDateTime($propGetter($k), IL_CAL_UNIX);
285  $this->tpl->setCurrentBlock('td');
286  $this->tpl->setVariable('VALUE', $date_time->get(IL_CAL_DATE));
287  $this->tpl->parseCurrentBlock();
288  break;
289  default:
290  if ($propGetter($k) !== null) {
291  $this->tpl->setCurrentBlock('td');
292  $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
293  $this->tpl->parseCurrentBlock();
294  } else {
295  $this->tpl->setCurrentBlock('td');
296  $this->tpl->setVariable('VALUE', '&nbsp;');
297  $this->tpl->parseCurrentBlock();
298  }
299  break;
300  }
301  }
302 
303  $actions = new ilAdvancedSelectionListGUI();
304  $actions->setListTitle($DIC->language()->txt("actions"));
305  $actions->setId($user_certificate_dto->getCertificateId());
306  $actions->addItem($DIC->language()->txt("mst_download_certificate"), '', $user_certificate_dto->getDownloadLink());
307 
308  $this->tpl->setVariable('ACTIONS', $actions->getHTML());
309  $this->tpl->parseCurrentBlock();
310  }
311 
312 
318  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $user_certificate_dto)
319  {
320  $col = 0;
321  foreach ($this->getFieldValuesForExport($user_certificate_dto) as $k => $v) {
322  $a_excel->setCell($a_row, $col, $v);
323  $col++;
324  }
325  }
326 
327 
332  protected function fillRowCSV($a_csv, $user_certificate_dto)
333  {
334  foreach ($this->getFieldValuesForExport($user_certificate_dto) as $k => $v) {
335  $a_csv->addColumn($v);
336  }
337  $a_csv->addRow();
338  }
339 
340 
346  protected function getFieldValuesForExport(UserCertificateDto $user_certificate_dto)
347  {
348  $propGetter = Closure::bind(function ($prop) {
349  return $this->$prop;
350  }, $user_certificate_dto, $user_certificate_dto);
351 
352  $field_values = array();
353  foreach ($this->getSelectedColumns() as $k => $v) {
354  switch ($k) {
355  case 'usr_assinged_orgus':
356  $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($user_certificate_dto->getUserId());
357  break;
358  case 'issuedOnTimestamp':
359  $field_values[$k] = new ilDateTime($propGetter($k), IL_CAL_UNIX);
360  break;
361  default:
362  $field_values[$k] = strip_tags($propGetter($k));
363  break;
364  }
365  }
366 
367  return $field_values;
368  }
369 }
setExternalSorting($a_val)
Set external sorting.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setExportFormats(array $formats)
Set available export formats.
setEnableNumInfo($a_val)
Set enable num info.
setFilterCols($a_val)
Set filter columns.
setExternalSegmentation($a_val)
Set external segmentation.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
determineLimit()
Determine the limit.
__construct(ilMStListCertificatesGUI $parent_obj, $parent_cmd=ilMStListCertificatesGUI::CMD_INDEX)
const IL_CAL_UNIX
getOrderDirection()
Get order direction.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
static getTextRepresentationOfOrgUnits($sort_by_title=true)
Get ref id path array.
static getSelectableColumnInfo($a_admin=false)
Get info of searchable fields for selectable columns in table gui.
getOffset()
Get offset.
setDisableFilterHiding($a_val=true)
Set disable filter hiding.
global $DIC
Definition: goto.php:24
setPrefix($a_prefix)
getSelectedColumns()
Get selected columns.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
isColumnSelected($a_col)
Is given column selected?
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
const IL_CAL_DATE
setFormName($a_formname="")
Set Form name.
__construct(Container $dic, ilPlugin $plugin)
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getLimit()
Get limit.
filter()
Definition: filter.php:2
setMaxCount($a_max_count)
set max.
getExportMode()
Was export activated?
setEnableTitle($a_enabletitle)
Set Enable Title.
$cols
Definition: xhr_table.php:11