35 protected ?
int $id = null;
43 $this->db = $DIC->database();
44 $this->
user = $DIC->user();
53 bool $a_create_on_demand =
false 55 $id = self::getTeamId($a_assignment_id, $a_user_id, $a_create_on_demand);
62 foreach (self::getAssignmentTeamMap($a_assignment_id) as $user_id => $team_id) {
63 $teams[$team_id][] = $user_id;
67 foreach ($teams as $team_id => $members) {
70 $team->assignment_id = $a_assignment_id;
72 $res[$team_id] = $team;
83 private function setId(?
int $a_id): void
88 protected function read(
int $a_id): void
93 $this->members = array();
95 $sql =
"SELECT * FROM il_exc_team" .
96 " WHERE id = " .
$ilDB->quote($a_id,
"integer");
97 $set =
$ilDB->query($sql);
98 if (
$ilDB->numRows($set)) {
101 while ($row =
$ilDB->fetchAssoc($set)) {
102 $this->assignment_id = $row[
"ass_id"];
103 $this->members[] = $row[
"user_id"];
110 int $a_assignment_id,
112 bool $a_create_on_demand =
false 116 $ilDB = $DIC->database();
118 $sql =
"SELECT id FROM il_exc_team" .
119 " WHERE ass_id = " .
$ilDB->quote($a_assignment_id,
"integer") .
120 " AND user_id = " .
$ilDB->quote($a_user_id,
"integer");
121 $set =
$ilDB->query($sql);
123 if ($row =
$ilDB->fetchAssoc($set)) {
127 if (!$id && $a_create_on_demand) {
128 $id =
$ilDB->nextId(
"il_exc_team");
133 $fields = array(
"id" => array(
"integer", $id),
134 "ass_id" => array(
"integer", $a_assignment_id),
135 "user_id" => array(
"integer", $a_user_id));
136 $ilDB->insert(
"il_exc_team", $fields);
139 if ($idl->getStartingTimestamp() > 0) {
141 $idl_team->setStartingTimestamp($idl->getStartingTimestamp());
145 self::writeTeamLog($id, self::TEAM_LOG_CREATE_TEAM);
148 self::TEAM_LOG_ADD_MEMBER,
157 int $a_assignment_id,
161 $id =
$ilDB->nextId(
"il_exc_team");
162 $fields = array(
"id" => array(
"integer", $id),
163 "ass_id" => array(
"integer", $a_assignment_id),
164 "user_id" => array(
"integer", $a_user_id));
165 $ilDB->insert(
"il_exc_team", $fields);
166 self::writeTeamLog($id, self::TEAM_LOG_CREATE_TEAM);
169 self::TEAM_LOG_ADD_MEMBER,
191 $sql =
"SELECT user_id" .
192 " FROM il_exc_team" .
193 " WHERE ass_id = " .
$ilDB->quote($this->assignment_id,
"integer");
194 $set =
$ilDB->query($sql);
195 while ($row =
$ilDB->fetchAssoc($set)) {
196 $ids[] = $row[
"user_id"];
209 ?
int $a_exc_ref_id = null
219 $fields = array(
"id" => array(
"integer", $this->
id),
220 "ass_id" => array(
"integer", $this->assignment_id),
221 "user_id" => array(
"integer", $a_user_id));
222 $ilDB->insert(
"il_exc_team", $fields);
229 self::TEAM_LOG_ADD_MEMBER,
233 $this->
read($this->
id);
246 ?
int $a_exc_ref_id = null
254 $sql =
"DELETE FROM il_exc_team" .
255 " WHERE ass_id = " .
$ilDB->quote($this->assignment_id,
"integer") .
256 " AND id = " .
$ilDB->quote($this->
id,
"integer") .
257 " AND user_id = " .
$ilDB->quote($a_user_id,
"integer");
258 $ilDB->manipulate($sql);
265 self::TEAM_LOG_REMOVE_MEMBER,
269 $this->
read($this->
id);
277 $ilDB = $DIC->database();
281 $sql =
"SELECT * FROM il_exc_team" .
282 " WHERE ass_id = " .
$ilDB->quote($a_ass_id,
"integer");
283 $set =
$ilDB->query($sql);
284 while ($row =
$ilDB->fetchAssoc($set)) {
285 $map[$row[
"user_id"]] = $row[
"id"];
293 string $a_details = null
295 self::writeTeamLog($this->
id, $a_action, $a_details);
304 string $a_details = null
308 $ilDB = $DIC->database();
310 $id =
$ilDB->nextId(
'il_exc_team_log');
313 "log_id" => array(
"integer", $id),
314 "team_id" => array(
"integer", $a_team_id),
315 "user_id" => array(
"integer",
$ilUser->getId()),
316 "action" => array(
"integer", $a_action),
317 "details" => array(
"text", $a_details),
318 "tstamp" => array(
"integer", time())
321 $ilDB->insert(
"il_exc_team_log", $fields);
333 $sql =
"SELECT * FROM il_exc_team_log" .
334 " WHERE team_id = " .
$ilDB->quote($this->
id,
"integer") .
335 " ORDER BY tstamp DESC";
336 $set =
$ilDB->query($sql);
337 while ($row =
$ilDB->fetchAssoc($set)) {
355 $obsolete_teams = [];
356 $set =
$ilDB->query(
"SELECT DISTINCT l.team_id as id FROM il_exc_team_log as l LEFT JOIN il_exc_team as t ON (l.team_id = t.id) WHERE t.id IS NULL;");
357 while ($row =
$ilDB->fetchAssoc($set)) {
358 $obsolete_teams[] = $row[
"id"];
361 if (count($obsolete_teams) > 0) {
362 $q =
"DELETE FROM il_exc_team_log" .
363 " WHERE " .
$ilDB->in(
"team_id", $obsolete_teams,
false,
"integer");
364 $ilDB->manipulate($q);
380 if (!$a_exc_ref_id ||
381 $ilUser->getId() == $a_user_id) {
387 $ntf->setLangModules(array(
"exc"));
388 $ntf->setRefId($a_exc_ref_id);
389 $ntf->setChangedByUserId(
$ilUser->getId());
390 $ntf->setSubjectLangId(
'exc_team_notification_subject_' . $a_action);
391 $ntf->setIntroductionLangId(
'exc_team_notification_body_' . $a_action);
392 $ntf->addAdditionalInfo(
"exc_assignment", $ass->getTitle());
393 $ntf->setGotoLangId(
'exc_team_notification_link');
394 $ntf->setReasonLangId(
'exc_team_notification_reason');
395 $ntf->sendMailAndReturnRecipients(array($a_user_id));
401 int $a_exclude_ass_id = null,
402 int $a_user_id = null
407 foreach (
$data as $row) {
408 if ($a_exclude_ass_id && $row[
"id"] == $a_exclude_ass_id) {
413 $map = self::getAssignmentTeamMap($row[
"id"]);
415 if ($a_user_id && !array_key_exists($a_user_id, $map)) {
422 $user_team_id = $map[$a_user_id];
423 $user_team = array();
424 foreach ($map as $user_id => $team_id) {
425 if ($user_id != $a_user_id &&
426 $user_team_id == $team_id) {
427 $user_team[] = $user_id;
434 $res[$row[
"id"]] = array(
435 "title" => $row[
"title"],
436 "teams" => count(array_flip($map)),
440 $res[$row[
"id"]][
"user_team"] = $user_team;
454 int $a_source_ass_id,
455 int $a_target_ass_id,
456 int $a_user_id = null,
457 int $a_exc_ref_id = null
462 foreach (self::getAssignmentTeamMap($a_source_ass_id) as $user_id => $team_id) {
463 $teams[$team_id][] = $user_id;
465 if ($a_user_id && $user_id == $a_user_id) {
466 $old_team = $team_id;
473 self::getInstanceByUserId($a_target_ass_id, $a_user_id)->
getId()) {
478 $current_map = self::getAssignmentTeamMap($a_target_ass_id);
480 foreach ($teams as $team_id => $user_ids) {
481 if (!$old_team || $team_id == $old_team) {
484 foreach ($user_ids as $user_id) {
485 if (!array_key_exists($user_id, $current_map)) {
486 $missing[] = $user_id;
490 if ($missing !== []) {
492 $first = array_shift($missing);
493 $new_team = self::getInstanceByUserId($a_target_ass_id, $first,
true);
496 if ($a_user_id > 0 && $old_team > 0) {
498 if ($idl->getStartingTimestamp()) {
500 $idl_team->setStartingTimestamp($idl->getStartingTimestamp());
507 $new_team->sendNotification($a_exc_ref_id, $first,
"add");
510 foreach ($missing as $user_id) {
511 $new_team->addTeamMember($user_id, $a_exc_ref_id);
530 $tree = $DIC->repositoryTree();
534 $parent_ref_id = $tree->getParentId($a_exc_ref_id);
535 if ($parent_ref_id) {
536 foreach ($tree->getChildsByType($parent_ref_id,
"grp") as $group) {
537 $res[] = $group[
"obj_id"];
548 foreach (self::getAdoptableGroups($a_exc_ref_id) as $grp_obj_id) {
551 $res[$grp_obj_id] = array(
553 ,
"members" => $members_obj->getMembers()
573 int $a_assignment_id,
575 int $a_min_participants
578 if (count(self::getAssignmentTeamMap($a_assignment_id))) {
583 $members = $obj_exc_members->getMembers();
584 $total_exc_members = count($members);
585 $number_of_teams = $a_number_teams;
586 if (!$number_of_teams) {
587 if ($a_min_participants) {
588 $number_of_teams = round($total_exc_members / $a_min_participants);
590 $number_of_teams = random_int(1, $total_exc_members);
593 $members_per_team = round($total_exc_members / $number_of_teams);
595 for (
$i = 0;
$i < $number_of_teams;
$i++) {
596 $members_counter = 0;
597 while (!empty($members) && $members_counter < $members_per_team) {
598 $member_id = array_pop($members);
599 if ($members_counter == 0) {
600 $team_id = $this->
createTeam($a_assignment_id, $member_id);
601 $this->
setId($team_id);
602 $this->assignment_id = $a_assignment_id;
610 $teams = array_unique(array_values(self::getAssignmentTeamMap($a_assignment_id)));
612 while (!empty($members)) {
613 $member_id = array_pop($members);
614 $team_id = array_pop($teams);
615 $this->
setId($team_id);
writeLog(string $a_action, string $a_details=null)
removeTeamMember(int $a_user_id, ?int $a_exc_ref_id=null)
createTeam(int $a_assignment_id, int $a_user_id)
const TEAM_LOG_REMOVE_MEMBER
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupFullname(int $a_user_id)
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 getAdoptableTeamAssignments(int $a_exercise_id, int $a_exclude_ass_id=null, int $a_user_id=null)
static getInstanceByUserId(int $a_assignment_id, int $a_user_id, bool $a_create_on_demand=false)
addTeamMember(int $a_user_id, ?int $a_exc_ref_id=null)
sendNotification(int $a_exc_ref_id, int $a_user_id, string $a_action)
Send notification about team status.
static getAdoptableGroups(int $a_exc_ref_id)
static getAssignmentDataOfExercise(int $a_exc_id)
const TEAM_LOG_REMOVE_FILE
static _lookupTitle(int $obj_id)
cleanLog()
Remove obsolete log entries.
static getTeamId(int $a_assignment_id, int $a_user_id, bool $a_create_on_demand=false)
getMembersOfAllTeams()
Get members for all teams of assignment.
static getAssignmentTeamMap(int $a_ass_id)
static writeTeamLog(int $a_team_id, string $a_action, string $a_details=null)
Add entry to team log.
__construct(?int $a_id=null)
createRandomTeams(int $a_exercise_id, int $a_assignment_id, int $a_number_teams, int $a_min_participants)
Create random teams for assignment type "team upload" following specific rules.
static adoptTeams(int $a_source_ass_id, int $a_target_ass_id, int $a_user_id=null, int $a_exc_ref_id=null)
static getGroupMembersMap(int $a_exc_ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const TEAM_LOG_CREATE_TEAM
static getInstance(int $a_ass_id, int $a_participant_id, bool $a_is_team=false)
static getInstancesFromMap(int $a_assignment_id)
const TEAM_LOG_ADD_MEMBER
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)