ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMStListUsersTableGUI.php
Go to the documentation of this file.
1<?php
3
4use Closure;
7use ilExcel;
10use ilObjOrgUnit;
14use ilTable2GUI;
17
24{
25
29 protected $filter = array();
33 protected $access;
34
35
41 {
42 global $DIC;
43
44 $this->access = ilMyStaffAccess::getInstance();
45
46 $this->setPrefix('myst_lu');
47 $this->setFormName('myst_lu');
48 $this->setId('myst_lu');
49
50 parent::__construct($parent_obj, $parent_cmd, '');
51
52 $this->setRowTemplate('tpl.list_users_row.html', "Services/MyStaff");
53 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
54 $this->setDefaultOrderDirection('desc');
55
56 $this->setShowRowsSelector(true);
57
58 $this->setEnableTitle(true);
59 $this->setDisableFilterHiding(true);
60 $this->setEnableNumInfo(true);
61
62 $this->setExportFormats(array( self::EXPORT_EXCEL, self::EXPORT_CSV ));
63
64 $this->setFilterCols(4);
65 $this->initFilter();
66 $this->addColumns();
67
68 $this->parseData();
69 }
70
71
75 protected function parseData()
76 {
77 global $DIC;
78
79 $this->setExternalSorting(true);
80 $this->setExternalSegmentation(true);
81 $this->setDefaultOrderField('lastname');
82
83 $this->determineLimit();
85
86 //Permission Filter
87 $arr_usr_id = $this->access->getUsersForUser($DIC->user()->getId());
88
89 $options = array(
90 'filters' => $this->filter,
91 'limit' => array(),
92 'count' => true,
93 'sort' => array(
94 'field' => $this->getOrderField(),
95 'direction' => $this->getOrderDirection(),
96 ),
97 );
98
99 $list_users_fetcher = new ilMStListUsers($DIC);
100 $count = $list_users_fetcher->getData($arr_usr_id, $options);
101 $options['limit'] = array(
102 'start' => intval($this->getOffset()),
103 'end' => intval($this->getLimit()),
104 );
105 $options['count'] = false;
106 $data = $list_users_fetcher->getData($arr_usr_id, $options);
107
108 $this->setMaxCount($count);
109 $this->setData($data);
110 }
111
112
116 public function initFilter()
117 {
118 global $DIC;
119
120 // User name, login, email filter
121 $item = new ilTextInputGUI($DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language()
122 ->txt("name"), "user");
123 //$item->setDataSource($DIC->ctrl()->getLinkTarget($this->getParentObject(),"addUserAutoComplete", "", true));
124 //$item->setSize(20);
125 //$item->setSubmitFormOnEnter(true);
126 $this->addFilterItem($item);
127 $item->readFromSession();
128 $this->filter['user'] = $item->getValue();
129
130 if (ilUserSearchOptions::_isEnabled('org_units')) {
133 $nodes = $tree->getAllChildren($root);
135 $options[0] = $DIC->language()->txt('mst_opt_all');
136 foreach ($paths as $org_ref_id => $path) {
137 $options[$org_ref_id] = $path;
138 }
139 $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
140 $item->setOptions($options);
141 $item->addCustomAttribute("style='width:100%'");
142 $this->addFilterItem($item);
143 $item->readFromSession();
144 $this->filter['org_unit'] = $item->getValue();
145 }
146 }
147
148
152 public function getSelectableColumns()
153 {
154 $arr_fields_without_table_sort = array(
155 'org_units',
156 'interests_general',
157 'interests_help_offered',
158 'interests_help_looking',
159 );
160 $cols = array();
161 foreach (ilUserSearchOptions::getSelectableColumnInfo() as $key => $col) {
162 $cols[$key] = $col;
163 if (!in_array($key, $arr_fields_without_table_sort)) {
164 $cols[$key]['sort_field'] = $key;
165 }
166 }
167
168 return $cols;
169 }
170
171
175 private function addColumns()
176 {
177 global $DIC;
178
179 //User Profile Picture
180 if (!$this->getExportMode()) {
181 $this->addColumn('');
182 }
183
184 foreach ($this->getSelectableColumns() as $k => $v) {
185 if ($this->isColumnSelected($k)) {
186 if (isset($v['sort_field'])) {
187 $sort = $v['sort_field'];
188 } else {
189 $sort = null;
190 }
191 $this->addColumn($v['txt'], $sort, $v['width']);
192 }
193 }
194 //Actions
195 if (!$this->getExportMode()) {
196 $this->addColumn($DIC->language()->txt('actions'));
197 }
198 }
199
200
204 public function fillRow($my_staff_user)
205 {
206 global $DIC;
207
208 $propGetter = Closure::bind(function ($prop) {
209 return $this->$prop;
210 }, $my_staff_user, $my_staff_user);
211
212 //Avatar
213 $this->tpl->setCurrentBlock('user_profile_picture');
214 $f = $DIC->ui()->factory();
215 $renderer = $DIC->ui()->renderer();
216 $il_obj_user = $my_staff_user->returnIlUserObj();
217 $avatar = $f->image()->standard($il_obj_user->getPersonalPicturePath('small'), $il_obj_user->getPublicName());
218 $this->tpl->setVariable('user_profile_picture', $renderer->render($avatar));
219 $this->tpl->parseCurrentBlock();
220
221 foreach ($this->getSelectableColumns() as $k => $v) {
222 if ($this->isColumnSelected($k)) {
223 switch ($k) {
224 case 'org_units':
225 $this->tpl->setCurrentBlock('td');
226 $this->tpl->setVariable('VALUE', strval(ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($my_staff_user->getUsrId())));
227 $this->tpl->parseCurrentBlock();
228 break;
229 case 'gender':
230 $this->tpl->setCurrentBlock('td');
231 $this->tpl->setVariable('VALUE', $DIC->language()->txt('gender_' . $my_staff_user->getGender()));
232 $this->tpl->parseCurrentBlock();
233 break;
234 case 'interests_general':
235 $this->tpl->setCurrentBlock('td');
236 $this->tpl->setVariable('VALUE', ($my_staff_user->returnIlUserObj()
237 ->getGeneralInterestsAsText() ? $my_staff_user->returnIlUserObj()->getGeneralInterestsAsText() : '&nbsp;'));
238 $this->tpl->parseCurrentBlock();
239 break;
240 case 'interests_help_offered':
241 $this->tpl->setCurrentBlock('td');
242 $this->tpl->setVariable('VALUE', ($my_staff_user->returnIlUserObj()
243 ->getOfferingHelpAsText() ? $my_staff_user->returnIlUserObj()->getOfferingHelpAsText() : '&nbsp;'));
244 $this->tpl->parseCurrentBlock();
245 break;
246 case 'interests_help_looking':
247 $this->tpl->setCurrentBlock('td');
248 $this->tpl->setVariable('VALUE', ($my_staff_user->returnIlUserObj()
249 ->getLookingForHelpAsText() ? $my_staff_user->returnIlUserObj()->getLookingForHelpAsText() : '&nbsp;'));
250 $this->tpl->parseCurrentBlock();
251 break;
252 default:
253 if ($propGetter($k) !== null) {
254 $this->tpl->setCurrentBlock('td');
255 $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
256 $this->tpl->parseCurrentBlock();
257 } else {
258 $this->tpl->setCurrentBlock('td');
259 $this->tpl->setVariable('VALUE', '&nbsp;');
260 $this->tpl->parseCurrentBlock();
261 }
262 break;
263 }
264 }
265 }
266
267 $actions = new ilAdvancedSelectionListGUI();
268 $actions->setListTitle($DIC->language()->txt("actions"));
269 $actions->setAsynch(true);
270 $actions->setId($my_staff_user->getUsrId());
271
272 $DIC->ctrl()->setParameterByClass(ilMStListUsersGUI::class, 'mst_lus_usr_id', $my_staff_user->getUsrId());
273
274 $actions->setAsynchUrl(str_replace("\\", "\\\\", $DIC->ctrl()
275 ->getLinkTarget($this->parent_obj, ilMStListUsersGUI::CMD_GET_ACTIONS, "", true)));
276 $this->tpl->setVariable('ACTIONS', $actions->getHTML());
277 $this->tpl->parseCurrentBlock();
278 }
279
280
286 private function getProfileBackUrl()
287 {
288 global $DIC;
289
290 return rawurlencode($DIC->ctrl()->getLinkTargetByClass(strtolower(ilMyStaffGUI::class), ilMyStaffGUI::CMD_INDEX));
291 }
292
293
299 protected function fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_user)
300 {
301 $col = 0;
302 foreach ($this->getFieldValuesForExport($my_staff_user) as $k => $v) {
303 $a_excel->setCell($a_row, $col, $v);
304 $col++;
305 }
306 }
307
308
313 protected function fillRowCSV($a_csv, $my_staff_user)
314 {
315 foreach ($this->getFieldValuesForExport($my_staff_user) as $k => $v) {
316 $a_csv->addColumn($v);
317 }
318 $a_csv->addRow();
319 }
320
321
327 protected function getFieldValuesForExport(ilMStListUser $my_staff_user)
328 {
329 global $DIC;
330
331 $propGetter = Closure::bind(function ($prop) {
332 return $this->$prop;
333 }, $my_staff_user, $my_staff_user);
334
335 $field_values = array();
336
337 foreach ($this->getSelectedColumns() as $k => $v) {
338 switch ($k) {
339 case 'org_units':
340 $field_values[$k] = ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($my_staff_user->getUsrId());
341 break;
342 case 'gender':
343 $field_values[$k] = $DIC->language()->txt('gender_' . $my_staff_user->getGender());
344 break;
345 case 'interests_general':
346 $field_values[$k] = $my_staff_user->returnIlUserObj()->getGeneralInterestsAsText();
347 break;
348 case 'interests_help_offered':
349 $field_values[$k] = $my_staff_user->returnIlUserObj()->getOfferingHelpAsText();
350 break;
351 case 'interests_help_looking':
352 $field_values[$k] = $my_staff_user->returnIlUserObj()->getLookingForHelpAsText();
353 break;
354 default:
355 $field_values[$k] = strip_tags($propGetter($k));
356 break;
357 }
358 }
359
360 return $field_values;
361 }
362}
An exception for terminatinating execution or to throw for unit testing.
__construct(ilMStListUsersGUI $parent_obj, $parent_cmd=ilMStListUsersGUI::CMD_INDEX)
fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_user)
User interface class for advanced drop-down selection lists.
Helper class to generate CSV files.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
Class ilMStListUsersGUI.
Class ilObjOrgUnitTree Implements a singleton pattern for caching.
Class ilObjOrgUnit.
static getRootOrgRefId()
Class ilOrgUnitPathStorage.
static getTextRepresentationOfOrgUnits($sort_by_title=true)
Get ref id path array.
This class represents a selection list property in a property form.
Class ilTable2GUI.
getExportMode()
Was export activated?
getSelectedColumns()
Get selected columns.
setDisableFilterHiding($a_val=true)
Set disable filter hiding.
setExternalSorting($a_val)
Set external sorting.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setExportFormats(array $formats)
Set available export formats.
setPrefix($a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
setData($a_data)
set table data @access public
setEnableTitle($a_enabletitle)
Set Enable Title.
setEnableNumInfo($a_val)
Set enable num info.
getLimit()
Get limit.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
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.
getOffset()
Get offset.
setExternalSegmentation($a_val)
Set external segmentation.
setId($a_val)
Set id.
setFormName($a_formname="")
Set Form name.
setFilterCols($a_val)
Set filter columns.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
determineLimit()
Determine the limit.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
isColumnSelected($a_col)
Is given column selected?
getOrderDirection()
Get order direction.
setMaxCount($a_max_count)
set max.
This class represents a text property in a property form.
static getSelectableColumnInfo($a_admin=false)
Get info of searchable fields for selectable columns in table gui.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46
$cols
Definition: xhr_table.php:11