ILIAS  release_8 Revision v8.24
class.ilExSubmissionTeamGUI.php
Go to the documentation of this file.
1<?php
2
20
30{
31 protected ilCtrl $ctrl;
33 protected ilLanguage $lng;
36 protected ilObjUser $user;
40 protected ?ilExAssignmentTeam $team = null;
44 protected array $requested_team_ids = [];
46
47 public function __construct(
48 ilObjExercise $a_exercise,
49 ilExSubmission $a_submission
50 ) {
52 global $DIC;
53
54 $this->toolbar = $DIC->toolbar();
55 $this->user = $DIC->user();
56 $ilCtrl = $DIC->ctrl();
57 $ilTabs = $DIC->tabs();
58 $lng = $DIC->language();
59 $tpl = $DIC["tpl"];
60
61 $this->exercise = $a_exercise;
62 $this->submission = $a_submission;
63 $this->assignment = $a_submission->getAssignment();
64
65 // :TODO:
66 $this->ctrl = $ilCtrl;
67 $this->tabs_gui = $ilTabs;
68 $this->lng = $lng;
69 $this->tpl = $tpl;
70
71 $this->request = $DIC->exercise()->internal()->gui()->request();
72 $this->requested_team_ids = $this->request->getTeamIds();
73 }
74
78 public function executeCommand(): void
79 {
80 $ilCtrl = $this->ctrl;
81
82 $class = $ilCtrl->getNextClass($this);
83 $cmd = $ilCtrl->getCmd("submissionScreenTeam");
84
85 if (!$this->assignment->hasTeam() ||
86 !$this->submission->canView()) {
87 return;
88 }
89 $this->team = $this->submission->getTeam();
90
91 if (!$this->submission->isTutor()) {
93 $this->tabs_gui->activateTab("team");
94 }
95
96 switch ($class) {
97 case 'ilrepositorysearchgui':
98 $this->ctrl->setReturn($this, 'submissionScreenTeam');
99 $rep_search = new ilRepositorySearchGUI();
100 if (!$this->submission->isTutor()) {
102 }
103 $rep_search->setTitle($this->lng->txt("exc_team_member_add"));
104 $rep_search->setCallback($this, 'addTeamMemberActionObject');
105 $this->ctrl->forwardCommand($rep_search);
106 break;
107
108 default:
109 $this->{$cmd . "Object"}();
110 break;
111 }
112 }
113
114 public static function getOverviewContent(
115 ilInfoScreenGUI $a_info,
116 ilExSubmission $a_submission
117 ): void {
118 global $DIC;
119
120 $lng = $DIC->language();
121 $ilCtrl = $DIC->ctrl();
122
123 if (!$a_submission->getAssignment()->hasTeam()) {
124 return;
125 }
126
127 $state = ilExcAssMemberState::getInstanceByIds($a_submission->getAssignment()->getId(), $a_submission->getUserId());
128
129 $team_members = $a_submission->getTeam()->getMembers();
130 if ($team_members !== []) { // we have a team
131 $team = array();
132 foreach ($team_members as $member_id) {
133 //$team[] = ilObjUser::_lookupFullname($member_id);
134 $team[] = ilUserUtil::getNamePresentation($member_id, false, false, "", false);
135 }
136 $team = implode("; ", $team);
137
138 if (!$a_submission->getAssignment()->getTeamTutor()) {
139 #23685
140 // any team member upload?
141 if (!$a_submission->getLastSubmission()) {
142 $button = ilLinkButton::getInstance();
143 $button->setCaption("exc_delete_team");
144 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTeamGUI"), "confirmDeleteTeam"));
145 $team .= " " . $button->render();
146 }
147 $button = ilLinkButton::getInstance();
148 $button->setCaption("exc_manage_team");
149 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTeamGUI"), "submissionScreenTeam"));
150 } else {
151 $button = ilLinkButton::getInstance();
152 $button->setCaption("exc_team_log");
153 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTeamGUI"), "submissionScreenTeamLog"));
154 }
155 $team .= "<br><br>" . $button->render();
156
157 $a_info->addProperty($lng->txt("exc_team_members"), $team);
158 } else {
159 //if($a_submission->getAssignment()->beforeDeadline()) // this was "for all users"
160 if (!$state->hasSubmissionEnded()) { // this is for current user/team -> no team creation, if no submission possible
161 if (!$a_submission->hasSubmitted()) {
162 $team_info = $lng->txt("exc_no_team_yet_notice");
163 } else {
164 $team_info = '<span class="warning">' . $lng->txt("exc_no_team_yet_notice") . '</span>';
165 }
166
167 if (!$a_submission->getAssignment()->getTeamTutor()) {
168 $button = ilLinkButton::getInstance();
169 $button->setPrimary(true);
170 $button->setCaption("exc_create_team"); // team creation
171 $button->setUrl($ilCtrl->getLinkTargetByClass(array("ilExSubmissionGUI", "ilExSubmissionTeamGUI"), "createTeam"));
172 $team_info .= " " . $button->render();
173
174 $team_info .= '<div class="ilFormInfo">' . $lng->txt("exc_no_team_yet_info") . '</div>';
175 } else {
176 $team_info .= '<div class="ilFormInfo">' . $lng->txt("exc_no_team_yet_info_tutor") . '</div>';
177 }
178 } else {
179 $team_info = $lng->txt("exc_create_team_times_up_warning");
180 }
181
182 $a_info->addProperty($lng->txt("exc_team_members"), $team_info);
183 }
184 }
185
186 public function returnToParentObject(): void
187 {
188 $this->ctrl->returnToParent($this);
189 }
190
191 public static function handleTabs(): void
192 {
193 global $DIC;
194
195 $ilTabs = $DIC->tabs();
196 $ilCtrl = $DIC->ctrl();
197 $lng = $DIC->language();
198
199 $ilTabs->addTab(
200 "team",
201 $lng->txt("exc_team"),
202 $ilCtrl->getLinkTargetByClass("ilExSubmissionTeamGUI", "submissionScreenTeam")
203 );
204
205 $ilTabs->addTab(
206 "log",
207 $lng->txt("exc_team_log"),
208 $ilCtrl->getLinkTargetByClass("ilExSubmissionTeamGUI", "submissionScreenTeamLog")
209 );
210 }
211
212 protected function canEditTeam(): bool
213 {
214 return (($this->submission->canSubmit() &&
215 !$this->submission->getAssignment()->getTeamTutor()) ||
216 $this->submission->isTutor());
217 }
218
222 public function submissionScreenTeamObject(): void
223 {
224 $ilToolbar = $this->toolbar;
225
226 // #13414
227 $read_only = !$this->canEditTeam();
228
229 if ($this->submission->getAssignment()->afterDeadlineStrict(false)) {
230 $this->tpl->setOnScreenMessage('info', $this->lng->txt("exercise_time_over"));
231 } elseif (!$read_only) {
232 $add_search = $this->submission->isTutor();
233 // add member
235 $this,
236 $ilToolbar,
237 array(
238 'auto_complete_name' => $this->lng->txt('user'),
239 'submit_name' => $this->lng->txt('add'),
240 'add_search' => $add_search,
241 'add_from_container' => $this->exercise->getRefId()
242 )
243 );
244 } elseif ($this->submission->getAssignment()->getTeamTutor()) {
245 $this->tpl->setOnScreenMessage('info', $this->lng->txt("exc_no_team_yet_info_tutor"));
246 }
247
249 $this,
250 "submissionScreenTeam",
252 $this->exercise->getRefId(),
253 $this->team,
254 $read_only
255 );
256
257 $this->tpl->setContent($tbl->getHTML());
258 }
259
264 array $a_user_ids = array()
265 ): void {
266 if (!$this->canEditTeam()) {
267 $this->ctrl->redirect($this, "submissionScreenTeam");
268 }
269
270 if ($a_user_ids === []) {
271 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("no_checkbox"));
272 return;
273 }
274
275 $new_users = [];
276
277 foreach ($a_user_ids as $user_id) {
278 if ($this->team->addTeamMember($user_id, $this->exercise->getRefId())) {
279 $new_users[] = $user_id;
280
281 // #14277
282 if (!$this->exercise->members_obj->isAssigned($user_id)) {
283 $this->exercise->members_obj->assignMember($user_id);
284 }
285 } else {
286 // #11959
287 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_members_already_assigned_team"), true);
288 }
289 }
290
291 if ($new_users !== []) {
292 // re-evaluate complete team, as new member could have already submitted
293 $this->exercise->processExerciseStatus(
294 $this->assignment,
295 $this->team->getMembers(),
296 $this->submission->hasSubmitted(),
297 $this->submission->validatePeerReviews()
298 );
299 // :TODO: notification?
300 $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
301 }
302
303 $this->ctrl->redirect($this, "submissionScreenTeam");
304 }
305
309 public function confirmDeleteTeamObject(): void
310 {
311 $this->confirmRemoveTeamMemberObject(true);
312 }
313
318 bool $a_full_delete = false
319 ): void {
320 $ilUser = $this->user;
322
323 if (!$this->submission->isTutor()) {
324 $ids = $a_full_delete ? $this->team->getMembers() : $this->requested_team_ids;
325
326 if ([] === $ids && !$this->canEditTeam()) {
327 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
328 $this->ctrl->redirect($this, "submissionScreenTeam");
329 }
330 } else {
331 $ids = $this->requested_team_ids;
332 if ([] === $ids) {
333 $this->returnToParentObject();
334 }
335 }
336
337 $members = $this->team->getMembers();
338 if (count($members) <= count($ids)) {
339 if (count($members) == 1 && $members[0] == $ilUser->getId()) {
340 // direct team deletion - no confirmation
341 $this->removeTeamMemberObject($a_full_delete);
342 return;
343 } else {
344 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_team_at_least_one"), true);
345 $this->ctrl->redirect($this, "submissionScreenTeam");
346 }
347 }
348
349 $cgui = new ilConfirmationGUI();
350 $cgui->setFormAction($this->ctrl->getFormAction($this));
351 $cgui->setHeaderText($this->lng->txt("exc_team_member_remove_sure"));
352 $cgui->setConfirm($this->lng->txt("remove"), "removeTeamMember");
353 $cgui->setCancel($this->lng->txt("cancel"), $this->submission->isTutor()
354 ? "returnToParent"
355 : "submissionScreenTeam");
356
357 $files = $this->submission->getFiles();
358
359 foreach ($ids as $id) {
360 $details = array();
361 foreach ($files as $file) {
362 if ($file["owner_id"] == $id) {
363 $details[] = $file["filetitle"];
364 }
365 }
367 if ($details !== []) {
368 $uname .= ": " . implode(", ", $details);
369 }
370 $cgui->addItem("id[]", $id, $uname);
371 }
372
373 $tpl->setContent($cgui->getHTML());
374 }
375
379 public function removeTeamMemberObject(
380 bool $a_full_delete = false
381 ): void {
382 $ilUser = $this->user;
383
384 $cancel_cmd = $this->submission->isTutor()
385 ? "returnToParent"
386 : "submissionScreenTeam";
387
388 $ids = [];
389 if ($a_full_delete) {
390 $ids = $this->team->getMembers();
391 } else {
392 $ids = $this->requested_team_ids;
393 }
394 $ids = array_filter(array_map('intval', $ids));
395
396 if ([] === $ids && !$this->canEditTeam()) {
397 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("select_one"), true);
398 $this->ctrl->redirect($this, $cancel_cmd);
399 }
400
401 $team_deleted = $a_full_delete;
402 if (!$team_deleted) {
403 $members = $this->team->getMembers();
404 if (count($members) <= count($ids)) {
405 if (count($members) == 1 && $members[0] == $ilUser->getId()) {
406 $team_deleted = true;
407 } else {
408 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("exc_team_at_least_one"), true);
409 $this->ctrl->redirect($this, $cancel_cmd);
410 }
411 }
412 }
413
414 foreach ($ids as $user_id) {
415 $this->team->removeTeamMember($user_id, $this->exercise->getRefId());
416 }
417
418 // reset ex team members, as any submission is not valid without team
419 $this->exercise->processExerciseStatus(
420 $this->assignment,
421 $ids,
422 false
423 );
424
425 if (!$team_deleted) {
426 // re-evaluate complete team, as removed member might have had submitted
427 $this->exercise->processExerciseStatus(
428 $this->assignment,
429 $this->team->getMembers(),
430 $this->submission->hasSubmitted(),
431 $this->submission->validatePeerReviews()
432 );
433 }
434
435 $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
436 if (!$team_deleted) {
437 $this->ctrl->redirect($this, $cancel_cmd);
438 } else {
439 $this->ctrl->redirect($this, "returnToParent");
440 }
441 }
442
443 public function submissionScreenTeamLogObject(): void
444 {
445 $this->tabs_gui->activateTab("log");
446
448 $this,
449 "submissionScreenTeamLog",
450 $this->team
451 );
452
453 $this->tpl->setContent($tbl->getHTML());
454 }
455
456 public function createSingleMemberTeamObject(): void
457 {
459 $this->assignment->getId(),
460 $this->submission->getUserId(),
461 true
462 );
463 $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
464 $this->returnToParentObject();
465 }
466
467 public function showTeamLogObject(): void
468 {
469 $tbl = new ilExAssignmentTeamLogTableGUI($this, "showTeamLog", $this->team);
470 $this->tpl->setContent($tbl->getHTML());
471 }
472
477 {
478 $ctrl = $this->ctrl;
480 $ilUser = $this->user;
481
482 $form = new ilPropertyFormGUI();
483 $form->setTitle($lng->txt("exc_team_assignment_adopt_user"));
484 $form->setFormAction($ctrl->getFormAction($this, "createAdoptedTeam"));
485
486 $teams = new ilRadioGroupInputGUI($lng->txt("exc_assignment"), "ass_adpt");
487 $teams->setValue(-1);
488
489 $teams->addOption(new ilRadioOption($lng->txt("exc_team_assignment_adopt_none_user"), -1));
490
491 $current_map = ilExAssignmentTeam::getAssignmentTeamMap($this->assignment->getId());
492
493 $options = ilExAssignmentTeam::getAdoptableTeamAssignments($this->assignment->getExerciseId(), $this->assignment->getId(), $ilUser->getId());
494 foreach ($options as $id => $item) {
495 $members = array();
496 $free = false;
497 foreach ($item["user_team"] as $user_id) {
498 $members[$user_id] = ilUserUtil::getNamePresentation($user_id);
499
500 if (array_key_exists($user_id, $current_map)) {
501 $members[$user_id] .= " (" . $lng->txt("exc_team_assignment_adopt_already_assigned") . ")";
502 } else {
503 $free = true;
504 }
505 }
506 asort($members);
507 $members = implode("<br />", $members);
508 $option = new ilRadioOption($item["title"], $id);
509 $option->setInfo($members);
510 if (!$free) {
511 $option->setDisabled(true);
512 }
513 $teams->addOption($option);
514 }
515
516 $form->addItem($teams);
517
518 $form->addCommandButton("createAdoptedTeam", $lng->txt("save"));
519 $form->addCommandButton("returnToParent", $lng->txt("cancel"));
520
521 return $form;
522 }
523
524 public function createTeamObject(): void
525 {
526 $ilCtrl = $this->ctrl;
527 $ilUser = $this->user;
529
530 if ($this->submission->canSubmit()) {
531 $options = ilExAssignmentTeam::getAdoptableTeamAssignments($this->assignment->getExerciseId(), $this->assignment->getId(), $ilUser->getId());
532 if ($options !== []) {
533 $form = $this->getAdoptForm();
534 $tpl->setContent($form->getHTML());
535 return;
536 }
537
538 ilExAssignmentTeam::getTeamId($this->assignment->getId(), $ilUser->getId(), true);
539
540 // #18046
541 if (!$this->exercise->members_obj->isAssigned($ilUser->getId())) {
542 $this->exercise->members_obj->assignMember($ilUser->getId());
543 }
544
545 $this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
546 }
547
548 $ilCtrl->redirect($this, "returnToParent");
549 }
550
554 public function createAdoptedTeamObject(): void
555 {
556 $ilCtrl = $this->ctrl;
557 $ilUser = $this->user;
559
560 $form = $this->getAdoptForm();
561 $form->checkInput();
562 if ($this->submission->canSubmit()) {
563 $src_ass_id = $form->getInput("ass_adpt");
564 if ($src_ass_id > 0) {
565 ilExAssignmentTeam::adoptTeams($src_ass_id, $this->assignment->getId(), $ilUser->getId(), $this->exercise->getRefId());
566 } else {
567 ilExAssignmentTeam::getTeamId($this->assignment->getId(), $ilUser->getId(), true);
568 }
569
570 $this->tpl->setOnScreenMessage('success', $lng->txt("settings_saved"), true);
571 }
572
573 $ilCtrl->redirect($this, "returnToParent");
574 }
575
580 public function addUserFromAutoCompleteObject(): void
581 {
582 $user_login = $this->request->getUserLogin();
583 if ($user_login == "") {
584 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_search_string'));
585 $this->submissionScreenTeamObject();
586 return;
587 }
588
589 $users = explode(',', $user_login);
590
591 $user_ids = array();
592 foreach ($users as $user) {
593 $user_id = ilObjUser::_lookupId($user);
594
595 if (!$user_id) {
596 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('user_not_known'));
597 $this->submissionScreenTeamObject();
598 return;
599 }
600
601 $user_ids[] = $user_id;
602 }
603
604 $this->addTeamMemberActionObject($user_ids);
605 }
606}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Exercise gui request wrapper.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
getNextClass($a_gui_class=null)
@inheritDoc
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static adoptTeams(int $a_source_ass_id, int $a_target_ass_id, int $a_user_id=null, int $a_exc_ref_id=null)
static getAssignmentTeamMap(int $a_ass_id)
static getAdoptableTeamAssignments(int $a_exercise_id, int $a_exclude_ass_id=null, int $a_user_id=null)
static getTeamId(int $a_assignment_id, int $a_user_id, bool $a_create_on_demand=false)
Exercise assignment.
ilGlobalTemplateInterface $tpl
removeTeamMemberObject(bool $a_full_delete=false)
addTeamMemberActionObject(array $a_user_ids=array())
confirmRemoveTeamMemberObject(bool $a_full_delete=false)
submissionScreenTeamObject()
Displays a form which allows members to manage team uploads.
static getOverviewContent(ilInfoScreenGUI $a_info, ilExSubmission $a_submission)
addUserFromAutoCompleteObject()
Add user as member.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getLastSubmission()
TODO -> get rid of getTableUserWhere and move to repository class Get the date of the last submission...
static getInstanceByIds(int $a_ass_id, int $a_user_id=0)
Class ilInfoScreenGUI.
addProperty(string $a_name, string $a_value, string $a_link="")
add a property to current section
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
Class ilObjExercise.
User class.
static _lookupId($a_user_str)
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static fillAutoCompleteToolbar(object $parent_object, ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt('user'), auto_complete_size = 15, user_type = array(ilCoursePar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
array $details
Details for error message relating to last request processed.
Definition: System.php:109
$lng