ILIAS  release_7 Revision v7.30-3-g800a261c036
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;
42 protected $columnDefinition = null;
46 protected $orgu_names = null;
47
53 {
54 global $DIC;
55
56 $this->access = ilMyStaffAccess::getInstance();
57
58 $this->usr_id = $DIC->http()->request()->getQueryParams()['usr_id'];
59
60 $this->setPrefix('myst_su');
61 $this->setFormName('myst_su');
62 $this->setId('myst_su');
63
64 parent::__construct($parent_obj, $parent_cmd, '');
65 $this->setRowTemplate('tpl.list_user_courses_row.html', "Services/MyStaff");
66 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
67 ;
68 $this->setDefaultOrderDirection('desc');
69
70 $this->setShowRowsSelector(true);
71
72 $this->setEnableTitle(true);
73 $this->setDisableFilterHiding(true);
74 $this->setEnableNumInfo(true);
75
76 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
77
78 $this->setFilterCols(5);
79 $this->initFilter();
80 $this->addColumns();
81
82 $this->parseData();
83 }
84
85
89 protected function parseData()
90 {
91 global $DIC;
92
93 $this->setExternalSorting(true);
94 $this->setExternalSegmentation(true);
95 $this->setDefaultOrderField('crs_title');
96
97 $this->determineLimit();
99
100 $arr_usr_id = $this->access->getUsersForUserOperationAndContext($DIC->user()
102
103 $this->filter['usr_id'] = $this->usr_id;
104 $options = array(
105 'filters' => $this->filter,
106 'limit' => array(),
107 'count' => true,
108 'sort' => array(
109 'field' => $this->getOrderField(),
110 'direction' => $this->getOrderDirection(),
111 ),
112 );
113
114 $user_courses_fetcher = new ilMStShowUserCourses($DIC);
115 $count = $user_courses_fetcher->getData($arr_usr_id, $options);
116 $options['limit'] = array(
117 'start' => intval($this->getOffset()),
118 'end' => intval($this->getLimit()),
119 );
120 $options['count'] = false;
121 $data = $user_courses_fetcher->getData($arr_usr_id, $options);
122
123 $this->setMaxCount($count);
124 $this->setData($data);
125 }
126
127
131 public function initFilter()
132 {
133 global $DIC;
134
135 $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title");
136 $this->addFilterItem($item);
137 $item->readFromSession();
138 $this->filter['crs_title'] = $item->getValue();
139
140 // course members
141 $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course");
142 $item->setSelectText($DIC->language()->txt("mst_select_course"));
143 $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course"));
144 $item->setClickableTypes(array(ilMyStaffAccess::COURSE_CONTEXT));
145 $this->addFilterItem($item);
146 $item->readFromSession();
147 $item->setParent($this->getParentObject());
148 $this->filter["course"] = $item->getValue();
149
150 //membership status
151 $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status');
152 $item->setOptions(array(
153 "" => $DIC->language()->txt("mst_opt_all"),
154 ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'),
155 ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'),
156 ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'),
157 ));
158 $this->addFilterItem($item);
159 $item->readFromSession();
160 $this->filter["memb_status"] = $item->getValue();
161
162 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
163 //learning progress status
164 $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status');
165 //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0.
166 $item->setOptions(array(
167 "" => $DIC->language()->txt("mst_opt_all"),
172 ));
173 $this->addFilterItem($item);
174 $item->readFromSession();
175 $this->filter["lp_status"] = $item->getValue();
176 $this->filter["lp_status"] = (int) $this->filter["lp_status"] - 1;
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 protected function getTextRepresentationOfOrgUnits() : array
245 {
246 if (isset($this->orgu_names)) {
247 return $this->orgu_names;
248 }
249
251 }
252
253
257 public function fillRow($profile)
258 {
259 global $DIC;
260
261 $propGetter = Closure::bind(function ($prop) {
262 return $this->$prop;
263 }, $profile, $profile);
264
265 foreach ($this->getSelectedColumns() as $k => $v) {
266 switch ($k) {
267 case 'usr_reg_status':
268 $this->tpl->setCurrentBlock('td');
269 $this->tpl->setVariable('VALUE', $this->getSpaceOrValue(ilMStListCourse::getMembershipStatusText($profile->getUsrRegStatus())));
270 $this->tpl->parseCurrentBlock();
271 break;
272 case 'usr_lp_status':
273 $this->tpl->setCurrentBlock('td');
274 $this->tpl->setVariable('VALUE', $this->getSpaceOrValue(ilMyStaffGUI::getUserLpStatusAsHtml($profile)));
275 $this->tpl->parseCurrentBlock();
276 break;
277 default:
278 if ($propGetter($k) !== null) {
279 $this->tpl->setCurrentBlock('td');
280 $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
281 $this->tpl->parseCurrentBlock();
282 } else {
283 $this->tpl->setCurrentBlock('td');
284 $this->tpl->setVariable('VALUE', '&nbsp;');
285 $this->tpl->parseCurrentBlock();
286 }
287 break;
288 }
289 }
290
291 $actions = new ilAdvancedSelectionListGUI();
292 $actions->setListTitle($DIC->language()->txt("actions"));
293 $actions->setId($profile->getUsrId() . "-" . $profile->getCrsRefId());
294
295 $mst_lco_usr_id = $profile->getUsrId();
296 $mst_lco_crs_ref_id = $profile->getCrsRefId();
297
298 if ($DIC->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) {
299 $link = \ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::COURSE_CONTEXT);
300 $actions->addItem(\ilObject2::_lookupTitle(\ilObject2::_lookupObjectId($mst_lco_crs_ref_id)), '', $link);
301 };
302
303 foreach (
304 \ilOrgUnitUserAssignment::innerjoin('object_reference', 'orgu_id', 'ref_id')->where(array(
305 'user_id' => $mst_lco_usr_id,
306 'object_reference.deleted' => null
307 ), array('user_id' => '=', 'object_reference.deleted' => '!='))->get() as $org_unit_assignment
308 ) {
309 if ($DIC->access()->checkAccess("read", "", $org_unit_assignment->getOrguId())) {
310 $org_units = $this->getTextRepresentationOfOrgUnits();
311 $link = \ilLink::_getStaticLink($org_unit_assignment->getOrguId(), 'orgu');
312 $actions->addItem($org_units[$org_unit_assignment->getOrguId()], '', $link);
313 }
314 }
315
316 $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'mst_lco_usr_id', $mst_lco_usr_id);
317 $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'mst_lco_crs_ref_id', $mst_lco_crs_ref_id);
318
319 $actions = ilMyStaffGUI::extendActionMenuWithUserActions(
320 $actions,
321 $mst_lco_usr_id,
322 rawurlencode($this->ctrl->getLinkTargetByClass(
323 "ilMStShowUserCoursesGUI",
325 ))
326 );
327
328 $this->tpl->setVariable('ACTIONS', $actions->getHTML());
329 $this->tpl->parseCurrentBlock();
330 }
331
332
338 protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill)
339 {
340 $col = 0;
341 foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
342 $a_excel->setCell($a_row, $col, $v);
343 $col++;
344 }
345 }
346
347
352 protected function fillRowCSV($a_csv, $selected_skill)
353 {
354 foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
355 $a_csv->addColumn($v);
356 }
357 $a_csv->addRow();
358 }
359
360
364 protected function getFieldValuesForExport(ilMStListCourse $my_staff_course)
365 {
366 $propGetter = Closure::bind(function ($prop) {
367 return $this->$prop;
368 }, $my_staff_course, $my_staff_course);
369
370 $field_values = array();
371
372 foreach ($this->getSelectedColumns() as $k => $v) {
373 switch ($k) {
374 case 'usr_reg_status':
375 $field_values[$k] = ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus());
376 break;
377 case 'usr_lp_status':
378 $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course);
379 break;
380 default:
381 $field_values[$k] = strip_tags($propGetter($k));
382 break;
383 }
384 }
385
386 return $field_values;
387 }
388
389
390 protected function getSpaceOrValue(string $string)
391 {
392 if (!$this->getExportMode()) {
393 if (empty($string)) {
394 return "&nbsp";
395 }
396 }
397
398 return $string;
399 }
400}
static innerjoin($tablename, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)
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
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
Class ilOrgUnitOperation.
static getTextRepresentationOfOrgUnits($sort_by_title=true)
Get ref id path array.
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.
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$cols
Definition: xhr_table.php:11