ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMStListCompetencesSkillsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use Closure;
7 use ilCSVWriter;
8 use ilExcel;
17 use ilTable2GUI;
18 use ilTextInputGUI;
20 
27 {
28 
32  protected $filter = array();
36  protected $access;
40  protected $dic;
41 
42 
48  public function __construct($parent_obj, string $parent_cmd, Container $dic)
49  {
50  $this->dic = $dic;
51  $this->access = ilMyStaffAccess::getInstance();
52 
53  $this->setPrefix('myst_cs');
54  $this->setFormName('myst_cs');
55  $this->setId('myst_cs');
56 
57  parent::__construct($parent_obj, $parent_cmd, '');
58 
59  $this->setRowTemplate('tpl.list_skills_row.html', "Services/MyStaff");
60  $this->setFormAction($this->dic->ctrl()->getFormAction($parent_obj));
61  $this->setDefaultOrderDirection('desc');
62 
63  $this->setShowRowsSelector(true);
64 
65  $this->setEnableTitle(true);
66  $this->setDisableFilterHiding(true);
67  $this->setEnableNumInfo(true);
68 
69  $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
70 
71  $this->setFilterCols(5);
72  $this->initFilter();
73 
74  $this->addColumns();
75 
76  $this->parseData();
77  }
78 
79 
83  protected function parseData()
84  {
85  $this->setExternalSorting(true);
86  $this->setExternalSegmentation(true);
87  $this->setDefaultOrderField('skill_title');
88 
89  $this->determineLimit();
90  $this->determineOffsetAndOrder();
91 
92  $options = array(
93  'filters' => $this->filter,
94  'limit' => array(),
95  'count' => true,
96  'sort' => array(
97  'field' => $this->getOrderField(),
98  'direction' => $this->getOrderDirection(),
99  ),
100  );
101 
102 
103  $skills_fetcher = new ilMStListCompetencesSkills($this->dic);
104  $count = $skills_fetcher->getData($options);
105  $options['limit'] = array(
106  'start' => intval($this->getOffset()),
107  'end' => intval($this->getLimit()),
108  );
109  $options['count'] = false;
110  $data = $skills_fetcher->getData($options);
111  $this->setMaxCount($count);
112  $this->setData($data);
113  }
114 
115 
119  public function initFilter()
120  {
121  // skill
122  $item = new ilTextInputGUI($this->dic->language()->txt("skmg_skill"), 'skill');
123  $this->addFilterItem($item);
124  $item->readFromSession();
125  $this->filter['skill'] = $item->getValue();
126 
127  // skill level
128  $item = new ilTextInputGUI($this->dic->language()->txt("skmg_skill_level"), 'skill_level');
129  $this->addFilterItem($item);
130  $item->readFromSession();
131  $this->filter['skill_level'] = $item->getValue();
132 
133  //user
134  $item = new ilTextInputGUI($this->dic->language()->txt("login") . "/" . $this->dic->language()->txt("email") . "/" . $this->dic->language()
135  ->txt("name"), "user");
136 
137  $this->addFilterItem($item);
138  $item->readFromSession();
139  $this->filter['user'] = $item->getValue();
140 
141  // orgunits
142  if (ilUserSearchOptions::_isEnabled('org_units')) {
144  $options[0] = $this->dic->language()->txt('mst_opt_all');
145  foreach ($paths as $org_ref_id => $path) {
146  $options[$org_ref_id] = $path;
147  }
148  $item = new ilSelectInputGUI($this->dic->language()->txt('obj_orgu'), 'org_unit');
149  $item->setOptions($options);
150  $this->addFilterItem($item);
151  $item->readFromSession();
152  $this->filter['org_unit'] = $item->getValue();
153  }
154  }
155 
156 
160  public function getSelectableColumns()
161  {
162  $cols = array();
163 
164  $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
165 
166  $cols['skill_title'] = array(
167  'txt' => $this->dic->language()->txt('skmg_skill'),
168  'default' => true,
169  'width' => 'auto',
170  'sort_field' => 'skill_title',
171  );
172  $cols['skill_level'] = array(
173  'txt' => $this->dic->language()->txt('skmg_skill_level'),
174  'default' => true,
175  'width' => 'auto',
176  'sort_field' => 'skill_level',
177  );
178 
179  if ($arr_searchable_user_columns['login']) {
180  $cols['login'] = array(
181  'txt' => $this->dic->language()->txt('login'),
182  'default' => true,
183  'width' => 'auto',
184  'sort_field' => 'login',
185  );
186  }
187  if ($arr_searchable_user_columns['firstname']) {
188  $cols['first_name'] = array(
189  'txt' => $this->dic->language()->txt('firstname'),
190  'default' => true,
191  'width' => 'auto',
192  'sort_field' => 'firstname',
193  );
194  }
195  if ($arr_searchable_user_columns['lastname']) {
196  $cols['last_name'] = array(
197  'txt' => $this->dic->language()->txt('lastname'),
198  'default' => true,
199  'width' => 'auto',
200  'sort_field' => 'lastname',
201  );
202  }
203 
204  return $cols;
205  }
206 
207 
211  private function addColumns()
212  {
213  foreach ($this->getSelectableColumns() as $k => $v) {
214  if ($this->isColumnSelected($k)) {
215  if (isset($v['sort_field'])) {
216  $sort = $v['sort_field'];
217  } else {
218  $sort = null;
219  }
220  $this->addColumn($v['txt'], $sort, $v['width']);
221  }
222  }
223 
224  //Actions
225  if (!$this->getExportMode()) {
226  $this->addColumn($this->dic->language()->txt('actions'));
227  }
228  }
229 
230 
234  public function fillRow($profile)
235  {
236  $propGetter = Closure::bind(function ($prop) {
237  return $this->$prop;
238  }, $profile, $profile);
239 
240  foreach ($this->getSelectableColumns() as $k => $v) {
241  if ($this->isColumnSelected($k)) {
242  if ($propGetter($k) !== null) {
243  $this->tpl->setCurrentBlock('td');
244  $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
245  $this->tpl->parseCurrentBlock();
246  } else {
247  $this->tpl->setCurrentBlock('td');
248  $this->tpl->setVariable('VALUE', '&nbsp;');
249  $this->tpl->parseCurrentBlock();
250  }
251  }
252  }
253 
254  $actions = new ilAdvancedSelectionListGUI();
255  $actions->setListTitle($this->dic->language()->txt("actions"));
256  $actions->setAsynch(true);
257 
258  $this->dic->ctrl()->setParameterByClass(get_class($this->parent_obj), 'mst_lcom_usr_id', $profile->getUserId());
259 
260  $actions->setAsynchUrl(str_replace("\\", "\\\\", $this->dic->ctrl()
261  ->getLinkTarget($this->parent_obj, ilMStListCompetencesSkillsGUI::CMD_GET_ACTIONS, "", true)));
262  $this->tpl->setVariable('ACTIONS', $actions->getHTML());
263  $this->tpl->parseCurrentBlock();
264  }
265 
266 
272  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill)
273  {
274  $col = 0;
275  foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
276  $a_excel->setCell($a_row, $col, $v);
277  $col++;
278  }
279  }
280 
281 
286  protected function fillRowCSV($a_csv, $selected_skill)
287  {
288  foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
289  $a_csv->addColumn($v);
290  }
291  $a_csv->addRow();
292  }
293 
294 
300  protected function getFieldValuesForExport(ilMStListCompetencesSkill $selected_skill)
301  {
302  $propGetter = Closure::bind(function ($prop) {
303  return $this->$prop;
304  }, $selected_skill, $selected_skill);
305 
306  $field_values = array();
307  foreach ($this->getSelectedColumns() as $k => $v) {
308  switch ($k) {
309  default:
310  $field_values[$k] = strip_tags($propGetter($k));
311  break;
312  }
313  }
314 
315  return $field_values;
316  }
317 }
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.
getOrderDirection()
Get order direction.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:17
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.
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.
setMaxCount($a_max_count)
set max.
getExportMode()
Was export activated?
setEnableTitle($a_enabletitle)
Set Enable Title.
$cols
Definition: xhr_table.php:11