33 protected \ILIAS\Exercise\Team\TeamDBRepository
$repo;
37 protected ?
int $id =
null;
44 $this->db =
$DIC->database();
45 $this->
user = $DIC->user();
46 $this->repo =
$DIC->exercise()->internal()->repo()->team();
47 $this->team_manager =
$DIC->exercise()->internal()->domain()->team();
56 bool $a_create_on_demand =
false
58 $id = self::
getTeamId($a_assignment_id, $a_user_id, $a_create_on_demand);
65 foreach (self::getAssignmentTeamMap($a_assignment_id) as
$user_id => $team_id) {
70 foreach ($teams as $team_id => $members) {
73 $team->assignment_id = $a_assignment_id;
74 $team->members = $members;
75 $res[$team_id] = $team;
86 private function setId(?
int $a_id): void
91 protected function read(
int $a_id): void
98 foreach ($this->repo->getMembers($a_id) as $member) {
99 $this->assignment_id = $member->getAssignmentId();
100 $this->members[] = $member->getUserId();
106 int $a_assignment_id,
108 bool $a_create_on_demand =
false
113 $repo =
$DIC->exercise()->internal()->repo()->team();
114 $manager =
$DIC->exercise()->internal()->domain()->team();
116 $id = $repo->getTeamForMember($a_assignment_id, $a_user_id);
118 if (!
$id && $a_create_on_demand) {
120 $id = $manager->create(
129 if ($idl->getStartingTimestamp() > 0) {
131 $idl_team->setStartingTimestamp($idl->getStartingTimestamp());
135 self::writeTeamLog(
$id, self::TEAM_LOG_CREATE_TEAM);
138 self::TEAM_LOG_ADD_MEMBER,
147 int $a_assignment_id,
151 $id = $this->team_manager->create(
156 self::writeTeamLog(
$id, self::TEAM_LOG_CREATE_TEAM);
159 self::TEAM_LOG_ADD_MEMBER,
168 return $this->members;
177 return iterator_to_array(
178 $this->repo->getAllMemberIdsOfAssignment($this->assignment_id)
189 ?
int $a_exc_ref_id =
null
198 if (!in_array($a_user_id, $this->getMembersOfAllTeams())) {
201 $status = $this->team_manager->getStatusForTeam($this->
id);
203 $this->repo->addUser(
205 $this->assignment_id,
211 $this->assignment_id,
214 $mem_stat->setStatus($status);
219 $this->sendNotification($a_exc_ref_id, $a_user_id,
"add");
223 self::TEAM_LOG_ADD_MEMBER,
227 $this->read($this->
id);
240 ?
int $a_exc_ref_id =
null
248 $this->repo->removeUser(
250 $this->assignment_id,
255 $this->sendNotification($a_exc_ref_id, $a_user_id,
"rmv");
259 self::TEAM_LOG_REMOVE_MEMBER,
263 $this->read($this->
id);
271 $repo =
$DIC->exercise()->internal()->repo()->team();
272 return $repo->getUserTeamMap($a_ass_id);
277 ?
string $a_details =
null
280 self::writeTeamLog($this->
id, $a_action, $a_details);
290 ?
string $a_details =
null
295 $ilUser =
$DIC->user();
296 $id =
$ilDB->nextId(
'il_exc_team_log');
299 "log_id" => array(
"integer",
$id),
300 "team_id" => array(
"integer", $a_team_id),
301 "user_id" => array(
"integer", $ilUser->getId()),
302 "action" => array(
"integer", $a_action),
303 "details" => array(
"text", $a_details),
304 "tstamp" => array(
"integer", time())
307 $ilDB->insert(
"il_exc_team_log", $fields);
319 $sql =
"SELECT * FROM il_exc_team_log" .
320 " WHERE team_id = " .
$ilDB->quote($this->
id,
"integer") .
321 " ORDER BY tstamp DESC";
322 $set =
$ilDB->query($sql);
323 while ($row =
$ilDB->fetchAssoc($set)) {
341 $obsolete_teams = [];
342 $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;");
343 while ($row =
$ilDB->fetchAssoc($set)) {
344 $obsolete_teams[] = $row[
"id"];
347 if (count($obsolete_teams) > 0) {
348 $q =
"DELETE FROM il_exc_team_log" .
349 " WHERE " .
$ilDB->in(
"team_id", $obsolete_teams,
false,
"integer");
363 $ilUser = $this->
user;
366 if (!$a_exc_ref_id ||
367 $ilUser->getId() == $a_user_id) {
373 $ntf->setLangModules(array(
"exc"));
374 $ntf->setRefId($a_exc_ref_id);
375 $ntf->setChangedByUserId($ilUser->getId());
376 $ntf->setSubjectLangId(
'exc_team_notification_subject_' . $a_action);
377 $ntf->setIntroductionLangId(
'exc_team_notification_body_' . $a_action);
378 $ntf->addAdditionalInfo(
"exc_assignment", $ass->getTitle());
379 $ntf->setGotoLangId(
'exc_team_notification_link');
380 $ntf->setReasonLangId(
'exc_team_notification_reason');
381 $ntf->sendMailAndReturnRecipients(array($a_user_id));
387 ?
int $a_exclude_ass_id =
null,
388 ?
int $a_user_id =
null
393 foreach (
$data as $row) {
394 if ($a_exclude_ass_id && $row[
"id"] == $a_exclude_ass_id) {
399 $map = self::getAssignmentTeamMap($row[
"id"]);
401 if ($a_user_id && !array_key_exists($a_user_id, $map)) {
408 $user_team_id = $map[$a_user_id];
409 $user_team = array();
410 foreach ($map as
$user_id => $team_id) {
412 $user_team_id == $team_id) {
420 $res[$row[
"id"]] = array(
421 "title" => $row[
"title"],
422 "teams" => count(array_flip($map)),
426 $res[$row[
"id"]][
"user_team"] = $user_team;
440 int $a_source_ass_id,
441 int $a_target_ass_id,
442 ?
int $a_user_id =
null,
443 ?
int $a_exc_ref_id =
null
448 foreach (self::getAssignmentTeamMap($a_source_ass_id) as
$user_id => $team_id) {
451 if ($a_user_id &&
$user_id == $a_user_id) {
452 $old_team = $team_id;
459 self::getInstanceByUserId($a_target_ass_id, $a_user_id)->
getId()) {
464 $current_map = self::getAssignmentTeamMap($a_target_ass_id);
466 foreach ($teams as $team_id => $user_ids) {
467 if (!$old_team || $team_id == $old_team) {
471 if (!array_key_exists(
$user_id, $current_map)) {
476 if ($missing !== []) {
478 $first = array_shift($missing);
479 $new_team = self::getInstanceByUserId($a_target_ass_id, $first,
true);
482 if ($a_user_id > 0 && $old_team > 0) {
484 if ($idl->getStartingTimestamp()) {
486 $idl_team->setStartingTimestamp($idl->getStartingTimestamp());
493 $new_team->sendNotification($a_exc_ref_id, $first,
"add");
497 $new_team->addTeamMember(
$user_id, $a_exc_ref_id);
516 $tree =
$DIC->repositoryTree();
520 $parent_ref_id = $tree->getParentId($a_exc_ref_id);
521 if ($parent_ref_id) {
522 foreach ($tree->getChildsByType($parent_ref_id,
"grp") as $group) {
523 $res[] = $group[
"obj_id"];
534 foreach (self::getAdoptableGroups($a_exc_ref_id) as $grp_obj_id) {
537 $res[$grp_obj_id] = array(
539 ,
"members" => $members_obj->getMembers()
559 int $a_assignment_id,
561 int $a_min_participants
564 if (count(self::getAssignmentTeamMap($a_assignment_id))) {
569 $members = $obj_exc_members->getMembers();
570 $total_exc_members = count($members);
571 $number_of_teams = $a_number_teams;
572 if (!$number_of_teams) {
573 if ($a_min_participants) {
574 $number_of_teams = round($total_exc_members / $a_min_participants);
576 $number_of_teams = random_int(1, $total_exc_members);
579 $members_per_team = round($total_exc_members / $number_of_teams);
581 for ($i = 0;$i < $number_of_teams;$i++) {
582 $members_counter = 0;
583 while (!empty($members) && $members_counter < $members_per_team) {
584 $member_id = array_pop($members);
585 if ($members_counter == 0) {
586 $team_id = $this->createTeam($a_assignment_id, $member_id);
587 $this->setId($team_id);
588 $this->assignment_id = $a_assignment_id;
590 $this->addTeamMember($member_id);
596 $teams = array_unique(array_values(self::getAssignmentTeamMap($a_assignment_id)));
598 while (!empty($members)) {
599 $member_id = array_pop($members);
600 $team_id = array_pop($teams);
601 $this->setId($team_id);
602 $this->addTeamMember($member_id);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
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 getAssignmentTeamMap(int $a_ass_id)
static adoptTeams(int $a_source_ass_id, int $a_target_ass_id, ?int $a_user_id=null, ?int $a_exc_ref_id=null)
static getAdoptableGroups(int $a_exc_ref_id)
addTeamMember(int $a_user_id, ?int $a_exc_ref_id=null)
getMembersOfAllTeams()
Get members for all teams of assignment.
createTeam(int $a_assignment_id, int $a_user_id)
const TEAM_LOG_REMOVE_FILE
const TEAM_LOG_REMOVE_MEMBER
static writeTeamLog(int $a_team_id, int $a_action, ?string $a_details=null)
Add entry to team log.
sendNotification(int $a_exc_ref_id, int $a_user_id, string $a_action)
Send notification about team status.
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)
writeLog(int $a_action, ?string $a_details=null)
static getTeamId(int $a_assignment_id, int $a_user_id, bool $a_create_on_demand=false)
ILIAS Exercise Team TeamManager $team_manager
ILIAS Exercise Team TeamDBRepository $repo
const TEAM_LOG_ADD_MEMBER
__construct(?int $a_id=null)
removeTeamMember(int $a_user_id, ?int $a_exc_ref_id=null)
const TEAM_LOG_CREATE_TEAM
static getInstancesFromMap(int $a_assignment_id)
static getGroupMembersMap(int $a_exc_ref_id)
cleanLog()
Remove obsolete log entries.
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 getAssignmentDataOfExercise(int $a_exc_id)
static getInstance(int $a_ass_id, int $a_participant_id, bool $a_is_team=false)
static _lookupFullname(int $a_user_id)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))