ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMStShowUserCoursesTableGUI.php
Go to the documentation of this file.
1<?php
2
4
5use Closure;
8use ilExcel;
11use ilLPStatus;
13use ilMyStaffGUI;
18use ilTable2GUI;
20
27{
28
32 protected $usr_id;
36 protected $filter = array();
40 protected $access;
41
43 protected $columnDefinition = null;
44
45
51 {
52 global $DIC;
53
54 $this->access = ilMyStaffAccess::getInstance();
55
56 $this->usr_id = $DIC->http()->request()->getQueryParams()['usr_id'];
57
58 $this->setPrefix('myst_su');
59 $this->setFormName('myst_su');
60 $this->setId('myst_su');
61
62 parent::__construct($parent_obj, $parent_cmd, '');
63 $this->setRowTemplate('tpl.list_user_courses_row.html', "Services/MyStaff");
64 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
65 ;
66 $this->setDefaultOrderDirection('desc');
67
68 $this->setShowRowsSelector(true);
69
70 $this->setEnableTitle(true);
71 $this->setDisableFilterHiding(true);
72 $this->setEnableNumInfo(true);
73
74 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
75
76 $this->setFilterCols(5);
77 $this->initFilter();
78 $this->addColumns();
79
80 $this->parseData();
81 }
82
83
87 protected function parseData()
88 {
89 global $DIC;
90
91 $this->setExternalSorting(true);
92 $this->setExternalSegmentation(true);
93 $this->setDefaultOrderField('crs_title');
94
95 $this->determineLimit();
97
98 $arr_usr_id = $this->access->getUsersForUserOperationAndContext($DIC->user()
100
101 $this->filter['usr_id'] = $this->usr_id;
102 $options = array(
103 'filters' => $this->filter,
104 'limit' => array(),
105 'count' => true,
106 'sort' => array(
107 'field' => $this->getOrderField(),
108 'direction' => $this->getOrderDirection(),
109 ),
110 );
111
112 $user_courses_fetcher = new ilMStShowUserCourses($DIC);
113 $count = $user_courses_fetcher->getData($arr_usr_id, $options);
114 $options['limit'] = array(
115 'start' => intval($this->getOffset()),
116 'end' => intval($this->getLimit()),
117 );
118 $options['count'] = false;
119 $data = $user_courses_fetcher->getData($arr_usr_id, $options);
120
121 $this->setMaxCount($count);
122 $this->setData($data);
123 }
124
125
129 public function initFilter()
130 {
131 global $DIC;
132
133 $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title");
134 $this->addFilterItem($item);
135 $item->readFromSession();
136 $this->filter['crs_title'] = $item->getValue();
137
138 // course members
139 $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course");
140 $item->setSelectText($DIC->language()->txt("mst_select_course"));
141 $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course"));
142 $item->setClickableTypes(array(ilMyStaffAccess::DEFAULT_CONTEXT));
143 $this->addFilterItem($item);
144 $item->readFromSession();
145 $item->setParent($this->getParentObject());
146 $this->filter["course"] = $item->getValue();
147
148 //membership status
149 $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status');
150 $item->setOptions(array(
151 "" => $DIC->language()->txt("mst_opt_all"),
152 ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'),
153 ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'),
154 ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'),
155 ));
156 $this->addFilterItem($item);
157 $item->readFromSession();
158 $this->filter["memb_status"] = $item->getValue();
159
160 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
161 //learning progress status
162 $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status');
163 //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0.
164 $item->setOptions(array(
165 "" => $DIC->language()->txt("mst_opt_all"),
170 ));
171 $this->addFilterItem($item);
172 $item->readFromSession();
173 $this->filter["lp_status"] = $item->getValue();
174 if ($this->filter["lp_status"]) {
175 $this->filter["lp_status"] = $this->filter["lp_status"] - 1;
176 }
177 }
178 }
179
180
184 public function getSelectableColumns()
185 {
186 global $DIC;
187
188 if ($this->columnDefinition !== null) {
190 }
191
192 $cols = array();
193
194 $cols['crs_title'] = array(
195 'txt' => $DIC->language()->txt('crs_title'),
196 'default' => true,
197 'width' => 'auto',
198 'sort_field' => 'crs_title',
199 );
200 $cols['usr_reg_status'] = array(
201 'txt' => $DIC->language()->txt('member_status'),
202 'default' => true,
203 'width' => 'auto',
204 'sort_field' => 'reg_status',
205 );
206 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
207 $cols['usr_lp_status'] = array(
208 'txt' => $DIC->language()->txt('learning_progress'),
209 'default' => true,
210 'width' => 'auto',
211 'sort_field' => 'lp_status',
212 );
213 }
214
215 $this->columnDefinition = $cols;
216
218 }
219
220
224 private function addColumns()
225 {
226 global $DIC;
227
228 foreach ($this->getSelectableColumns() as $k => $v) {
229 if ($this->isColumnSelected($k)) {
230 if (isset($v['sort_field'])) {
231 $sort = $v['sort_field'];
232 } else {
233 $sort = null;
234 }
235 $this->addColumn($v['txt'], $sort, $v['width']);
236 }
237 }
238 //Actions
239 if (!$this->getExportMode()) {
240 $this->addColumn($DIC->language()->txt('actions'));
241 }
242 }
243
244
248 public function fillRow($profile)
249 {
250 global $DIC;
251
252 $propGetter = Closure::bind(function ($prop) {
253 return $this->$prop;
254 }, $profile, $profile);
255
256 foreach ($this->getSelectableColumns() as $k => $v) {
257 if ($this->isColumnSelected($k)) {
258 switch ($k) {
259 case 'usr_reg_status':
260 $this->tpl->setCurrentBlock('td');
261 $this->tpl->setVariable('VALUE', $this->getSpaceOrValue(ilMStListCourse::getMembershipStatusText($profile->getUsrRegStatus())));
262 $this->tpl->parseCurrentBlock();
263 break;
264 case 'usr_lp_status':
265 $this->tpl->setCurrentBlock('td');
266 $this->tpl->setVariable('VALUE', $this->getSpaceOrValue(ilMyStaffGUI::getUserLpStatusAsHtml($profile)));
267 $this->tpl->parseCurrentBlock();
268 break;
269 default:
270 if ($propGetter($k) !== null) {
271 $this->tpl->setCurrentBlock('td');
272 $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
273 $this->tpl->parseCurrentBlock();
274 } else {
275 $this->tpl->setCurrentBlock('td');
276 $this->tpl->setVariable('VALUE', '&nbsp;');
277 $this->tpl->parseCurrentBlock();
278 }
279 break;
280 }
281 }
282 }
283
284 $actions = new ilAdvancedSelectionListGUI();
285 $actions->setListTitle($DIC->language()->txt("actions"));
286 $actions->setAsynch(true);
287 $actions->setId($profile->getUsrId() . "-" . $profile->getCrsRefId());
288
289 $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'mst_lco_usr_id', $profile->getUsrId());
290 $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'mst_lco_crs_ref_id', $profile->getCrsRefId());
291
292 $actions->setAsynchUrl(str_replace("\\", "\\\\", $DIC->ctrl()
293 ->getLinkTarget($this->parent_obj, ilMStShowUserCoursesGUI::CMD_GET_ACTIONS, "", true)));
294 $this->tpl->setVariable('ACTIONS', $actions->getHTML());
295 $this->tpl->parseCurrentBlock();
296 }
297
298
304 protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill)
305 {
306 $col = 0;
307 foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
308 $a_excel->setCell($a_row, $col, $v);
309 $col++;
310 }
311 }
312
313
318 protected function fillRowCSV($a_csv, $selected_skill)
319 {
320 foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
321 $a_csv->addColumn($v);
322 }
323 $a_csv->addRow();
324 }
325
326
330 protected function getFieldValuesForExport(ilMStListCourse $my_staff_course)
331 {
332 $propGetter = Closure::bind(function ($prop) {
333 return $this->$prop;
334 }, $my_staff_course, $my_staff_course);
335
336 $field_values = array();
337
338 foreach ($this->getSelectedColumns() as $k => $v) {
339 switch ($k) {
340 case 'usr_reg_status':
341 $field_values[$k] = ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus());
342 break;
343 case 'usr_lp_status':
344 $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course);
345 break;
346 default:
347 $field_values[$k] = strip_tags($propGetter($k));
348 break;
349 }
350 }
351
352 return $field_values;
353 }
354
355
356 protected function getSpaceOrValue(string $string)
357 {
358 if (!$this->getExportMode()) {
359 if (empty($string)) {
360 return "&nbsp";
361 }
362 }
363
364 return $string;
365 }
366}
An exception for terminatinating execution or to throw for unit testing.
__construct(ilMStShowUserCoursesGUI $parent_obj, $parent_cmd=ilMStShowUserCoursesGUI::CMD_INDEX)
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.
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_COMPLETED
const LP_STATUS_FAILED
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
Class ilMyStaffGUI.
static getUserLpStatusAsText(ilMStListCourse $my_staff_course)
static getUserLpStatusAsHtml(ilMStListCourse $my_staff_course)
static _enabledLearningProgress()
check wether learing progress is enabled or not
Class ilOrgUnitOperation.
This class represents a repository selector in a property form.
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.
getParentObject()
Get parent object.
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.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$DIC
Definition: xapitoken.php:46
$cols
Definition: xhr_table.php:11