ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
17 {
21  public $ctrl;
22 
26  public $tpl;
27 
31  protected $ilAccess;
32 
36  public $object;
37 
41  protected $ilLog;
42 
46  public $ilias;
47 
51  public $lng;
52 
56  public $toolbar;
57 
61  public $user;
62 
63  protected $parent_gui;
64 
69 
73  protected $progress_objects;
74 
75  public function __construct($a_parent_gui, $a_ref_id, ilStudyProgrammeUserProgressDB $sp_user_progress_db)
76  {
77  global $DIC;
78  $tpl = $DIC['tpl'];
79  $ilCtrl = $DIC['ilCtrl'];
80  $ilAccess = $DIC['ilAccess'];
81  $ilToolbar = $DIC['ilToolbar'];
82  $ilLocator = $DIC['ilLocator'];
83  $tree = $DIC['tree'];
84  $lng = $DIC['lng'];
85  $ilLog = $DIC['ilLog'];
86  $ilias = $DIC['ilias'];
87  $ilUser = $DIC['ilUser'];
88 
89  $this->ref_id = $a_ref_id;
90  $this->parent_gui = $a_parent_gui;
91  $this->tpl = $tpl;
92  $this->ctrl = $ilCtrl;
93  $this->ilAccess = $ilAccess;
94  $this->ilLocator = $ilLocator;
95  $this->tree = $tree;
96  $this->toolbar = $ilToolbar;
97  $this->ilLog = $ilLog;
98  $this->ilias = $ilias;
99  $this->lng = $lng;
100  $this->user = $ilUser;
101  $this->sp_user_progress_db = $sp_user_progress_db;
102  $this->progress_objects = array();
103 
104  $this->object = null;
105 
106  $lng->loadLanguageModule("prg");
107  }
108 
109  public function executeCommand()
110  {
111  $cmd = $this->ctrl->getCmd();
112  $next_class = $this->ctrl->getNextClass($this);
113 
114  if ($cmd == "") {
115  $cmd = "view";
116  }
117 
118  # TODO: Check permission of user!!
119 
120  switch ($next_class) {
121  case "ilstudyprogrammerepositorysearchgui":
122  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeRepositorySearchGUI.php");
123  $rep_search = new ilStudyProgrammeRepositorySearchGUI();
124  $rep_search->setCallback($this, "addUsers");
125 
126  $this->ctrl->setReturn($this, "view");
127  $this->ctrl->forwardCommand($rep_search);
128  return;
129  case "ilobjstudyprogrammeindividualplangui":
130  require_once("./Modules/StudyProgramme/classes/class.ilObjStudyProgrammeIndividualPlanGUI.php");
131  $individual_plan_gui = new ilObjStudyProgrammeIndividualPlanGUI($this, $this->ref_id, $this->sp_user_progress_db);
132  $this->ctrl->forwardCommand($individual_plan_gui);
133  return;
134  case false:
135  switch ($cmd) {
136  case "view":
137  case "markAccredited":
138  case "markAccreditedMulti":
139  case "unmarkAccredited":
140  case "unmarkAccreditedMulti":
141  case "removeUser":
142  case "removeUserMulti":
143  case "addUsersWithAcknowledgedCourses":
144  case "markNotRelevantMulti":
145  case "markRelevantMulti":
146  case "updateFromCurrentPlanMulti":
147  $cont = $this->$cmd();
148  break;
149  default:
150  throw new ilException("ilObjStudyProgrammeMembersGUI: " .
151  "Command not supported: $cmd");
152  }
153  break;
154  default:
155  throw new ilException("ilObjStudyProgrammeMembersGUI: Can't forward to next class $next_class");
156  }
157 
158  $this->tpl->setContent($cont);
159  }
160 
166  protected function view()
167  {
168  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeMembersTableGUI.php");
169 
170  if ($this->getStudyProgramme()->isActive()) {
171  $this->initSearchGUI();
172  }
173 
174  if (!$this->getStudyProgramme()->isActive()) {
175  ilUtil::sendInfo($this->lng->txt("prg_no_members_not_active"));
176  }
177 
178  $prg_id = ilObject::_lookupObjId($this->ref_id);
179  $table = new ilStudyProgrammeMembersTableGUI($prg_id, $this->ref_id, $this, "view", "", $this->sp_user_progress_db);
180  return $table->getHTML();
181  }
182 
190  public function addUsers($a_users)
191  {
192  $prg = $this->getStudyProgramme();
193 
194  $completed_courses = array();
195 
196  foreach ($a_users as $user_id) {
197  $completed_crss = $prg->getCompletedCourses($user_id);
198  if ($completed_crss) {
199  $completed_courses[$user_id] = $completed_crss;
200  }
201  }
202 
203  if (count($completed_courses) > 0) {
204  $this->viewCompletedCourses($completed_courses, $a_users);
205  return true;
206  }
207 
208  $this->_addUsers($a_users);
209 
210  $this->ctrl->redirect($this, "view");
211  }
212 
221  public function viewCompletedCourses($a_completed_courses, $a_users)
222  {
223  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeAcknowledgeCompletedCoursesTableGUI.php");
224 
225  $tpl = new ilTemplate("tpl.acknowledge_completed_courses.html", true, true, "Modules/StudyProgramme");
226  $tpl->setVariable("TITLE", $this->lng->txt("prg_acknowledge_completed_courses"));
227  $tpl->setVariable("CAPTION_ADD", $this->lng->txt("btn_next"));
228  $tpl->setVariable("CAPTION_CANCEL", $this->lng->txt("cancel"));
229  $tpl->setVariable("FORM_ACTION", $this->ctrl->getFormAction($this));
230  $tpl->setVariable("ADD_CMD", "addUsersWithAcknowledgedCourses");
231  $tpl->setVariable("CANCEL_CMD", "view");
232 
233  foreach ($a_completed_courses as $user_id => $completed_courses) {
234  $names = ilObjUser::_lookupName($user_id);
235  $tpl->setCurrentBlock("usr_section");
236  $tpl->setVariable("FIRSTNAME", $names["firstname"]);
237  $tpl->setVariable("LASTNAME", $names["lastname"]);
238  $table = new ilStudyProgrammeAcknowledgeCompletedCoursesTableGUI($this, $user_id, $completed_courses);
239  $tpl->setVariable("TABLE", $table->getHTML());
240  $tpl->parseCurrentBlock();
241  }
242 
243  foreach ($a_users as $usr_id) {
244  $tpl->setCurrentBlock("usr_ids_section");
245  $tpl->setVariable("USR_ID", $usr_id);
246  $tpl->parseCurrentBlock();
247  }
248 
249  $this->tpl->setContent($tpl->get());
250  }
251 
258  {
259  $users = $_POST["users"];
260  $assignments = $this->_addUsers($users);
261 
262  $completed_programmes = $_POST["courses"];
263  if (is_array($completed_programmes)) {
264  foreach ($completed_programmes as $user_id => $prg_ref_ids) {
265  $ass_id = $assignments[$user_id]->getId();
266  foreach ($prg_ref_ids as $ids) {
267  list($prg_ref_id, $crs_id, $crsr_id) = explode(";", $ids);
268  $prg = $this->getStudyProgramme($prg_ref_id);
269  $progress = $prg->getProgressForAssignment($ass_id);
270  $progress->setLPCompleted($crsr_id, $user_id);
271  }
272  }
273  }
274 
275  $this->ctrl->redirect($this, "view");
276  }
277 
285  protected function _addUsers($a_users)
286  {
287  $prg = $this->getStudyProgramme();
288 
289  $assignments = array();
290 
291  foreach ($a_users as $user_id) {
292  $assignments[$user_id] = $prg->assignUser($user_id);
293  }
294 
295  if (count($a_users) == 1) {
296  ilUtil::sendSuccess($this->lng->txt("prg_added_member"), true);
297  }
298  if (count($a_users) > 1) {
299  ilUtil::sendSuccess($this->lng->txt("prg_added_members"), true);
300  }
301 
302  return $assignments;
303  }
304 
310  protected function getPostPrgsIds()
311  {
312  $prgrs_ids = $_POST['prgs_ids'];
313  if ($prgrs_ids === null) {
314  $this->showInfoMessage("no_user_selected");
315  $this->ctrl->redirect($this, "view");
316  }
317  return $prgrs_ids;
318  }
319 
325  public function markAccredited()
326  {
327  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
328  $prgrs_id = $this->getPrgrsId();
329  $this->markAccreditedById($prgrs_id);
330  $this->showSuccessMessage("mark_accredited_success");
331  $this->ctrl->redirect($this, "view");
332  }
333 
339  public function markAccreditedMulti()
340  {
341  $prgrs_ids = $this->getPostPrgsIds();
342  foreach ($prgrs_ids as $key => $prgrs_id) {
343  $this->markAccreditedById((int) $prgrs_id);
344  }
345  $this->showSuccessMessage("mark_accredited_multi_success");
346  $this->ctrl->redirect($this, "view");
347  }
348 
356  protected function markAccreditedById($prgrs_id)
357  {
358  $prgrs = $this->getProgressObject($prgrs_id);
359  $prgrs->markAccredited($this->user->getId());
360  }
361 
367  public function unmarkAccredited()
368  {
369  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
370  $prgrs_id = $this->getPrgrsId();
371  $this->unmarkAccreditedByProgressId($prgrs_id);
372  $this->showSuccessMessage("unmark_accredited_success");
373  $this->ctrl->redirect($this, "view");
374  }
375 
383  protected function unmarkAccreditedByProgressId($prgrs_id)
384  {
385  $prgrs = $this->getProgressObject($prgrs_id);
386  $prgrs->unmarkAccredited();
387  }
388 
394  public function unmarkAccreditedMulti()
395  {
396  $prgrs_ids = $this->getPostPrgsIds();
397  foreach ($prgrs_ids as $key => $prgrs_id) {
398  if ($this->getProgressObject((int) $prgrs_id)->getStatus() == ilStudyProgrammeProgress::STATUS_ACCREDITED) {
399  $this->unmarkAccreditedByProgressId((int) $prgrs_id);
400  }
401  }
402  $this->showSuccessMessage("unmark_accredited_multi_success");
403  $this->ctrl->redirect($this, "view");
404  }
405 
411  public function markRelevantMulti()
412  {
413  $prgrs_ids = $this->getPostPrgsIds();
414 
415  foreach ($prgrs_ids as $key => $prgrs_id) {
416  $prgrs = $this->getProgressObject((int) $prgrs_id);
417  if (
418  $this->getProgressObject((int) $prgrs_id)->getStatus() == ilStudyProgrammeProgress::STATUS_IN_PROGRESS ||
419  $this->getProgressObject((int) $prgrs_id)->getStatus() == ilStudyProgrammeProgress::STATUS_ACCREDITED
420  ) {
421  continue;
422  }
423  $prgrs->markRelevant($this->user->getId());
424  }
425 
426  $this->showSuccessMessage("mark_relevant_multi_success");
427  $this->ctrl->redirect($this, "view");
428  }
429 
435  public function markNotRelevantMulti()
436  {
437  $prgrs_ids = $this->getPostPrgsIds();
438 
439  foreach ($prgrs_ids as $key => $prgrs_id) {
440  $prgrs = $this->getProgressObject((int) $prgrs_id);
441  $prgrs->markNotRelevant($this->user->getId());
442  }
443 
444  $this->showSuccessMessage("mark_not_relevant_multi_success");
445  $this->ctrl->redirect($this, "view");
446  }
447 
453  public function updateFromCurrentPlanMulti()
454  {
455  $prgrs_ids = $this->getPostPrgsIds();
456  $not_updated = array();
457 
458  foreach ($prgrs_ids as $key => $prgrs_id) {
459  $prgrs = $this->getProgressObject((int) $prgrs_id);
460  $ass = $prgrs->getAssignment();
461  $prg = $ass->getStudyProgramme();
462  if ($prg->getRefId() != $this->ref_id) {
463  $not_updated[] = $prgrs_id;
464  continue;
465  }
466 
467  $ass->updateFromProgram();
468  }
469 
470  if (count($not_updated) == count($prgrs_ids)) {
471  $this->showInfoMessage("update_from_current_plan_not_possible");
472  } elseif (count($not_updated) > 0) {
473  $this->showSuccessMessage("update_from_current_plan_partitial_success");
474  } else {
475  $this->showSuccessMessage("update_from_current_plan_success");
476  }
477 
478  $this->ctrl->redirect($this, "view");
479  }
480 
486  public function removeUser()
487  {
488  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
489  $prgrs_id = $this->getPrgrsId();
490  $this->remove($prgrs_id);
491  $this->showSuccessMessage("remove_user_success");
492  $this->ctrl->redirect($this, "view");
493  }
494 
500  protected function removeUserMulti()
501  {
502  $prgrs_ids = $this->getPostPrgsIds();
503  $not_removed = array();
504  foreach ($prgrs_ids as $key => $prgrs_id) {
505  try {
506  $this->remove((int) $prgrs_id);
507  } catch (ilException $e) {
508  $not_removed[] = $prgrs_id;
509  }
510  }
511  if (count($not_removed) == count($prgrs_ids)) {
512  $this->showInfoMessage("remove_users_not_possible");
513  } elseif (count($not_removed) > 0) {
514  $this->showSuccessMessage("remove_users_partitial_success");
515  } else {
516  $this->showSuccessMessage("remove_users_success");
517  }
518  $this->ctrl->redirect($this, "view");
519  }
520 
528  protected function remove($prgrs_id)
529  {
530  $prgrs = $this->getProgressObject($prgrs_id);
531  $ass = $prgrs->getAssignment();
532  $prg = $ass->getStudyProgramme();
533  if ($prg->getRefId() != $this->ref_id) {
534  throw new ilException("Can only remove users from the node they where assigned to.");
535  }
536  $ass->deassign();
537  }
538 
546  protected function getProgressObject($prgrs_id)
547  {
548  assert('is_int($prgrs_id)');
549  if (!array_key_exists($prgrs_id, $this->progress_objects)) {
550  require_once("Modules/StudyProgramme/classes/class.ilStudyProgrammeUserProgress.php");
551  $this->progress_objects[$prgrs_id] = $this->sp_user_progress_db->getInstanceById($prgrs_id);
552  }
553  return $this->progress_objects[$prgrs_id];
554  }
555 
563  protected function getPrgrsId()
564  {
565  if (!is_numeric($_GET["prgrs_id"])) {
566  throw new ilException("Expected integer 'prgrs_id'");
567  }
568  return (int) $_GET["prgrs_id"];
569  }
570 
576  protected function showSuccessMessage($a_lng_var)
577  {
578  require_once("Services/Utilities/classes/class.ilUtil.php");
579  ilUtil::sendSuccess($this->lng->txt("prg_$a_lng_var"), true);
580  }
581 
587  protected function showInfoMessage($a_lng_var)
588  {
589  require_once("Services/Utilities/classes/class.ilUtil.php");
590  ilUtil::sendInfo($this->lng->txt("prg_$a_lng_var"), true);
591  }
592 
593  protected function initSearchGUI()
594  {
595  require_once("./Modules/StudyProgramme/classes/class.ilStudyProgrammeRepositorySearchGUI.php");
597  $this,
598  $this->toolbar,
599  array(
600  "auto_complete_name" => $this->lng->txt("user"),
601  "submit_name" => $this->lng->txt("add"),
602  "add_search" => true
603  )
604  );
605  }
606 
613  public function getStudyProgramme($a_ref_id = null)
614  {
615  if ($a_ref_id === null) {
616  $a_ref_id = $this->ref_id;
617  }
618  require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgramme.php");
619  return ilObjStudyProgramme::getInstanceByRefId($a_ref_id);
620  }
621 
630  public function getLinkTargetForAction($a_action, $a_prgrs_id, $a_ass_id)
631  {
632  switch ($a_action) {
634  $target_name = "markAccredited";
635  break;
637  $target_name = "unmarkAccredited";
638  break;
640  require_once("Modules/StudyProgramme/classes/class.ilObjStudyProgrammeIndividualPlanGUI.php");
641  return ilObjStudyProgrammeIndividualPlanGUI::getLinkTargetView($this->ctrl, $a_ass_id);
643  $target_name = "removeUser";
644  break;
645  default:
646  throw new ilException("Unknown action: $action");
647  }
648 
649  $this->ctrl->setParameter($this, "prgrs_id", $a_prgrs_id);
650  $link = $this->ctrl->getLinkTarget($this, $target_name);
651  $this->ctrl->setParameter($this, "prgrs_id", null);
652  return $link;
653  }
654 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static _lookupName($a_user_id)
lookup user name
markNotRelevantMulti()
Mark SP as not relevant for users.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
Storage implementation for ilStudyProgrammeUserProgress.
logging
Definition: class.ilLog.php:18
markAccreditedMulti()
Mark SP for users accredited.
Class ilAccessHandler.
showInfoMessage($a_lng_var)
Shows ilutil failed message.
user()
Definition: user.php:4
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.
addUsersWithAcknowledgedCourses()
Assign users if they have any completed course.
markRelevantMulti()
Mark SP as relevant for users.
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.
unmarkAccreditedByProgressId($prgrs_id)
Deaccredited SP.
viewCompletedCourses($a_completed_courses, $a_users)
Shows list of completed courses for each user if he should be assigned.
markAccredited()
Mark SP for single user accredited.
static _lookupObjId($a_id)
special template class to simplify handling of ITX/PEAR
view()
Shows table with all members of the SP.
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
Class ilObjStudyProgrammeMembersGUI.
Create styles array
The data for the language used.
__construct($a_parent_gui, $a_ref_id, ilStudyProgrammeUserProgressDB $sp_user_progress_db)
getStudyProgramme($a_ref_id=null)
Get studyprogramm object for ref_id Use this ref_id if argument is null.
$users
Definition: authpage.php:44
getProgressObject($prgrs_id)
Get progress object for prgrs id.
updateFromCurrentPlanMulti()
Update user plan from current SP structure if they has no individual plan.
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...
showSuccessMessage($a_lng_var)
Shows ilutil success message.
if(empty($password)) $table
Definition: pwgen.php:24
$key
Definition: croninfo.php:18
$_POST["username"]
unmarkAccredited()
Unmark SP for single user accredited.
unmarkAccreditedMulti()
Unmark SP for users accredited.