ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilOrgUnitStaffTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once("./Services/Table/classes/class.ilTable2GUI.php");
4 require_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php");
5 require_once("./Services/Tracking/classes/class.ilObjUserTracking.php");
14 
16  private $recursive = false;
17 
19  private $staff = "employee";
20 
21  public function __construct($parent_obj, $parent_cmd, $staff = "employee", $recursive = false, $template_context = ""){
22  parent::__construct($parent_obj, $parent_cmd, $template_context);
23 
24  global $lng, $ilCtrl, $ilTabs;
29  $this->ctrl = $ilCtrl;
30  $this->tabs = $ilTabs;
31  $this->lng = $lng;
32 
33  $this->setPrefix("sr_orgu_".$staff);
34  $this->setFormName('sr_orgu_'.$staff);
35  $this->setId("sr_orgu_".$staff);
36  $this->setStaff($staff);
37  $this->recursive = $recursive;
38  $this->setTableHeaders();
39  $this->setTopCommands(true);
40  $this->setEnableHeader(true);
41  $this->setShowRowsSelector(true);
42  $this->setShowTemplates(false);
43  $this->setEnableHeader(true);
44  $this->setDefaultOrderField("role");
45  $this->setEnableTitle(true);
46  $this->setTitle($this->lng->txt("Staff"));
47  $this->setRowTemplate("tpl.staff_row.html", "Modules/OrgUnit");
48  }
49 
50 
51  protected function setTableHeaders(){
52  $this->addColumn($this->lng->txt("firstname"), "first_name");
53  $this->addColumn($this->lng->txt("lastname"), "last_name");
54  if ($this->recursive) {
55  $this->addColumn($this->lng->txt('obj_orgu'), 'org_units');
56  }
57  $this->addColumn($this->lng->txt("action"));
58  }
59 
60  public function parseData(){
61  if($this->staff == "employee")
62  $data = $this->parseRows(ilObjOrgUnitTree::_getInstance()->getEmployees($_GET["ref_id"], $this->recursive));
63  elseif($this->staff == "superior")
64  $data = $this->parseRows(ilObjOrgUnitTree::_getInstance()->getSuperiors($_GET["ref_id"], $this->recursive));
65  else
66  throw new Exception("The ilOrgUnitStaffTableGUI's staff variable has to be either 'employee' or 'superior'");
67 
68  $this->setData($data);
69  }
70 
71  protected function parseRows($user_ids){
72  $data = array();
73  foreach($user_ids as $user_id){
74  $set = array();
75  $this->setRowForUser($set, $user_id);
76  $data[] = $set;
77  }
78  return $data;
79  }
80 
84  public function setStaff($staff)
85  {
86  $this->staff = $staff;
87  }
88 
92  public function getStaff()
93  {
94  return $this->staff;
95  }
96 
97  protected function setRowForUser(&$set, $user_id){
98  $user = new ilObjUser($user_id);
99  $set["first_name"] = $user->getFirstname();
100  $set["last_name"] = $user->getLastname();
101  $set["user_object"] = $user;
102  $set["user_id"] = $user_id;
103  if ($this->recursive) $set["org_units"] = ilObjOrgUnitTree::_getInstance()->getOrgUnitOfUser($user_id, (int)$_GET['ref_id']);
104  }
105 
106  function fillRow($set){
107  global $ilUser, $Access, $lng, $ilAccess;
108  $this->tpl->setVariable("FIRST_NAME", $set["first_name"]);
109  $this->tpl->setVariable("LAST_NAME", $set["last_name"]);
110  if ($this->recursive) {
111  $orgUnitsTitles = array_values(ilObjOrgUnitTree::_getInstance()->getTitles($set['org_units']));
112  $this->tpl->setVariable("ORG_UNITS", implode(', ', $orgUnitsTitles));
113  }
114  $this->ctrl->setParameterByClass("illearningprogressgui", "obj_id", $set["user_id"]);
115  $this->ctrl->setParameterByClass("ilobjorgunitgui", "obj_id", $set["user_id"]);
116  $selection = new ilAdvancedSelectionListGUI();
117  $selection->setListTitle($lng->txt("Actions"));
118  $selection->setId("selection_list_user_lp_".$set["user_id"]);
119 
120  if($ilAccess->checkAccess("view_learning_progress", "", $_GET["ref_id"]) AND ilObjUserTracking::_enabledLearningProgress() and
122  $selection->addItem($lng->txt("show_learning_progress"), "show_learning_progress", $this->ctrl->getLinkTargetByClass(array("ilAdministrationGUI", "ilObjOrgUnitGUI", "ilLearningProgressGUI"), ""));
123  }
124  if($ilAccess->checkAccess("write", "", $_GET["ref_id"]) && !$this->recursive){
125  if($this->staff == "employee")
126  $this->addEmployeeActions($selection);
127  if($this->staff == "superior")
128  $this->addSuperiorActions($selection);
129  }
130  $this->tpl->setVariable("ACTIONS", $selection->getHTML());
131 
132  }
133 
137  protected function addEmployeeActions(&$selection){
138  $selection->addItem($this->lng->txt("remove"), "delete_from_employees", $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "confirmRemoveFromEmployees"));
139  $selection->addItem($this->lng->txt("change_to_superior"), "change_to_superior", $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "fromEmployeeToSuperior"));
140  }
141 
145  protected function addSuperiorActions(&$selection){
146  $selection->addItem($this->lng->txt("remove"), "delete_from_superiors", $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "confirmRemoveFromSuperiors"));
147  $selection->addItem($this->lng->txt("change_to_employee"), "change_to_employee", $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "fromSuperiorToEmployee"));
148  }
149 
153  public function setRecursive($recursive){
154  $this->recursive = $recursive;
155  }
156 
157 
158 }
159 ?>