ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilMStShowUserCoursesTableGUI.php
Go to the documentation of this file.
1 <?php
2 
9 {
10 
14  protected $usr_id;
18  protected $filter = array();
22  protected $access;
23 
24 
30  {
31  global $DIC;
32 
33  $this->access = ilMyStaffAccess::getInstance();
34 
35  $this->usr_id = $DIC->http()->request()->getQueryParams()['usr_id'];
36 
37  $this->setPrefix('myst_su');
38  $this->setFormName('myst_su');
39  $this->setId('myst_su');
40 
41  parent::__construct($parent_obj, $parent_cmd, '');
42  $this->setRowTemplate('tpl.list_user_courses_row.html', "Services/MyStaff");
43  $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
44  ;
45  $this->setDefaultOrderDirection('desc');
46 
47  $this->setShowRowsSelector(true);
48 
49  $this->setEnableTitle(true);
50  $this->setDisableFilterHiding(true);
51  $this->setEnableNumInfo(true);
52 
53  $this->setExportFormats(array( self::EXPORT_EXCEL, self::EXPORT_CSV ));
54 
55  $this->setFilterCols(5);
56  $this->initFilter();
57  $this->addColumns();
58 
59  $this->parseData();
60  }
61 
62 
66  protected function parseData()
67  {
68  global $DIC;
69 
70  $this->setExternalSorting(true);
71  $this->setExternalSegmentation(true);
72  $this->setDefaultOrderField('crs_title');
73 
74  $this->determineLimit();
75  $this->determineOffsetAndOrder();
76 
77  $arr_usr_id = $this->access->getUsersForUserOperationAndContext($DIC->user()
79 
80  $this->filter['usr_id'] = $this->usr_id;
81  $options = array(
82  'filters' => $this->filter,
83  'limit' => array(),
84  'count' => true,
85  'sort' => array(
86  'field' => $this->getOrderField(),
87  'direction' => $this->getOrderDirection(),
88  ),
89  );
90  $count = ilMStShowUserCourses::getData($arr_usr_id, $options);
91  $options['limit'] = array(
92  'start' => intval($this->getOffset()),
93  'end' => intval($this->getLimit()),
94  );
95  $options['count'] = false;
97 
98  $this->setMaxCount($count);
99  $this->setData($data);
100  }
101 
102 
106  public function initFilter()
107  {
108  global $DIC;
109 
110  $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title");
111  $this->addFilterItem($item);
112  $item->readFromSession();
113  $this->filter['crs_title'] = $item->getValue();
114 
115  // course members
116  $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course");
117  $item->setSelectText($DIC->language()->txt("mst_select_course"));
118  $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course"));
119  $item->setClickableTypes(array( ilMyStaffAccess::DEFAULT_CONTEXT ));
120  $this->addFilterItem($item);
121  $item->readFromSession();
122  $item->setParent($this->getParentObject());
123  $this->filter["course"] = $item->getValue();
124 
125  //membership status
126  $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status');
127  $item->setOptions(array(
128  "" => $DIC->language()->txt("mst_opt_all"),
129  ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'),
130  ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'),
131  ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'),
132  ));
133  $this->addFilterItem($item);
134  $item->readFromSession();
135  $this->filter["memb_status"] = $item->getValue();
136 
137  if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
138  //learning progress status
139  $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status');
140  //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0.
141  $item->setOptions(array(
142  "" => $DIC->language()->txt("mst_opt_all"),
147  ));
148  $this->addFilterItem($item);
149  $item->readFromSession();
150  $this->filter["lp_status"] = $item->getValue();
151  if ($this->filter["lp_status"]) {
152  $this->filter["lp_status"] = $this->filter["lp_status"] - 1;
153  }
154  }
155  }
156 
157 
161  public function getSelectableColumns()
162  {
163  global $DIC;
164 
165  $cols = array();
166 
167  $cols['crs_title'] = array(
168  'txt' => $DIC->language()->txt('crs_title'),
169  'default' => true,
170  'width' => 'auto',
171  'sort_field' => 'crs_title',
172  );
173  $cols['usr_reg_status'] = array(
174  'txt' => $DIC->language()->txt('member_status'),
175  'default' => true,
176  'width' => 'auto',
177  'sort_field' => 'reg_status',
178  );
179  if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
180  $cols['usr_lp_status'] = array(
181  'txt' => $DIC->language()->txt('learning_progress'),
182  'default' => true,
183  'width' => 'auto',
184  'sort_field' => 'lp_status',
185  );
186  }
187 
188  return $cols;
189  }
190 
191 
195  private function addColumns()
196  {
197  foreach ($this->getSelectableColumns() as $k => $v) {
198  if ($this->isColumnSelected($k)) {
199  if (isset($v['sort_field'])) {
200  $sort = $v['sort_field'];
201  } else {
202  $sort = null;
203  }
204  $this->addColumn($v['txt'], $sort, $v['width']);
205  }
206  }
207  }
208 
209 
213  public function fillRow($my_staff_course)
214  {
215  $propGetter = Closure::bind(function ($prop) {
216  return $this->$prop;
217  }, $my_staff_course, $my_staff_course);
218 
219  foreach ($this->getSelectableColumns() as $k => $v) {
220  if ($this->isColumnSelected($k)) {
221  switch ($k) {
222  case 'usr_reg_status':
223  $this->tpl->setCurrentBlock('td');
224  $this->tpl->setVariable('VALUE', ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus()));
225  $this->tpl->parseCurrentBlock();
226  break;
227  case 'usr_lp_status':
228  $this->tpl->setCurrentBlock('td');
229  $this->tpl->setVariable('VALUE', ilMyStaffGUI::getUserLpStatusAsHtml($my_staff_course));
230  $this->tpl->parseCurrentBlock();
231  break;
232  default:
233  if ($propGetter($k) !== null) {
234  $this->tpl->setCurrentBlock('td');
235  $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
236  $this->tpl->parseCurrentBlock();
237  } else {
238  $this->tpl->setCurrentBlock('td');
239  $this->tpl->setVariable('VALUE', '&nbsp;');
240  $this->tpl->parseCurrentBlock();
241  }
242  break;
243  }
244  }
245  }
246  }
247 
248 
254  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_course)
255  {
256  $col = 0;
257  foreach ($this->getFieldValuesForExport($my_staff_course) as $k => $v) {
258  $a_excel->setCell($a_row, $col, $v);
259  $col++;
260  }
261  }
262 
263 
268  protected function fillRowCSV($a_csv, $my_staff_course)
269  {
270  foreach ($this->getFieldValuesForExport($my_staff_course) as $k => $v) {
271  $a_csv->addColumn($v);
272  }
273  $a_csv->addRow();
274  }
275 
276 
280  protected function getFieldValuesForExport(ilMStListCourse $my_staff_course)
281  {
282  $propGetter = Closure::bind(function ($prop) {
283  return $this->$prop;
284  }, $my_staff_course, $my_staff_course);
285 
286  $field_values = array();
287 
288  foreach ($this->getSelectedColumns() as $k => $v) {
289  switch ($k) {
290  case 'usr_reg_status':
291  $field_values[$k] = ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus());
292  break;
293  case 'usr_lp_status':
294  $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course);
295  break;
296  default:
297  $field_values[$k] = strip_tags($propGetter($k));
298  break;
299  }
300  }
301 
302  return $field_values;
303  }
304 }
const LP_STATUS_COMPLETED_NUM
static getData(array $arr_usr_ids=array(), array $options=array())
Class ilMStListCourse.
setExternalSorting($a_val)
Set external sorting.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setExportFormats(array $formats)
Set available export formats.
This class represents a selection list property in a property form.
global $DIC
Definition: saml.php:7
setEnableNumInfo($a_val)
Set enable num info.
const LP_STATUS_NOT_ATTEMPTED
setFilterCols($a_val)
Set filter columns.
setExternalSegmentation($a_val)
Set external segmentation.
const LP_STATUS_IN_PROGRESS_NUM
__construct(ilMStShowUserGUI $parent_obj, $parent_cmd=ilMStShowUserGUI::CMD_INDEX)
Class ilMStShowUserGUI.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
determineLimit()
Determine the limit.
getOrderDirection()
Get order direction.
static getUserLpStatusAsHtml(ilMStListCourse $my_staff_course)
fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_course)
getParentObject()
Get parent object.
setId($a_val)
Set id.
const LP_STATUS_IN_PROGRESS
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
static _enabledLearningProgress()
check wether learing progress is enabled or not
const LP_STATUS_FAILED
Class ilTable2GUI.
getOffset()
Get offset.
This class represents a repository selector in a property form.
setDisableFilterHiding($a_val=true)
Set disable filter hiding.
This class represents a text property in a property form.
setPrefix($a_prefix)
static getUserLpStatusAsText(ilMStListCourse $my_staff_course)
getSelectedColumns()
Get selected columns.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
setOptions($a_options)
Set Options.
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.
const LP_STATUS_NOT_ATTEMPTED_NUM
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setFormName($a_formname="")
Set Form name.
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.
static getMembershipStatusText($status)
getFieldValuesForExport(ilMStListCourse $my_staff_course)
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
Class ilMStShowUserCoursesTableGUI.
setEnableTitle($a_enabletitle)
Set Enable Title.
const LP_STATUS_COMPLETED
$cols
Definition: xhr_table.php:11
const LP_STATUS_FAILED_NUM