ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  protected $prg_obj_id;
22  protected $prg_ref_id;
23 
24  public function __construct($a_prg_obj_id, $a_prg_ref_id, $a_parent_obj, $a_parent_cmd="", $a_template_context="") {
25  $this->setId("sp_member_list");
26  parent::__construct($a_parent_obj, $a_parent_cmd, $a_template_context);
27 
28  $this->prg_obj_id = $a_prg_obj_id;
29  $this->prg_ref_id = $a_prg_ref_id;
30  $this->prg_has_lp_children = $a_parent_obj->getStudyProgramme()->hasLPChildren();
31 
32  global $DIC;
33  $ilCtrl = $DIC['ilCtrl'];
34  $lng = $DIC['lng'];
35  $ilDB = $DIC['ilDB'];
36  $this->ctrl = $ilCtrl;
37  $this->lng = $lng;
38  $this->db = $ilDB;
39 
40  $this->setEnableTitle(true);
41  $this->setTopCommands(false);
42  $this->setEnableHeader(true);
43  // TODO: switch this to internal sorting/segmentation
44  $this->setExternalSorting(true);
45  $this->setExternalSegmentation(true);
46  $this->setRowTemplate("tpl.members_table_row.html", "Modules/StudyProgramme");
47  $this->setShowRowsSelector(false);
48 
49  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, "view"));
50 
51 
52  if($this->prg_has_lp_children) {
53  $columns = $this->getColumnsLPChildren();
54  } else {
55  $columns = $this->getColumnsChildren();
56  }
57 
58  foreach ($this->getSelectedColumns() as $column) {
59  $columns[$column] = array($column);
60  }
61 
62  $columns["action"] = array(null);
63 
64  foreach ($columns as $lng_var => $params) {
65  $this->addColumn($this->lng->txt($lng_var), $params[0]);
66  }
67 
68  $this->determineLimit();
69  $this->determineOffsetAndOrder();
70  $oder = $this->getOrderField();
71  $dir = $this->getOrderDirection();
72 
73  $members_list = $this->fetchData($a_prg_obj_id, $this->getLimit(), $this->getOffset(), $this->getOrderField(), $this->getOrderDirection());
74  $this->setMaxCount($this->countFetchData($a_prg_obj_id));
75  $this->setData($members_list);
76  }
77 
78  protected function fillRow($a_set) {
79  $this->tpl->setVariable("FIRSTNAME", $a_set["firstname"]);
80  $this->tpl->setVariable("LASTNAME", $a_set["lastname"]);
81  $this->tpl->setVariable("LOGIN", $a_set["login"]);
82  $this->tpl->setVariable("STATUS", ilStudyProgrammeUserProgress::statusToRepr($a_set["status"]));
83  $this->tpl->setVariable("COMPLETION_BY", $a_set["completion_by"]);
84  $this->tpl->setVariable("POINTS_REQUIRED", $a_set["points"]);
85 
86  if(!$this->prg_has_lp_children) {
87  $this->tpl->setCurrentBlock("points_current");
88  $this->tpl->setVariable("POINTS_CURRENT", $a_set["points_current"]);
89  $this->tpl->parseCurrentBlock();
90  }
91 
92  $this->tpl->setVariable("CUSTOM_PLAN", $a_set["last_change_by"]
93  ? $this->lng->txt("yes")
94  : $this->lng->txt("no"));
95  $this->tpl->setVariable("BELONGS_TO", $a_set["belongs_to"]);
96  $this->tpl->setVariable("ACTIONS", $this->buildActionDropDown( $a_set["actions"]
97  , $a_set["prgrs_id"]
98  , $a_set["assignment_id"]));
99 
100  foreach ($this->getSelectedColumns() as $column) {
101  switch($column) {
102  case "prg_assign_date":
103  $this->tpl->setCurrentBlock("assign_date");
104  $this->tpl->setVariable("ASSIGN_DATE", $a_set["prg_assign_date"]);
105  $this->tpl->parseCurrentBlock("assign_date");
106  break;
107  case "prg_assigned_by":
108  $this->tpl->setCurrentBlock("assigned_by");
109  $this->tpl->setVariable("ASSIGNED_BY", $a_set["prg_assigned_by"]);
110  $this->tpl->parseCurrentBlock("assigned_by");
111  break;
112  }
113  }
114  }
115 
116  protected function buildActionDropDown($a_actions, $a_prgrs_id, $a_ass_id) {
118  foreach($a_actions as $action) {
119  $target = $this->getLinkTargetForAction($action, $a_prgrs_id, $a_ass_id);
120  $l->addItem($this->lng->txt("prg_$action"), $action, $target);
121  }
122  return $l->getHTML();
123  }
124 
125  protected function getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id) {
126  return $this->getParentObject()->getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id);
127  }
128 
129  protected function fetchData($a_prg_id, $limit = null, $offset = null, $order_coloumn = null, $order_direction = null) {
130  // TODO: Reimplement this in terms of ActiveRecord when innerjoin
131  // supports the required rename functionality
132  $query = "SELECT prgrs.id prgrs_id"
133  ." , pcp.firstname"
134  ." , pcp.lastname"
135  ." , pcp.login"
136  ." , prgrs.points"
137  //the following is a replacement for:
138  //IF(prgrs.status = ".ilStudyProgrammeProgress::STATUS_ACCREDITED.",prgrs.points,prgrs.points_cur)
139  //dirty hack to make it work with oracle :/ 1-|x-a|/max(|x-a|,1) = id_a(x)
140  ." , prgrs.points_cur*"
141  ."ABS(prgrs.status - ".ilStudyProgrammeProgress::STATUS_ACCREDITED.")"
142  ."/(GREATEST(ABS(prgrs.status - ".ilStudyProgrammeProgress::STATUS_ACCREDITED."),1))"
143  ." + prgrs.points*"
144  ."(1 -ABS(prgrs.status - ".ilStudyProgrammeProgress::STATUS_ACCREDITED.")"
145  ."/(GREATEST(ABS(prgrs.status - ".ilStudyProgrammeProgress::STATUS_ACCREDITED."),1))) points_current"
146  ." , prgrs.last_change_by"
147  ." , prgrs.status"
148  ." , blngs.title belongs_to"
149  ." , cmpl_usr.login accredited_by"
150  ." , cmpl_obj.title completion_by"
151  ." , cmpl_obj.type completion_by_type"
152  ." , prgrs.completion_by completion_by_id"
153  ." , prgrs.assignment_id assignment_id"
154  ." , ass.root_prg_id root_prg_id"
155  ." , ass.last_change prg_assign_date"
156  ." , ass_usr.login prg_assigned_by"
157  // for sorting
158  ." , CONCAT(pcp.firstname, pcp.lastname) name"
159  ." , (prgrs.last_change_by IS NOT NULL) custom_plan"
160  ;
161 
162  $query .= $this->getFrom();
163  $query .= $this->getWhere($a_prg_id);
164 
165  if($order_coloumn !== null) {
166  $query .= " ORDER BY $order_coloumn";
167 
168  if($order_direction !== null) {
169  $query .= " $order_direction";
170  }
171  }
172 
173 
174  if($limit !== null) {
175  $this->db->setLimit($limit, $offset !== null ? $offset : 0);
176  }
177  $res = $this->db->query($query);
178 
179  $members_list = array();
180  while($rec = $this->db->fetchAssoc($res)) {
182  $a_prg_id, $rec["root_prg_id"], $rec["status"]);
183  $rec['points_current'] = number_format($rec['points_current']);
184  if ($rec["status"] == ilStudyProgrammeProgress::STATUS_COMPLETED) {
185  //If the status completet is set by crs reference
186  //use crs title
187  if($rec["completion_by_type"] == "crsr") {
188  $rec["completion_by"] = ilContainerReference::_lookupTitle($rec["completion_by_id"]);
189  }
190 
191  // If the status completed and there is a non-null completion_by field
192  // in the set, this means the completion was achieved by some leaf in
193  // the program tree.
194  if (!$rec["completion_by"]) {
195  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
197  , $rec["assignment_id"]);
198  $rec["completion_by"] = implode(", ", $prgrs->getNamesOfCompletedOrAccreditedChildren());
199  }
200  }
201  else if($rec["status"] == ilStudyProgrammeProgress::STATUS_ACCREDITED) {
202  $rec["completion_by"] = $rec["accredited_by"];
203  }
204 
205  $members_list[] = $rec;
206  }
207  return $members_list;
208  }
209 
210  protected function countFetchData($a_prg_id) {
211  // TODO: Reimplement this in terms of ActiveRecord when innerjoin
212  // supports the required rename functionality
213  $query = "SELECT count(prgrs.id) as cnt";
214  $query .= $this->getFrom();
215  $query .= $this->getWhere($a_prg_id);
216 
217  $res = $this->db->query($query);
218  $rec = $this->db->fetchAssoc($res);
219 
220  return $rec["cnt"];
221  }
222 
223  protected function getFrom() {
224  return " FROM ".ilStudyProgrammeProgress::returnDbTableName()." prgrs"
225  ." JOIN usr_data pcp ON pcp.usr_id = prgrs.usr_id"
227  ." ON ass.id = prgrs.assignment_id"
228  ." JOIN object_data blngs ON blngs.obj_id = ass.root_prg_id"
229  ." LEFT JOIN usr_data ass_usr ON ass_usr.usr_id = ass.last_change_by"
230  ." LEFT JOIN usr_data cmpl_usr ON cmpl_usr.usr_id = prgrs.completion_by"
231  ." LEFT JOIN object_data cmpl_obj ON cmpl_obj.obj_id = prgrs.completion_by";
232  }
233 
234  protected function getWhere($a_prg_id) {
235  return " WHERE prgrs.prg_id = ".$this->db->quote($a_prg_id, "integer");
236  }
237 
243  function getSelectableColumns() {
244  // default fields
245  $cols = array();
246 
247  $cols["prg_assign_date"] = array(
248  "txt" => $this->lng->txt("prg_assign_date"));
249 
250  $cols["prg_assigned_by"] = array(
251  "txt" => $this->lng->txt("prg_assigned_by"));
252 
253  return $cols;
254  }
255 
256  protected function getColumnsChildren() {
257  return array( "name" => array("name")
258  , "login" => array("login")
259  , "prg_status" => array("status")
260  , "prg_completion_by" => array(null)
261  , "prg_points_required" => array("points")
262  , "prg_points_current" => array("points_current")
263  , "prg_custom_plan" => array("custom_plan")
264  , "prg_belongs_to" => array("belongs_to")
265  );
266  }
267 
268  protected function getColumnsLPChildren() {
269  return array( "name" => array("name")
270  , "login" => array("login")
271  , "prg_status" => array("status")
272  , "prg_completion_by" => array(null)
273  , "prg_points_reachable" => array("points")
274  , "prg_custom_plan" => array("custom_plan")
275  , "prg_belongs_to" => array("belongs_to")
276  );
277  }
278 }
279 
280 ?>
getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id)
setExternalSorting($a_val)
Set external sorting.
static statusToRepr($a_status)
Get a user readable representation of a status.
static getInstanceForAssignment($a_program_id, $a_assignment_id)
Get the instance for the assignment on the program.
setExternalSegmentation($a_val)
Set external segmentation.
determineLimit()
Determine the limit.
__construct($a_prg_obj_id, $a_prg_ref_id, $a_parent_obj, $a_parent_cmd="", $a_template_context="")
getOrderDirection()
Get order direction.
fetchData($a_prg_id, $limit=null, $offset=null, $order_coloumn=null, $order_direction=null)
getParentObject()
Get parent object.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
Class ilObjStudyProgrammeMembersTableGUI.
setTopCommands($a_val)
Set top commands (display command buttons on top of table, too)
Class ilTable2GUI.
$column
Definition: 39dropdown.php:62
buildActionDropDown($a_actions, $a_prgrs_id, $a_ass_id)
static _lookupTitle($a_obj_id)
Overwitten from base class.
getOffset()
Get offset.
static getPossibleActions($a_node_id, $a_root_prg_id, $a_status)
Get a list with possible actions on a progress record.
getSelectedColumns()
Get selected columns.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
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
global $lng
Definition: privfeed.php:17
global $ilDB
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setEnableHeader($a_enableheader)
Set Enable Header.
global $DIC
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
setEnableTitle($a_enabletitle)
Set Enable Title.
if(! $in) $columns
Definition: Utf8Test.php:45
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.
$params
Definition: example_049.php:96