ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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  parent::__construct($a_parent_obj, $a_parent_cmd, $a_template_context);
26 
27  $this->prg_obj_id = $a_prg_obj_id;
28  $this->prg_ref_id = $a_prg_ref_id;
29  $this->prg_has_lp_children = $a_parent_obj->getStudyProgramme()->hasLPChildren();
30 
31  global $ilCtrl, $lng, $ilDB;
32  $this->ctrl = $ilCtrl;
33  $this->lng = $lng;
34  $this->db = $ilDB;
35 
36  $this->setEnableTitle(true);
37  $this->setTopCommands(false);
38  $this->setEnableHeader(true);
39  // TODO: switch this to internal sorting/segmentation
40  $this->setExternalSorting(true);
41  $this->setExternalSegmentation(true);
42  $this->setRowTemplate("tpl.members_table_row.html", "Modules/StudyProgramme");
43 
44  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, "view"));
45 
46 
47  if($this->prg_has_lp_children) {
48  $columns = $this->getColumnsLPChildren();
49  } else {
50  $columns = $this->getColumnsChildren();
51  }
52 
53  foreach ($columns as $lng_var => $params) {
54  $this->addColumn($lng->txt($lng_var), $params[0]);
55  }
56 
57  $this->determineLimit();
58  $this->determineOffsetAndOrder();
59  $oder = $this->getOrderField();
60  $dir = $this->getOrderDirection();
61 
62  $members_list = $this->fetchData($a_prg_obj_id, $this->getLimit(), $this->getOffset(), $this->getOrderField(), $this->getOrderDirection());
63  $this->setMaxCount($this->countFetchData($a_prg_obj_id));
64  $this->setData($members_list);
65  }
66 
67  protected function fillRow($a_set) {
68  $this->tpl->setVariable("FIRSTNAME", $a_set["firstname"]);
69  $this->tpl->setVariable("LASTNAME", $a_set["lastname"]);
70  $this->tpl->setVariable("LOGIN", $a_set["login"]);
71  $this->tpl->setVariable("STATUS", ilStudyProgrammeUserProgress::statusToRepr($a_set["status"]));
72  $this->tpl->setVariable("COMPLETION_BY", $a_set["completion_by"]);
73  $this->tpl->setVariable("POINTS_REQUIRED", $a_set["points"]);
74 
75  if(!$this->prg_has_lp_children) {
76  $this->tpl->setCurrentBlock("points_current");
77  $this->tpl->setVariable("POINTS_CURRENT", $a_set["points_current"]);
78  $this->tpl->parseCurrentBlock();
79  }
80 
81  $this->tpl->setVariable("CUSTOM_PLAN", $a_set["last_change_by"]
82  ? $this->lng->txt("yes")
83  : $this->lng->txt("no"));
84  $this->tpl->setVariable("BELONGS_TO", $a_set["belongs_to"]);
85  $this->tpl->setVariable("ACTIONS", $this->buildActionDropDown( $a_set["actions"]
86  , $a_set["prgrs_id"]
87  , $a_set["assignment_id"]));
88  }
89 
90  protected function buildActionDropDown($a_actions, $a_prgrs_id, $a_ass_id) {
92  foreach($a_actions as $action) {
93  $target = $this->getLinkTargetForAction($action, $a_prgrs_id, $a_ass_id);
94  $l->addItem($this->lng->txt("prg_$action"), $action, $target);
95  }
96  return $l->getHTML();
97  }
98 
99  protected function getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id) {
100  return $this->getParentObject()->getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id);
101  }
102 
103  protected function fetchData($a_prg_id, $limit = null, $offset = null, $order_coloumn = null, $order_direction = null) {
104  // TODO: Reimplement this in terms of ActiveRecord when innerjoin
105  // supports the required rename functionality
106  $query = "SELECT prgrs.id prgrs_id"
107  ." , pcp.firstname"
108  ." , pcp.lastname"
109  ." , pcp.login"
110  ." , prgrs.points"
111  //the following is a replacement for:
112  //IF(prgrs.status = ".ilStudyProgrammeProgress::STATUS_ACCREDITED.",prgrs.points,prgrs.points_cur)
113  //dirty hack to make it work with oracle :/ 1-|x-a|/max(|x-a|,1) = id_a(x)
114  ." , prgrs.points_cur*"
115  ."ABS(prgrs.status - ".ilStudyProgrammeProgress::STATUS_ACCREDITED.")"
116  ."/(GREATEST(ABS(prgrs.status - ".ilStudyProgrammeProgress::STATUS_ACCREDITED."),1))"
117  ." + prgrs.points*"
118  ."(1 -ABS(prgrs.status - ".ilStudyProgrammeProgress::STATUS_ACCREDITED.")"
119  ."/(GREATEST(ABS(prgrs.status - ".ilStudyProgrammeProgress::STATUS_ACCREDITED."),1))) points_current"
120  ." , prgrs.last_change_by"
121  ." , prgrs.status"
122  ." , blngs.title belongs_to"
123  ." , cmpl_usr.login accredited_by"
124  ." , cmpl_obj.title completion_by"
125  ." , cmpl_obj.type completion_by_type"
126  ." , prgrs.completion_by completion_by_id"
127  ." , prgrs.assignment_id assignment_id"
128  ." , ass.root_prg_id root_prg_id"
129  // for sorting
130  ." , CONCAT(pcp.firstname, pcp.lastname) name"
131  ." , (prgrs.last_change_by IS NOT NULL) custom_plan"
132  ;
133 
134  $query .= $this->getFrom();
135  $query .= $this->getWhere($a_prg_id);
136 
137  if($order_coloumn !== null) {
138  $query .= " ORDER BY $order_coloumn";
139 
140  if($order_direction !== null) {
141  $query .= " $order_direction";
142  }
143  }
144 
145 
146  if($limit !== null) {
147  $this->db->setLimit($limit, $offset !== null ? $offset : 0);
148  }
149  $res = $this->db->query($query);
150 
151  $members_list = array();
152  while($rec = $this->db->fetchAssoc($res)) {
154  $a_prg_id, $rec["root_prg_id"], $rec["status"]);
155  $rec['points_current'] = number_format($rec['points_current']);
156  if ($rec["status"] == ilStudyProgrammeProgress::STATUS_COMPLETED) {
157  //If the status completet is set by crs reference
158  //use crs title
159  if($rec["completion_by_type"] == "crsr") {
160  $rec["completion_by"] = ilContainerReference::_lookupTitle($rec["completion_by_id"]);
161  }
162 
163  // If the status completed and there is a non-null completion_by field
164  // in the set, this means the completion was achieved by some leaf in
165  // the program tree.
166  if (!$rec["completion_by"]) {
167  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
169  , $rec["assignment_id"]);
170  $rec["completion_by"] = implode(", ", $prgrs->getNamesOfCompletedOrAccreditedChildren());
171  }
172  }
173  else if($rec["status"] == ilStudyProgrammeProgress::STATUS_ACCREDITED) {
174  $rec["completion_by"] = $rec["accredited_by"];
175  }
176 
177  $members_list[] = $rec;
178  }
179  return $members_list;
180  }
181 
182  protected function countFetchData($a_prg_id) {
183  // TODO: Reimplement this in terms of ActiveRecord when innerjoin
184  // supports the required rename functionality
185  $query = "SELECT count(prgrs.id) as cnt";
186  $query .= $this->getFrom();
187  $query .= $this->getWhere($a_prg_id);
188 
189  $res = $this->db->query($query);
190  $rec = $this->db->fetchAssoc($res);
191 
192  return $rec["cnt"];
193  }
194 
195  protected function getFrom() {
196  return " FROM ".ilStudyProgrammeProgress::returnDbTableName()." prgrs"
197  ." JOIN usr_data pcp ON pcp.usr_id = prgrs.usr_id"
199  ." ON ass.id = prgrs.assignment_id"
200  ." JOIN object_data blngs ON blngs.obj_id = ass.root_prg_id"
201  ." LEFT JOIN usr_data cmpl_usr ON cmpl_usr.usr_id = prgrs.completion_by"
202  ." LEFT JOIN object_data cmpl_obj ON cmpl_obj.obj_id = prgrs.completion_by";
203  }
204 
205  protected function getWhere($a_prg_id) {
206  return " WHERE prgrs.prg_id = ".$this->db->quote($a_prg_id, "integer");
207  }
208 
209  protected function getColumnsChildren() {
210  return array( "name" => array("name")
211  , "login" => array("login")
212  , "prg_status" => array("status")
213  , "prg_completion_by" => array(null)
214  , "prg_points_required" => array("points")
215  , "prg_points_current" => array("points_current")
216  , "prg_custom_plan" => array("custom_plan")
217  , "prg_belongs_to" => array("belongs_to")
218  , "actions" => array(null)
219  );
220  }
221 
222  protected function getColumnsLPChildren() {
223  return array( "name" => array("name")
224  , "login" => array("login")
225  , "prg_status" => array("status")
226  , "prg_completion_by" => array(null)
227  , "prg_points_reachable" => array("points")
228  , "prg_custom_plan" => array("custom_plan")
229  , "prg_belongs_to" => array("belongs_to")
230  , "actions" => array(null)
231  );
232  }
233 }
234 
235 ?>
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.
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)
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.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
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:40
global $ilDB
setEnableHeader($a_enableheader)
Set Enable Header.
getLimit()
Get limit.
setMaxCount($a_max_count)
set max.
setEnableTitle($a_enabletitle)
Set Enable Title.
if(! $in) $columns
Definition: Utf8Test.php:46
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