ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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();
34  protected $access;
35 
36 
42  {
43  global $DIC;
44 
45  $this->access = ilMyStaffAccess::getInstance();
46 
47  $this->setPrefix('myst_lcrt');
48  $this->setFormName('myst_lcrt');
49  $this->setId('myst_lcrt');
50 
51  parent::__construct($parent_obj, $parent_cmd, '');
52 
53  $this->setRowTemplate('tpl.list_courses_row.html', "Services/MyStaff");
54  $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
55  $this->setDefaultOrderDirection('desc');
56 
57  $this->setShowRowsSelector(true);
58 
59  $this->setEnableTitle(true);
60  $this->setDisableFilterHiding(true);
61  $this->setEnableNumInfo(true);
62 
63  $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
64 
65  $this->setFilterCols(5);
66  $this->initFilter();
67 
68  $this->addColumns();
69 
70  $this->parseData();
71  }
72 
73 
77  protected function parseData() : void
78  {
79  global $DIC;
80 
81  $this->setExternalSorting(true);
82  $this->setDefaultOrderField('obj_title');
83 
84  $this->determineLimit();
85  $this->determineOffsetAndOrder();
86 
87  $options = array(
88  'filters' => $this->filter,
89  'limit' => array(),
90  'count' => true,
91  'sort' => array(
92  'field' => $this->getOrderField(),
93  'direction' => $this->getOrderDirection(),
94  ),
95  );
96 
97  $certificates_fetcher = new ilMStListCertificates($DIC);
98  $data = $certificates_fetcher->getData($options);
99  $options['limit'] = array(
100  'start' => intval($this->getOffset()),
101  'end' => intval($this->getLimit()),
102  );
103  $this->setMaxCount(count($data));
104  $this->setData($data);
105  }
106 
107 
108  public function initFilter()
109  {
110  global $DIC;
111 
112  $item = new ilTextInputGUI($DIC->language()->txt("title"), "obj_title");
113  $this->addFilterItem($item);
114  $item->readFromSession();
115  $this->filter['obj_title'] = $item->getValue();
116 
117  //user
118  $item = new ilTextInputGUI($DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language()
119  ->txt("name"), "user");
120 
121  $this->addFilterItem($item);
122  $item->readFromSession();
123  $this->filter['user'] = $item->getValue();
124 
125  if (ilUserSearchOptions::_isEnabled('org_units')) {
127  $options[0] = $DIC->language()->txt('mst_opt_all');
128  foreach ($paths as $org_ref_id => $path) {
129  $options[$org_ref_id] = $path;
130  }
131  $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
132  $item->setOptions($options);
133  $this->addFilterItem($item);
134  $item->readFromSession();
135  $this->filter['org_unit'] = $item->getValue();
136  }
137  }
138 
139 
143  public function getSelectableColumns() : array
144  {
145  global $DIC;
146 
147  $cols = array();
148 
149  $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
150 
151  $cols['objectTitle'] = array(
152  'txt' => $DIC->language()->txt('title'),
153  'default' => true,
154  'width' => 'auto',
155  'sort_field' => 'objectTitle',
156  );
157  $cols['issuedOnTimestamp'] = array(
158  'txt' => $DIC->language()->txt('mst_cert_issued_on'),
159  'default' => true,
160  'width' => 'auto',
161  'sort_field' => 'issuedOnTimestamp',
162  );
163  if ($arr_searchable_user_columns['login']) {
164  $cols['userLogin'] = array(
165  'txt' => $DIC->language()->txt('login'),
166  'default' => true,
167  'width' => 'auto',
168  'sort_field' => 'userLogin',
169  );
170  }
171  if ($arr_searchable_user_columns['firstname']) {
172  $cols['userFirstName'] = array(
173  'txt' => $DIC->language()->txt('firstname'),
174  'default' => true,
175  'width' => 'auto',
176  'sort_field' => 'userFirstName',
177  );
178  }
179  if ($arr_searchable_user_columns['lastname']) {
180  $cols['userLastName'] = array(
181  'txt' => $DIC->language()->txt('lastname'),
182  'default' => true,
183  'width' => 'auto',
184  'sort_field' => 'userLastName',
185  );
186  }
187 
188  if ($arr_searchable_user_columns['email']) {
189  $cols['usr_email'] = array(
190  'txt' => $DIC->language()->txt('email'),
191  'default' => true,
192  'width' => 'auto',
193  'sort_field' => 'usr_email',
194  );
195  }
196  if ($arr_searchable_user_columns['org_units']) {
197  $cols['usr_assinged_orgus'] = array(
198  'txt' => $DIC->language()->txt('objs_orgu'),
199  'default' => true,
200  'width' => 'auto',
201  );
202  }
203 
204  return $cols;
205  }
206 
207 
211  private function addColumns()
212  {
213  global $DIC;
214 
215  foreach ($this->getSelectableColumns() as $k => $v) {
216  if ($this->isColumnSelected($k)) {
217  if (isset($v['sort_field'])) {
218  $sort = $v['sort_field'];
219  } else {
220  $sort = null;
221  }
222  $this->addColumn($v['txt'], $sort, $v['width']);
223  }
224  }
225 
226  //Actions
227  if (!$this->getExportMode()) {
228  $this->addColumn($DIC->language()->txt('actions'));
229  }
230  }
231 
232 
236  public function fillRow($user_certificate_dto)
237  {
238  global $DIC;
239 
240  $propGetter = Closure::bind(function ($prop) {
241  return $this->$prop;
242  }, $user_certificate_dto, $user_certificate_dto);
243 
244  foreach ($this->getSelectableColumns() as $k => $v) {
245  if ($this->isColumnSelected($k)) {
246  switch ($k) {
247  case 'usr_assinged_orgus':
248  $this->tpl->setCurrentBlock('td');
249  $this->tpl->setVariable('VALUE', strval(ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_certificate_dto->getUserId())));
250  $this->tpl->parseCurrentBlock();
251  break;
252  case 'issuedOnTimestamp':
253  $date_time = new ilDateTime($propGetter($k), IL_CAL_UNIX);
254  $this->tpl->setCurrentBlock('td');
255  $this->tpl->setVariable('VALUE', $date_time->get(IL_CAL_DATE));
256  $this->tpl->parseCurrentBlock();
257  break;
258  default:
259  if ($propGetter($k) !== null) {
260  $this->tpl->setCurrentBlock('td');
261  $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
262  $this->tpl->parseCurrentBlock();
263  } else {
264  $this->tpl->setCurrentBlock('td');
265  $this->tpl->setVariable('VALUE', '&nbsp;');
266  $this->tpl->parseCurrentBlock();
267  }
268  break;
269  }
270  }
271  }
272 
273  $actions = new ilAdvancedSelectionListGUI();
274  $actions->setListTitle($DIC->language()->txt("actions"));
275  $actions->setAsynch(false);
276  $actions->setId($user_certificate_dto->getCertificateId());
277  $actions->addItem($DIC->language()->txt("mst_download_certificate"), '', $user_certificate_dto->getDownloadLink());
278 
279  $this->tpl->setVariable('ACTIONS', $actions->getHTML());
280  $this->tpl->parseCurrentBlock();
281  }
282 
283 
289  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $user_certificate_dto)
290  {
291  $col = 0;
292  foreach ($this->getFieldValuesForExport($user_certificate_dto) as $k => $v) {
293  $a_excel->setCell($a_row, $col, $v);
294  $col++;
295  }
296  }
297 
298 
303  protected function fillRowCSV($a_csv, $user_certificate_dto)
304  {
305  foreach ($this->getFieldValuesForExport($user_certificate_dto) as $k => $v) {
306  $a_csv->addColumn($v);
307  }
308  $a_csv->addRow();
309  }
310 
311 
317  protected function getFieldValuesForExport(UserCertificateDto $user_certificate_dto)
318  {
319  $propGetter = Closure::bind(function ($prop) {
320  return $this->$prop;
321  }, $user_certificate_dto, $user_certificate_dto);
322 
323  $field_values = array();
324  foreach ($this->getSelectedColumns() as $k => $v) {
325  switch ($k) {
326  case 'usr_assinged_orgus':
327  $field_values[$k] = ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_certificate_dto->getUserId());
328  break;
329  case 'issuedOnTimestamp':
330  $field_values[$k] = new ilDateTime($propGetter($k), IL_CAL_UNIX);
331  break;
332  default:
333  $field_values[$k] = strip_tags($propGetter($k));
334  break;
335  }
336  }
337 
338  return $field_values;
339  }
340 }
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.
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.
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.
$DIC
Definition: xapitoken.php:46
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
getExportMode()
Was export activated?
setEnableTitle($a_enabletitle)
Set Enable Title.
$cols
Definition: xhr_table.php:11