ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilObjStudyProgrammeMembersGUI.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 
20  public $ctrl;
21 
25  public $tpl;
26 
30  protected $ilAccess;
31 
35  public $object;
36 
40  protected $ilLog;
41 
45  public $ilias;
46 
50  public $lng;
51 
55  public $toolbar;
56 
60  public $user;
61 
62  protected $parent_gui;
63 
64  public function __construct($a_parent_gui, $a_ref_id) {
65  global $tpl, $ilCtrl, $ilAccess, $ilToolbar, $ilLocator, $tree, $lng, $ilLog, $ilias, $ilUser;
66 
67  $this->ref_id = $a_ref_id;
68  $this->parent_gui = $a_parent_gui;
69  $this->tpl = $tpl;
70  $this->ctrl = $ilCtrl;
71  $this->ilAccess = $ilAccess;
72  $this->ilLocator = $ilLocator;
73  $this->tree = $tree;
74  $this->toolbar = $ilToolbar;
75  $this->ilLog = $ilLog;
76  $this->ilias = $ilias;
77  $this->lng = $lng;
78  $this->user = $ilUser;
79  $this->progress_object = null;
80 
81  $this->object = null;
82 
83  $lng->loadLanguageModule("prg");
84  }
85 
86  public function executeCommand() {
87  $cmd = $this->ctrl->getCmd();
88  $next_class = $this->ctrl->getNextClass($this);
89 
90 
91  if ($cmd == "") {
92  $cmd = "view";
93  }
94 
95  # TODO: Check permission of user!!
96 
97  switch ($next_class) {
98  case "ilstudyprogrammerepositorysearchgui":
99  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeRepositorySearchGUI.php");
100  $rep_search = new ilStudyProgrammeRepositorySearchGUI();
101  $rep_search->setCallback($this, "addUsers");
102 
103  $this->ctrl->setReturn($this, "view");
104  $this->ctrl->forwardCommand($rep_search);
105  return;
106  case "ilobjstudyprogrammeindividualplangui":
107  require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeIndividualPlanGUI.php");
108  $individual_plan_gui = new ilObjStudyProgrammeIndividualPlanGUI( $this, $this->ref_id);
109  $this->ctrl->forwardCommand($individual_plan_gui);
110  return;
111  case false:
112  switch ($cmd) {
113  case "view":
114  case "markAccredited":
115  case "unmarkAccredited":
116  case "removeUser":
117  case "addUsersWithAcknowledgedCourses":
118  $cont = $this->$cmd();
119  break;
120  default:
121  throw new ilException("ilObjStudyProgrammeMembersGUI: ".
122  "Command not supported: $cmd");
123  }
124  break;
125  default:
126  throw new ilException("ilObjStudyProgrammeMembersGUI: Can't forward to next class $next_class");
127  }
128 
129  $this->tpl->setContent($cont);
130  }
131 
132  protected function view() {
133  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeMembersTableGUI.php");
134 
135  if ($this->getStudyProgramme()->isActive()) {
136  $this->initSearchGUI();
137  }
138 
139  if (!$this->getStudyProgramme()->isActive()) {
140  ilUtil::sendInfo($this->lng->txt("prg_no_members_not_active"));
141  }
142 
143  $prg_id = ilObject::_lookupObjId($this->ref_id);
144  $table = new ilStudyProgrammeMembersTableGUI($prg_id, $this->ref_id, $this);
145  return $table->getHTML();
146  }
147 
148  public function addUsers($a_users) {
149  $prg = $this->getStudyProgramme();
150 
151  $completed_courses = array();
152 
153  foreach ($a_users as $user_id) {
154  $completed_crss = $prg->getCompletedCourses($user_id);
155  if ($completed_crss) {
156  $completed_courses[$user_id] = $completed_crss;
157  }
158  }
159 
160  if (count($completed_courses) > 0) {
161  $this->viewCompletedCourses($completed_courses, $a_users);
162  return true;
163  }
164 
165  $this->_addUsers($a_users);
166 
167  $this->ctrl->redirect($this, "view");
168  }
169 
170  public function viewCompletedCourses($a_completed_courses, $a_users) {
171  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeAcknowledgeCompletedCoursesTableGUI.php");
172 
173  $tpl = new ilTemplate("tpl.acknowledge_completed_courses.html", true, true, "Modules/StudyProgramme");
174  $tpl->setVariable("TITLE", $this->lng->txt("prg_acknowledge_completed_courses"));
175  $tpl->setVariable("CAPTION_ADD", $this->lng->txt("btn_next"));
176  $tpl->setVariable("CAPTION_CANCEL", $this->lng->txt("cancel"));
177  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
178  $tpl->setVariable("ADD_CMD", "addUsersWithAcknowledgedCourses");
179  $tpl->setVariable("CANCEL_CMD", "view");
180 
181  foreach ($a_completed_courses as $user_id => $completed_courses) {
182  $names = ilObjUser::_lookupName($user_id);
183  $tpl->setCurrentBlock("usr_section");
184  $tpl->setVariable("FIRSTNAME", $names["firstname"]);
185  $tpl->setVariable("LASTNAME", $names["lastname"]);
186  $table = new ilStudyProgrammeAcknowledgeCompletedCoursesTableGUI($this, $user_id, $completed_courses);
187  $tpl->setVariable("TABLE", $table->getHTML());
188  $tpl->parseCurrentBlock();
189  }
190 
191  foreach ($a_users as $usr_id) {
192  $tpl->setCurrentBlock("usr_ids_section");
193  $tpl->setVariable("USR_ID", $usr_id);
194  $tpl->parseCurrentBlock();
195  }
196 
197  $this->tpl->setContent($tpl->get());
198  }
199 
201  $users = $_POST["users"];
202  $assignments = $this->_addUsers($users);
203 
204  $completed_programmes = $_POST["courses"];
205  foreach ($completed_programmes as $user_id => $prg_ref_ids) {
206  $ass_id = $assignments[$user_id]->getId();
207  foreach ($prg_ref_ids as $ids) {
208  list($prg_ref_id, $crs_id, $crsr_id) = split(";", $ids);
209  $prg = $this->getStudyProgramme($prg_ref_id);
210  $progress = $prg->getProgressForAssignment($ass_id);
211  $progress->setLPCompleted($crsr_id, $user_id);
212  }
213  }
214 
215  $this->ctrl->redirect($this, "view");
216  }
217 
218  protected function _addUsers($a_users) {
219  $prg = $this->getStudyProgramme();
220 
221  $assignments = array();
222 
223  foreach ($a_users as $user_id) {
224  $assignments[$user_id] = $prg->assignUser($user_id);
225  }
226 
227  if (count($a_users) == 1) {
228  ilUtil::sendSuccess($this->lng->txt("prg_added_member"), true);
229  }
230  if (count($a_users) > 1) {
231  ilUtil::sendSuccess($this->lng->txt("prg_added_members"), true);
232  }
233 
234  return $assignments;
235  }
236 
237  public function markAccredited() {
238  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
239  $prgrs = $this->getProgressObject();
240  $prgrs->markAccredited($this->user->getId());
241  $this->showSuccessMessage("mark_accredited_success");
242  $this->ctrl->redirect($this, "view");
243  }
244 
245  public function unmarkAccredited() {
246  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
247  $prgrs = $this->getProgressObject();
248  $prgrs->unmarkAccredited();
249  $this->showSuccessMessage("unmark_accredited_success");
250  $this->ctrl->redirect($this, "view");
251  }
252 
253  public function removeUser() {
254  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
255  $prgrs = $this->getProgressObject();
256  $ass = $prgrs->getAssignment();
257  $prg = $ass->getStudyProgramme();
258  if ($prg->getRefId() != $this->ref_id) {
259  throw new ilException("Can only remove users from the node they where assigned to.");
260  }
261  $ass->deassign();
262  $this->showSuccessMessage("remove_user_success");
263  $this->ctrl->redirect($this, "view");
264  }
265 
266  protected function getProgressObject() {
267  if ($this->progress_object === null) {
268  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
269  if (!is_numeric($_GET["prgrs_id"])) {
270  throw new ilException("Expected integer 'prgrs_id'");
271  }
272  $id = (int)$_GET["prgrs_id"];
273  $this->progress_object = ilStudyProgrammeUserProgress::getInstanceById($id);
274  }
275  return $this->progress_object;
276  }
277 
278  protected function showSuccessMessage($a_lng_var) {
279  require_once("Services/Utilities/classes/class.ilUtil.php");
280  ilUtil::sendSuccess($this->lng->txt("prg_$a_lng_var"), true);
281  }
282 
283  protected function initSearchGUI() {
284  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeRepositorySearchGUI.php");
286  $this,
287  $this->toolbar,
288  array(
289  "auto_complete_name" => $this->lng->txt("user"),
290  "submit_name" => $this->lng->txt("add"),
291  "add_search" => true
292  )
293  );
294  }
295 
296  public function getStudyProgramme($a_ref_id = null) {
297  if ($a_ref_id === null) {
298  $a_ref_id = $this->ref_id;
299  }
300  require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
301  return ilObjStudyProgramme::getInstanceByRefId($a_ref_id);
302  }
303 
312  public function getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id) {
313  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
314 
315  switch ($a_action) {
317  $target_name = "markAccredited";
318  break;
320  $target_name = "unmarkAccredited";
321  break;
323  require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgrammeIndividualPlanGUI.php");
324  return ilObjStudyProgrammeIndividualPlanGUI::getLinkTargetView($this->ctrl, $a_ass_id);
326  $target_name = "removeUser";
327  break;
328  default:
329  throw new ilException("Unknown action: $action");
330  }
331 
332  $this->ctrl->setParameter($this, "prgrs_id", $a_prgrs_id);
333  $link = $this->ctrl->getLinkTarget($this, $target_name);
334  $this->ctrl->setParameter($this, "prgrs_id", null);
335  return $link;
336  }
337 }
338 
339 ?>
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupName($a_user_id)
lookup user name
Base class for ILIAS Exception handling.
$_POST['username']
Definition: cron.php:12
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
logging
Definition: class.ilLog.php:18
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
This is just the same as in the parent class, except for the hardcoded class name.
global $ilCtrl
Definition: ilias.php:18
Class ilObjStudyProgrammeMembersTableGUI.
static getInstanceByRefId($a_ref_id)
Get an instance of ilObjStudyProgramme, use cache.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id)
Get the link target for an action on user progress.
viewCompletedCourses($a_completed_courses, $a_users)
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
redirection script todo: (a better solution should control the processing via a xml file) ...
Class ilObjStudyProgrammeMembersGUI.
TableGUI class for acknowledgement of completed courses for new members of a study programme...
Custom repository search gui class for study programme to make it possible to get a handle on users s...
global $ilUser
Definition: imgupload.php:15
$ref_id
Definition: sahs_server.php:39
static getInstanceById($a_prgrs_id)
Get an instance by progress id.