ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilExSubmissionTeamGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
13 {
17  protected $ctrl;
18 
22  protected $tabs_gui;
23 
27  protected $lng;
28 
32  protected $tpl;
33 
37  protected $toolbar;
38 
42  protected $user;
43 
44  protected $exercise; // [ilObjExercise]
45  protected $assignment; // [ilExAssignment]
46  protected $submission; // [ilExSubmission]
47  protected $team; // [ilExAssignmentTeam]
48 
49  public function __construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
50  {
51  global $DIC;
52 
53  $this->toolbar = $DIC->toolbar();
54  $this->user = $DIC->user();
55  $ilCtrl = $DIC->ctrl();
56  $ilTabs = $DIC->tabs();
57  $lng = $DIC->language();
58  $tpl = $DIC["tpl"];
59 
60  $this->exercise = $a_exercise;
61  $this->submission = $a_submission;
62  $this->assignment = $a_submission->getAssignment();
63 
64  // :TODO:
65  $this->ctrl = $ilCtrl;
66  $this->tabs_gui = $ilTabs;
67  $this->lng = $lng;
68  $this->tpl = $tpl;
69  }
70 
71  public function executeCommand()
72  {
74 
75  $class = $ilCtrl->getNextClass($this);
76  $cmd = $ilCtrl->getCmd("submissionScreenTeam");
77 
78  if (!$this->assignment->hasTeam() ||
79  !$this->submission->canView()) {
80  return;
81  }
82  $this->team = $this->submission->getTeam();
83 
84  if (!$this->submission->isTutor()) {
85  self::handleTabs();
86  $this->tabs_gui->activateTab("team");
87  }
88 
89  switch ($class) {
90  case 'ilrepositorysearchgui':
91  $this->ctrl->setReturn($this, 'submissionScreenTeam');
92  include_once('./Services/Search/classes/class.ilRepositorySearchGUI.php');
93  $rep_search = new ilRepositorySearchGUI();
94  if (!$this->submission->isTutor()) {
95  $rep_search->setPrivacyMode(ilUserAutoComplete::PRIVACY_MODE_RESPECT_USER_SETTING);
96  }
97  $rep_search->setTitle($this->lng->txt("exc_team_member_add"));
98  $rep_search->setCallback($this, 'addTeamMemberActionObject');
99  $this->ctrl->forwardCommand($rep_search);
100  break;
101 
102  default:
103  $this->{$cmd . "Object"}();
104  break;
105  }
106  }
107 
108  public static function getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
109  {
110  global $DIC;
111 
112  $lng = $DIC->language();
113  $ilCtrl = $DIC->ctrl();
114 
115  if (!$a_submission->getAssignment()->hasTeam()) {
116  return;
117  }
118 
119  $state = ilExcAssMemberState::getInstanceByIds($a_submission->getAssignment()->getId(), $a_submission->getUserId());
120 
121  $team_members = $a_submission->getTeam()->getMembers();
122  if (sizeof($team_members)) { // we have a team
123  $team = array();
124  foreach ($team_members as $member_id) {
125  //$team[] = ilObjUser::_lookupFullname($member_id);
126  include_once("./Services/User/classes/class.ilUserUtil.php");
127  $team[] = ilUserUtil::getNamePresentation($member_id, false, false, "", false);
128  }
129  $team = implode("; ", $team);
130 
131  if (!$a_submission->getAssignment()->getTeamTutor()) {
132  #23685
133  // any team member upload?
134  if (!$a_submission->getLastSubmission()) {
135  $button = ilLinkButton::getInstance();
136  $button->setCaption("exc_delete_team");
137  $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTeamGUI"), "confirmDeleteTeam"));
138  $team .= " " . $button->render();
139  }
140  $button = ilLinkButton::getInstance();
141  $button->setCaption("exc_manage_team");
142  $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTeamGUI"), "submissionScreenTeam"));
143  } else {
144  $button = ilLinkButton::getInstance();
145  $button->setCaption("exc_team_log");
146  $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTeamGUI"), "submissionScreenTeamLog"));
147  }
148  $team .= "<br><br>" . $button->render();
149 
150  $a_info->addProperty($lng->txt("exc_team_members"), $team);
151  } else {
152  //if($a_submission->getAssignment()->beforeDeadline()) // this was "for all users"
153  if (!$state->hasSubmissionEnded()) { // this is for current user/team -> no team creation, if no submission possible
154  if (!$a_submission->hasSubmitted()) {
155  $team_info = $lng->txt("exc_no_team_yet_notice");
156  } else {
157  $team_info = '<span class="warning">' . $lng->txt("exc_no_team_yet_notice") . '</span>';
158  }
159 
160  if (!$a_submission->getAssignment()->getTeamTutor()) {
161  $button = ilLinkButton::getInstance();
162  $button->setPrimary(true);
163  $button->setCaption("exc_create_team"); // team creation
164  $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTeamGUI"), "createTeam"));
165  $team_info .= " " . $button->render();
166 
167  $team_info .= '<div class="ilFormInfo">' . $lng->txt("exc_no_team_yet_info") . '</div>';
168  } else {
169  $team_info .= '<div class="ilFormInfo">' . $lng->txt("exc_no_team_yet_info_tutor") . '</div>';
170  }
171  } else {
172  $team_info = '<span class="warning">' . $lng->txt("exc_create_team_times_up_warning") . '</span>';
173  }
174 
175  $a_info->addProperty($lng->txt("exc_team_members"), $team_info);
176  }
177  }
178 
179  public function returnToParentObject()
180  {
181  $this->ctrl->returnToParent($this);
182  }
183 
184  public static function handleTabs()
185  {
186  global $DIC;
187 
188  $ilTabs = $DIC->tabs();
189  $ilCtrl = $DIC->ctrl();
190  $lng = $DIC->language();
191 
192  $ilTabs->addTab(
193  "team",
194  $lng->txt("exc_team"),
195  $ilCtrl->getLinkTargetByClass("ilExSubmissionTeamGUI", "submissionScreenTeam")
196  );
197 
198  $ilTabs->addTab(
199  "log",
200  $lng->txt("exc_team_log"),
201  $ilCtrl->getLinkTargetByClass("ilExSubmissionTeamGUI", "submissionScreenTeamLog")
202  );
203  }
204 
205  protected function canEditTeam()
206  {
207  return (($this->submission->canSubmit() &&
208  !$this->submission->getAssignment()->getTeamTutor()) ||
209  $this->submission->isTutor());
210  }
211 
217  public function submissionScreenTeamObject()
218  {
219  $ilToolbar = $this->toolbar;
220 
221  // #13414
222  $read_only = !$this->canEditTeam();
223 
224  if ($this->submission->getAssignment()->afterDeadlineStrict(false)) {
225  ilUtil::sendInfo($this->lng->txt("exercise_time_over"));
226  } elseif (!$read_only) {
227  $add_search = $this->submission->isTutor();
228  // add member
229  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
231  $this,
232  $ilToolbar,
233  array(
234  'auto_complete_name' => $this->lng->txt('user'),
235  'submit_name' => $this->lng->txt('add'),
236  'add_search' => $add_search,
237  'add_from_container' => $this->exercise->getRefId()
238  )
239  );
240  } elseif ($this->submission->getAssignment()->getTeamTutor()) {
241  ilUtil::sendInfo($this->lng->txt("exc_no_team_yet_info_tutor"));
242  }
243 
244  include_once "Modules/Exercise/classes/class.ilExAssignmentTeamTableGUI.php";
246  $this,
247  "submissionScreenTeam",
249  $this->exercise->getRefId(),
250  $this->team,
251  $read_only
252  );
253 
254  $this->tpl->setContent($tbl->getHTML());
255  }
256 
257  public function addTeamMemberActionObject($a_user_ids = array())
258  {
259  if (!$this->canEditTeam()) {
260  $this->ctrl->redirect("submissionScreenTeam");
261  }
262 
263  if (!count($a_user_ids)) {
264  ilUtil::sendFailure($this->lng->txt("no_checkbox"));
265  return false;
266  }
267 
268  $new_users = [];
269 
270  foreach ($a_user_ids as $user_id) {
271  if ($this->team->addTeamMember($user_id, $this->exercise->getRefId())) {
272  $new_users[] = $user_id;
273 
274  // #14277
275  if (!$this->exercise->members_obj->isAssigned($user_id)) {
276  $this->exercise->members_obj->assignMember($user_id);
277  }
278  } else {
279  // #11959
280  ilUtil::sendFailure($this->lng->txt("exc_members_already_assigned_team"), true);
281  }
282  }
283 
284  if (sizeof($new_users)) {
285  // re-evaluate complete team, as new member could have already submitted
286  $this->exercise->processExerciseStatus(
287  $this->assignment,
288  $this->team->getMembers(),
289  $this->submission->hasSubmitted(),
290  $this->submission->validatePeerReviews()
291  );
292  // :TODO: notification?
293  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
294  }
295 
296  $this->ctrl->redirect($this, "submissionScreenTeam");
297  }
298 
299  public function confirmDeleteTeamObject()
300  {
301  $this->confirmRemoveTeamMemberObject(true);
302  }
303 
304  public function confirmRemoveTeamMemberObject($a_full_delete = false)
305  {
307  $tpl = $this->tpl;
308 
309  if (!$this->submission->isTutor()) {
310  $ids = [];
311  if ((bool) $a_full_delete) {
312  $ids = $this->team->getMembers();
313  } elseif (isset($_POST["id"]) && is_array($_POST["id"])) {
314  $ids = $_POST["id"];
315  }
316  $ids = array_filter(array_map('intval', $ids));
317 
318  if (0 === count($ids) && !$this->canEditTeam()) {
319  ilUtil::sendFailure($this->lng->txt("select_one"), true);
320  $this->ctrl->redirect($this, "submissionScreenTeam");
321  }
322  } else {
323  $ids = array_filter(array_map('intval', array($_GET["id"])));
324  if (0 === count($ids)) {
325  $this->returnToParentObject();
326  }
327  }
328 
329  $members = $this->team->getMembers();
330  if (sizeof($members) <= sizeof($ids)) {
331  if (sizeof($members) == 1 && $members[0] == $ilUser->getId()) {
332  // direct team deletion - no confirmation
333  return $this->removeTeamMemberObject($a_full_delete);
334  } else {
335  ilUtil::sendFailure($this->lng->txt("exc_team_at_least_one"), true);
336  $this->ctrl->redirect($this, "submissionScreenTeam");
337  }
338  }
339 
340  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
341  $cgui = new ilConfirmationGUI();
342  $cgui->setFormAction($this->ctrl->getFormAction($this));
343  $cgui->setHeaderText($this->lng->txt("exc_team_member_remove_sure"));
344  $cgui->setConfirm($this->lng->txt("remove"), "removeTeamMember");
345  $cgui->setCancel($this->lng->txt("cancel"), $this->submission->isTutor()
346  ? "returnToParent"
347  : "submissionScreenTeam");
348 
349  $files = $this->submission->getFiles();
350 
351  include_once "Services/User/classes/class.ilUserUtil.php";
352 
353  foreach ($ids as $id) {
354  $details = array();
355  foreach ($files as $file) {
356  if ($file["owner_id"] == $id) {
357  $details[] = $file["filetitle"];
358  }
359  }
360  $uname = ilUserUtil::getNamePresentation($id);
361  if (sizeof($details)) {
362  $uname .= ": " . implode(", ", $details);
363  }
364  $cgui->addItem("id[]", $id, $uname);
365  }
366 
367  $tpl->setContent($cgui->getHTML());
368  }
369 
370  public function removeTeamMemberObject($a_full_delete = false)
371  {
373 
374  $cancel_cmd = $this->submission->isTutor()
375  ? "returnToParent"
376  : "submissionScreenTeam";
377 
378  $ids = [];
379  if ((bool) $a_full_delete) {
380  $ids = $this->team->getMembers();
381  } elseif (isset($_POST["id"]) && is_array($_POST["id"])) {
382  $ids = $_POST["id"];
383  }
384  $ids = array_filter(array_map('intval', $ids));
385 
386  if (0 === count($ids) && !$this->canEditTeam()) {
387  ilUtil::sendFailure($this->lng->txt("select_one"), true);
388  $this->ctrl->redirect($this, $cancel_cmd);
389  }
390 
391  $team_deleted = (bool) $a_full_delete;
392  if (!$team_deleted) {
393  $members = $this->team->getMembers();
394  if (sizeof($members) <= sizeof($ids)) {
395  if (sizeof($members) == 1 && $members[0] == $ilUser->getId()) {
396  $team_deleted = true;
397  } else {
398  ilUtil::sendFailure($this->lng->txt("exc_team_at_least_one"), true);
399  $this->ctrl->redirect($this, $cancel_cmd);
400  }
401  }
402  }
403 
404  foreach ($ids as $user_id) {
405  $this->team->removeTeamMember($user_id, $this->exercise->getRefId());
406  }
407 
408  // reset ex team members, as any submission is not valid without team
409  $this->exercise->processExerciseStatus(
410  $this->assignment,
411  $ids,
412  false
413  );
414 
415  if (!$team_deleted) {
416  // re-evaluate complete team, as removed member might have had submitted
417  $this->exercise->processExerciseStatus(
418  $this->assignment,
419  $this->team->getMembers(),
420  $this->submission->hasSubmitted(),
421  $this->submission->validatePeerReviews()
422  );
423  }
424 
425  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
426  if (!$team_deleted) {
427  $this->ctrl->redirect($this, $cancel_cmd);
428  } else {
429  $this->ctrl->redirect($this, "returnToParent");
430  }
431  }
432 
434  {
435  $this->tabs_gui->activateTab("log");
436 
437  include_once "Modules/Exercise/classes/class.ilExAssignmentTeamLogTableGUI.php";
439  $this,
440  "submissionScreenTeamLog",
441  $this->team
442  );
443 
444  $this->tpl->setContent($tbl->getHTML());
445  }
446 
448  {
450  $this->assignment->getId(),
451  $this->submission->getUserId(),
452  true
453  );
454  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
455  $this->returnToParentObject();
456  }
457 
458  public function showTeamLogObject()
459  {
460  include_once "Modules/Exercise/classes/class.ilExAssignmentTeamLogTableGUI.php";
461  $tbl = new ilExAssignmentTeamLogTableGUI($this, "showTeamLog", $this->team);
462  $this->tpl->setContent($tbl->getHTML());
463  }
464 
465  public function createTeamObject()
466  {
469  $lng = $this->lng;
470  $tpl = $this->tpl;
471 
472  if ($this->submission->canSubmit()) {
473  $options = ilExAssignmentTeam::getAdoptableTeamAssignments($this->assignment->getExerciseId(), $this->assignment->getId(), $ilUser->getId());
474  if (sizeof($options)) {
475  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
476  $form = new ilPropertyFormGUI();
477  $form->setTitle($lng->txt("exc_team_assignment_adopt_user"));
478  $form->setFormAction($ilCtrl->getFormAction($this, "createAdoptedTeam"));
479 
480  $teams = new ilRadioGroupInputGUI($lng->txt("exc_assignment"), "ass_adpt");
481  $teams->setValue(-1);
482 
483  $teams->addOption(new ilRadioOption($lng->txt("exc_team_assignment_adopt_none_user"), -1));
484 
485  $current_map = ilExAssignmentTeam::getAssignmentTeamMap($this->assignment->getId());
486 
487  include_once "Services/User/classes/class.ilUserUtil.php";
488  foreach ($options as $id => $item) {
489  $members = array();
490  $free = false;
491  foreach ($item["user_team"] as $user_id) {
492  $members[$user_id] = ilUserUtil::getNamePresentation($user_id);
493 
494  if (array_key_exists($user_id, $current_map)) {
495  $members[$user_id] .= " (" . $lng->txt("exc_team_assignment_adopt_already_assigned") . ")";
496  } else {
497  $free = true;
498  }
499  }
500  asort($members);
501  $members = implode("<br />", $members);
502  $option = new ilRadioOption($item["title"], $id);
503  $option->setInfo($members);
504  if (!$free) {
505  $option->setDisabled(true);
506  }
507  $teams->addOption($option);
508  }
509 
510  $form->addItem($teams);
511 
512  $form->addCommandButton("createAdoptedTeam", $lng->txt("save"));
513  $form->addCommandButton("returnToParent", $lng->txt("cancel"));
514 
515  $tpl->setContent($form->getHTML());
516  return;
517  }
518 
519  ilExAssignmentTeam::getTeamId($this->assignment->getId(), $ilUser->getId(), true);
520 
521  // #18046
522  if (!$this->exercise->members_obj->isAssigned($ilUser->getId())) {
523  $this->exercise->members_obj->assignMember($ilUser->getId());
524  }
525 
526  ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
527  }
528 
529  $ilCtrl->redirect($this, "returnToParent");
530  }
531 
532  public function createAdoptedTeamObject()
533  {
536  $lng = $this->lng;
537 
538  if ($this->submission->canSubmit()) {
539  $src_ass_id = (int) $_POST["ass_adpt"];
540  if ($src_ass_id > 0) {
541  ilExAssignmentTeam::adoptTeams($src_ass_id, $this->assignment->getId(), $ilUser->getId(), $this->exercise->getRefId());
542  } else {
543  ilExAssignmentTeam::getTeamId($this->assignment->getId(), $ilUser->getId(), true);
544  }
545 
546  ilUtil::sendSuccess($lng->txt("settings_saved"), true);
547  }
548 
549  $ilCtrl->redirect($this, "returnToParent");
550  }
551 
552 
557  {
558  if (!strlen(trim($_POST['user_login']))) {
559  ilUtil::sendFailure($this->lng->txt('msg_no_search_string'));
561  return false;
562  }
563 
564  $users = explode(',', $_POST['user_login']);
565 
566  $user_ids = array();
567  foreach ($users as $user) {
568  $user_id = ilObjUser::_lookupId($user);
569 
570  if (!$user_id) {
571  ilUtil::sendFailure($this->lng->txt('user_not_known'));
572  return $this->submissionScreenTeamObject();
573  }
574 
575  $user_ids[] = $user_id;
576  }
577 
578  return $this->addTeamMemberActionObject($user_ids);
579  }
580 }
This class represents an option in a radio group.
Class ilInfoScreenGUI.
$files
Definition: metarefresh.php:49
__construct(ilObjExercise $a_exercise, ilExSubmission $a_submission)
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
static getAssignmentTeamMap($a_ass_id)
Get team structure for assignment.
static getTeamId($a_assignment_id, $a_user_id, $a_create_on_demand=false)
Get team id for member id.
$_GET["client_id"]
$tbl
Definition: example_048.php:81
if(!array_key_exists('StateId', $_REQUEST)) $id
static _lookupId($a_user_str)
Lookup id by login.
static adoptTeams($a_source_ass_id, $a_target_ass_id, $a_user_id=null, $a_exc_ref_id=null)
user()
Definition: user.php:4
static getInstanceByIds($a_ass_id, $a_user_id=0)
Get instance by IDs (recommended for consumer code)
global $ilCtrl
Definition: ilias.php:18
static getAdoptableTeamAssignments($a_exercise_id, $a_exclude_ass_id=null, $a_user_id=null)
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
Class ilObjExercise.
This class represents a property in a property form.
submissionScreenTeamObject()
Displays a form which allows members to manage team uploads.
if(isset($_POST['submit'])) $form
List all team members of an assignment.
getLastSubmission()
Get the date of the last submission of a user for the assignment.
$ilUser
Definition: imgupload.php:18
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
addUserFromAutoCompleteObject()
Add user as member.
$users
Definition: authpage.php:44
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
removeTeamMemberObject($a_full_delete=false)
addProperty($a_name, $a_value, $a_link="")
add a property to current section
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
confirmRemoveTeamMemberObject($a_full_delete=false)
Exercise submission //TODO: This class has to much static methods related to delivered "files"...
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
addTeamMemberActionObject($a_user_ids=array())
$_POST["username"]
Confirmation screen class.