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