ILIAS  Release_5_0_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 
23 
24  global $lng, $ilCtrl, $ilTabs;
29  $this->ctrl = $ilCtrl;
30  $this->tabs = $ilTabs;
31  $this->lng = $lng;
32 
33  $this->setPrefix("il_orgu_".$staff);
34  $this->setFormName('il_orgu_'.$staff);
35  $this->setId("il_orgu_".$staff);
36 
37  parent::__construct($parent_obj, $parent_cmd, $template_context);
38 
39  $this->setFormAction($this->ctrl->getFormAction($parent_obj));
40  $this->setStaff($staff);
41  $this->recursive = $recursive;
42  $this->setTableHeaders();
43  $this->setTopCommands(true);
44  $this->setEnableHeader(true);
45  $this->setShowRowsSelector(true);
46  $this->setShowTemplates(false);
47  $this->setEnableHeader(true);
48  $this->setDefaultOrderField("role");
49  $this->setEnableTitle(true);
50  $this->setTitle($this->lng->txt("Staff"));
51  $this->setRowTemplate("tpl.staff_row.html", "Modules/OrgUnit");
52  }
53 
54 
55  protected function setTableHeaders(){
56  $this->addColumn($this->lng->txt("firstname"), "first_name");
57  $this->addColumn($this->lng->txt("lastname"), "last_name");
58  if ($this->recursive) {
59  $this->addColumn($this->lng->txt('obj_orgu'), 'org_units');
60  }
61  $this->addColumn($this->lng->txt("action"));
62  }
63 
64  public function parseData(){
65  if($this->staff == "employee")
66  $data = $this->parseRows(ilObjOrgUnitTree::_getInstance()->getEmployees($_GET["ref_id"], $this->recursive));
67  elseif($this->staff == "superior")
68  $data = $this->parseRows(ilObjOrgUnitTree::_getInstance()->getSuperiors($_GET["ref_id"], $this->recursive));
69  else
70  throw new Exception("The ilOrgUnitStaffTableGUI's staff variable has to be either 'employee' or 'superior'");
71 
72  $this->setData($data);
73  }
74 
75  protected function parseRows($user_ids){
76  $data = array();
77  foreach($user_ids as $user_id){
78  $set = array();
79  $this->setRowForUser($set, $user_id);
80  $data[] = $set;
81  }
82  return $data;
83  }
84 
88  public function setStaff($staff)
89  {
90  $this->staff = $staff;
91  }
92 
96  public function getStaff()
97  {
98  return $this->staff;
99  }
100 
101  protected function setRowForUser(&$set, $user_id){
102  $user = new ilObjUser($user_id);
103  $set["first_name"] = $user->getFirstname();
104  $set["last_name"] = $user->getLastname();
105  $set["user_object"] = $user;
106  $set["user_id"] = $user_id;
107  if ($this->recursive) $set["org_units"] = ilObjOrgUnitTree::_getInstance()->getOrgUnitOfUser($user_id, (int)$_GET['ref_id']);
108  }
109 
110  function fillRow($set){
111  global $ilUser, $Access, $lng, $ilAccess;
112  $this->tpl->setVariable("FIRST_NAME", $set["first_name"]);
113  $this->tpl->setVariable("LAST_NAME", $set["last_name"]);
114  if ($this->recursive) {
115  $orgUnitsTitles = array_values(ilObjOrgUnitTree::_getInstance()->getTitles($set['org_units']));
116  $this->tpl->setVariable("ORG_UNITS", implode(', ', $orgUnitsTitles));
117  }
118  $this->ctrl->setParameterByClass("illearningprogressgui", "obj_id", $set["user_id"]);
119  $this->ctrl->setParameterByClass("ilobjorgunitgui", "obj_id", $set["user_id"]);
120  $selection = new ilAdvancedSelectionListGUI();
121  $selection->setListTitle($lng->txt("Actions"));
122  $selection->setId("selection_list_user_lp_".$set["user_id"]);
123 
124  if($ilAccess->checkAccess("view_learning_progress", "", $_GET["ref_id"]) AND ilObjUserTracking::_enabledLearningProgress() and
126  $selection->addItem($lng->txt("show_learning_progress"), "show_learning_progress", $this->ctrl->getLinkTargetByClass(array("ilAdministrationGUI", "ilObjOrgUnitGUI", "ilLearningProgressGUI"), ""));
127  }
128  if($ilAccess->checkAccess("write", "", $_GET["ref_id"]) && !$this->recursive){
129  if($this->staff == "employee")
130  $this->addEmployeeActions($selection);
131  if($this->staff == "superior")
132  $this->addSuperiorActions($selection);
133  }
134  $this->tpl->setVariable("ACTIONS", $selection->getHTML());
135 
136  }
137 
141  protected function addEmployeeActions(&$selection){
142  $selection->addItem($this->lng->txt("remove"), "delete_from_employees", $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "confirmRemoveFromEmployees"));
143  $selection->addItem($this->lng->txt("change_to_superior"), "change_to_superior", $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "fromEmployeeToSuperior"));
144  }
145 
149  protected function addSuperiorActions(&$selection){
150  $selection->addItem($this->lng->txt("remove"), "delete_from_superiors", $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "confirmRemoveFromSuperiors"));
151  $selection->addItem($this->lng->txt("change_to_employee"), "change_to_employee", $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "fromSuperiorToEmployee"));
152  }
153 
157  public function setRecursive($recursive){
158  $this->recursive = $recursive;
159  }
160 
161 
162 }
163 ?>