ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilStudyProgrammeMembersTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2015 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once("Services/Table/classes/class.ilTable2GUI.php");
6 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
7 require_once("Modules/StudyProgramme/classes/model/class.ilStudyProgrammeProgress.php");
8 require_once("Modules/StudyProgramme/classes/model/class.ilStudyProgrammeAssignment.php");
9 require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
10 require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
11 require_once("Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
12 
21 {
22  protected $prg_obj_id;
23  protected $prg_ref_id;
24 
29 
30  public function __construct($a_prg_obj_id, $a_prg_ref_id, $a_parent_obj, $a_parent_cmd = "", $a_template_context = "", \ilStudyProgrammeUserProgressDB $sp_user_progress_db)
31  {
32  $this->setId("sp_member_list");
33  parent::__construct($a_parent_obj, $a_parent_cmd, $a_template_context);
34 
35  $this->prg_obj_id = $a_prg_obj_id;
36  $this->prg_ref_id = $a_prg_ref_id;
37  $this->prg_has_lp_children = $a_parent_obj->getStudyProgramme()->hasLPChildren();
38 
39  global $DIC;
40  $ilCtrl = $DIC['ilCtrl'];
41  $lng = $DIC['lng'];
42  $ilDB = $DIC['ilDB'];
43  $this->ctrl = $ilCtrl;
44  $this->lng = $lng;
45  $this->db = $ilDB;
46 
47  $this->setEnableTitle(true);
48  $this->setTopCommands(false);
49  $this->setEnableHeader(true);
50  // TODO: switch this to internal sorting/segmentation
51  $this->setExternalSorting(true);
52  $this->setExternalSegmentation(true);
53  $this->setRowTemplate("tpl.members_table_row.html", "Modules/StudyProgramme");
54  $this->setShowRowsSelector(false);
55 
56  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, "view"));
57 
58  $this->addColumn("", "", "1", true);
59  $this->setSelectAllCheckbox("prgs_ids[]");
60  $this->setEnableAllCommand(true);
61  $this->addMultiCommands();
62 
63  if ($this->prg_has_lp_children) {
64  $columns = $this->getColumnsLPChildren();
65  } else {
66  $columns = $this->getColumnsChildren();
67  }
68 
69  foreach ($this->getSelectedColumns() as $column) {
70  $columns[$column] = array($column);
71  }
72 
73  $columns["action"] = array(null);
74 
75  foreach ($columns as $lng_var => $params) {
76  $this->addColumn($this->lng->txt($lng_var), $params[0]);
77  }
78 
79  $this->determineLimit();
80  $this->determineOffsetAndOrder();
81  $oder = $this->getOrderField();
82  $dir = $this->getOrderDirection();
83 
84  $this->sp_user_progress_db = $sp_user_progress_db;
85 
86  $members_list = $this->fetchData($a_prg_obj_id, $this->getLimit(), $this->getOffset(), $this->getOrderField(), $this->getOrderDirection());
87  $this->setMaxCount($this->countFetchData($a_prg_obj_id));
88  $this->setData($members_list);
89  }
90 
91  protected function fillRow($a_set)
92  {
93  $this->tpl->setCurrentBlock("checkb");
94  $this->tpl->setVariable("ID", $a_set["prgrs_id"]);
95  $this->tpl->parseCurrentBlock();
96 
97  $this->tpl->setVariable("FIRSTNAME", $a_set["firstname"]);
98  $this->tpl->setVariable("LASTNAME", $a_set["lastname"]);
99  $this->tpl->setVariable("LOGIN", $a_set["login"]);
100  $this->tpl->setVariable("STATUS", $this->sp_user_progress_db->statusToRepr($a_set["status"]));
101  $this->tpl->setVariable("COMPLETION_BY", $a_set["completion_by"]);
102  $this->tpl->setVariable("POINTS_REQUIRED", $a_set["points"]);
103 
104  if (!$this->prg_has_lp_children) {
105  $this->tpl->setCurrentBlock("points_current");
106  $this->tpl->setVariable("POINTS_CURRENT", $a_set["points_current"]);
107  $this->tpl->parseCurrentBlock();
108  }
109 
110  $this->tpl->setVariable("CUSTOM_PLAN", $a_set["last_change_by"]
111  ? $this->lng->txt("yes")
112  : $this->lng->txt("no"));
113  $this->tpl->setVariable("BELONGS_TO", $a_set["belongs_to"]);
114  $this->tpl->setVariable("ACTIONS", $this->buildActionDropDown($a_set["actions"], $a_set["prgrs_id"], $a_set["assignment_id"]));
115 
116  foreach ($this->getSelectedColumns() as $column) {
117  switch ($column) {
118  case "prg_assign_date":
119  $this->tpl->setCurrentBlock("assign_date");
120  $this->tpl->setVariable("ASSIGN_DATE", $a_set["prg_assign_date"]);
121  $this->tpl->parseCurrentBlock("assign_date");
122  break;
123  case "prg_assigned_by":
124  $this->tpl->setCurrentBlock("assigned_by");
125  $this->tpl->setVariable("ASSIGNED_BY", $a_set["prg_assigned_by"]);
126  $this->tpl->parseCurrentBlock("assigned_by");
127  break;
128  }
129  }
130  }
131 
141  protected function buildActionDropDown($a_actions, $a_prgrs_id, $a_ass_id)
142  {
144  foreach ($a_actions as $action) {
145  $target = $this->getLinkTargetForAction($action, $a_prgrs_id, $a_ass_id);
146  $l->addItem($this->lng->txt("prg_$action"), $action, $target);
147  }
148  return $l->getHTML();
149  }
150 
160  protected function getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id)
161  {
162  return $this->getParentObject()->getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id);
163  }
164 
176  protected function fetchData($a_prg_id, $limit = null, $offset = null, $order_coloumn = null, $order_direction = null)
177  {
178  // TODO: Reimplement this in terms of ActiveRecord when innerjoin
179  // supports the required rename functionality
180  $query = "SELECT prgrs.id prgrs_id"
181  . " , pcp.firstname"
182  . " , pcp.lastname"
183  . " , pcp.login"
184  . " , prgrs.points"
185  //the following is a replacement for:
186  //IF(prgrs.status = ".ilStudyProgrammeProgress::STATUS_ACCREDITED.",prgrs.points,prgrs.points_cur)
187  //dirty hack to make it work with oracle :/ 1-|x-a|/max(|x-a|,1) = id_a(x)
188  . " , prgrs.points_cur*"
189  . "ABS(prgrs.status - " . ilStudyProgrammeProgress::STATUS_ACCREDITED . ")"
190  . "/(GREATEST(ABS(prgrs.status - " . ilStudyProgrammeProgress::STATUS_ACCREDITED . "),1))"
191  . " + prgrs.points*"
192  . "(1 -ABS(prgrs.status - " . ilStudyProgrammeProgress::STATUS_ACCREDITED . ")"
193  . "/(GREATEST(ABS(prgrs.status - " . ilStudyProgrammeProgress::STATUS_ACCREDITED . "),1))) points_current"
194  . " , prgrs.last_change_by"
195  . " , prgrs.status"
196  . " , blngs.title belongs_to"
197  . " , cmpl_usr.login accredited_by"
198  . " , cmpl_obj.title completion_by"
199  . " , cmpl_obj.type completion_by_type"
200  . " , prgrs.completion_by completion_by_id"
201  . " , prgrs.assignment_id assignment_id"
202  . " , ass.root_prg_id root_prg_id"
203  . " , ass.last_change prg_assign_date"
204  . " , ass_usr.login prg_assigned_by"
205  // for sorting
206  . " , CONCAT(pcp.firstname, pcp.lastname) name"
207  . " , (prgrs.last_change_by IS NOT NULL) custom_plan"
208  ;
209 
210  $query .= $this->getFrom();
211  $query .= $this->getWhere($a_prg_id);
212 
213  if ($order_coloumn !== null) {
214  $query .= " ORDER BY $order_coloumn";
215 
216  if ($order_direction !== null) {
217  $query .= " $order_direction";
218  }
219  }
220 
221 
222  if ($limit !== null) {
223  $this->db->setLimit($limit, $offset !== null ? $offset : 0);
224  }
225  $res = $this->db->query($query);
226 
227  $members_list = array();
228  while ($rec = $this->db->fetchAssoc($res)) {
230  $a_prg_id,
231  $rec["root_prg_id"],
232  $rec["status"]
233  );
234  $rec['points_current'] = number_format($rec['points_current']);
235  if ($rec["status"] == ilStudyProgrammeProgress::STATUS_COMPLETED) {
236  //If the status completet is set by crs reference
237  //use crs title
238  if ($rec["completion_by_type"] == "crsr") {
239  $rec["completion_by"] = ilContainerReference::_lookupTitle($rec["completion_by_id"]);
240  }
241 
242  // If the status completed and there is a non-null completion_by field
243  // in the set, this means the completion was achieved by some leaf in
244  // the program tree.
245  if (!$rec["completion_by"]) {
246  $prgrs = $this->sp_user_progress_db->getInstanceForAssignment($this->prg_obj_id, $rec["assignment_id"]);
247  $rec["completion_by"] = implode(", ", $prgrs->getNamesOfCompletedOrAccreditedChildren());
248  }
249  } elseif ($rec["status"] == ilStudyProgrammeProgress::STATUS_ACCREDITED) {
250  $rec["completion_by"] = $rec["accredited_by"];
251  }
252 
253  $members_list[] = $rec;
254  }
255  return $members_list;
256  }
257 
265  protected function countFetchData($a_prg_id)
266  {
267  // TODO: Reimplement this in terms of ActiveRecord when innerjoin
268  // supports the required rename functionality
269  $query = "SELECT count(prgrs.id) as cnt";
270  $query .= $this->getFrom();
271  $query .= $this->getWhere($a_prg_id);
272 
273  $res = $this->db->query($query);
274  $rec = $this->db->fetchAssoc($res);
275 
276  return $rec["cnt"];
277  }
278 
284  protected function getFrom()
285  {
286  return " FROM " . ilStudyProgrammeProgress::returnDbTableName() . " prgrs"
287  . " JOIN usr_data pcp ON pcp.usr_id = prgrs.usr_id"
288  . " JOIN " . ilStudyProgrammeAssignment::returnDbTableName() . " ass"
289  . " ON ass.id = prgrs.assignment_id"
290  . " JOIN object_data blngs ON blngs.obj_id = ass.root_prg_id"
291  . " LEFT JOIN usr_data ass_usr ON ass_usr.usr_id = ass.last_change_by"
292  . " LEFT JOIN usr_data cmpl_usr ON cmpl_usr.usr_id = prgrs.completion_by"
293  . " LEFT JOIN object_data cmpl_obj ON cmpl_obj.obj_id = prgrs.completion_by";
294  }
295 
303  protected function getWhere($a_prg_id)
304  {
305  return " WHERE prgrs.prg_id = " . $this->db->quote($a_prg_id, "integer");
306  }
307 
313  public function getSelectableColumns()
314  {
315  // default fields
316  $cols = array();
317 
318  $cols["prg_assign_date"] = array(
319  "txt" => $this->lng->txt("prg_assign_date"));
320 
321  $cols["prg_assigned_by"] = array(
322  "txt" => $this->lng->txt("prg_assigned_by"));
323 
324  return $cols;
325  }
326 
332  protected function getColumnsChildren()
333  {
334  return array( "name" => array("name")
335  , "login" => array("login")
336  , "prg_status" => array("status")
337  , "prg_completion_by" => array(null)
338  , "prg_points_required" => array("points")
339  , "prg_points_current" => array("points_current")
340  , "prg_custom_plan" => array("custom_plan")
341  , "prg_belongs_to" => array("belongs_to")
342  );
343  }
344 
350  protected function getColumnsLPChildren()
351  {
352  return array( "name" => array("name")
353  , "login" => array("login")
354  , "prg_status" => array("status")
355  , "prg_completion_by" => array(null)
356  , "prg_points_reachable" => array("points")
357  , "prg_custom_plan" => array("custom_plan")
358  , "prg_belongs_to" => array("belongs_to")
359  );
360  }
361 
367  protected function addMultiCommands()
368  {
369  foreach ($this->getMultiCommands() as $cmd => $caption) {
370  $this->addMultiCommand($cmd, $caption);
371  }
372  }
373 
379  protected function getMultiCommands()
380  {
381  return array(
382  'markAccreditedMulti' => $this->lng->txt('prg_multi_mark_accredited'),
383  'unmarkAccreditedMulti' => $this->lng->txt('prg_multi_unmark_accredited'),
384  'removeUserMulti' => $this->lng->txt('prg_multi_remove_user'),
385  'markRelevantMulti' => $this->lng->txt('prg_multi_mark_relevant'),
386  'markNotRelevantMulti' => $this->lng->txt('prg_multi_unmark_relevant'),
387  'updateFromCurrentPlanMulti' => $this->lng->txt('prg_multi_update_from_current_plan')
388  );
389  }
390 }
getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id)
Get ilias link for action.
setExternalSorting($a_val)
Set external sorting.
$action
global $DIC
Definition: saml.php:7
setExternalSegmentation($a_val)
Set external segmentation.
Storage implementation for ilStudyProgrammeUserProgress.
determineLimit()
Determine the limit.
getOrderDirection()
Get order direction.
fetchData($a_prg_id, $limit=null, $offset=null, $order_coloumn=null, $order_direction=null)
Get data for table.
getParentObject()
Get parent object.
setId($a_val)
Set id.
countFetchData($a_prg_id)
Get maximum number of rows the table could have.
__construct($a_prg_obj_id, $a_prg_ref_id, $a_parent_obj, $a_parent_cmd="", $a_template_context="", \ilStudyProgrammeUserProgressDB $sp_user_progress_db)
global $ilCtrl
Definition: ilias.php:18
Class ilObjStudyProgrammeMembersTableGUI.
setTopCommands($a_val)
Set top commands (display command buttons on top of table, too)
Class ilTable2GUI.
buildActionDropDown($a_actions, $a_prgrs_id, $a_ass_id)
Builds the action menu for each row of the table.
foreach($_POST as $key=> $value) $res
static _lookupTitle($a_obj_id)
Overwitten from base class.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
getOffset()
Get offset.
static getPossibleActions($a_node_id, $a_root_prg_id, $a_status)
Get a list with possible actions on a progress record.
addMultiCommand($a_cmd, $a_text)
Add Command button.
getColumnsChildren()
Get columns for children if it is a child.
getSelectedColumns()
Get selected columns.
$query
setEnableAllCommand($a_value)
Enable actions for all entries in current result.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
getColumnsLPChildren()
Get columns for children if it is a lp child.
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
global $l
Definition: afr.php:30
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.
global $ilDB
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setEnableHeader($a_enableheader)
Set Enable Header.
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
setEnableTitle($a_enabletitle)
Set Enable Title.
$target
Definition: test.php:19
if(! $in) $columns
Definition: Utf8Test.php:45
$cols
Definition: xhr_table.php:11