36        $this->db = 
$DIC->database();
 
   37        $this->
user = $DIC->user();
 
   52        foreach (self::getAssignmentTeamMap($a_assignment_id) as $user_id => $team_id) {
 
   53            $teams[$team_id][] = $user_id;
 
   57        foreach ($teams as $team_id => 
$members) {
 
   60            $team->assignment_id = $a_assignment_id;
 
   62            $res[$team_id] = $team;
 
   78    protected function read($a_id)
 
   83        $this->members = array();
 
   85        $sql = 
"SELECT * FROM il_exc_team" .
 
   86            " WHERE id = " . 
$ilDB->quote($a_id, 
"integer");
 
   87        $set = 
$ilDB->query($sql);
 
   88        if (
$ilDB->numRows($set)) {
 
   91            while ($row = 
$ilDB->fetchAssoc($set)) {
 
   92                $this->assignment_id = $row[
"ass_id"];
 
   93                $this->members[] = $row[
"user_id"];
 
  107    public static function getTeamId($a_assignment_id, $a_user_id, $a_create_on_demand = 
false)
 
  113        $sql = 
"SELECT id FROM il_exc_team" .
 
  114            " WHERE ass_id = " . 
$ilDB->quote($a_assignment_id, 
"integer") .
 
  115            " AND user_id = " . 
$ilDB->quote($a_user_id, 
"integer");
 
  116        $set = 
$ilDB->query($sql);
 
  117        $row = 
$ilDB->fetchAssoc($set);
 
  120        if (!
$id && $a_create_on_demand) {
 
  126            $fields = array(
"id" => array(
"integer", 
$id),
 
  127                "ass_id" => array(
"integer", $a_assignment_id),
 
  128                "user_id" => array(
"integer", $a_user_id));
 
  129            $ilDB->insert(
"il_exc_team", $fields);
 
  132            if ($idl->getStartingTimestamp() > 0) {
 
  134                $idl_team->setStartingTimestamp($idl->getStartingTimestamp());
 
  141                self::TEAM_LOG_ADD_MEMBER,
 
  153        $fields = array(
"id" => array(
"integer", 
$id),
 
  154            "ass_id" => array(
"integer", $a_assignment_id),
 
  155            "user_id" => array(
"integer", $a_user_id));
 
  156        $ilDB->insert(
"il_exc_team", $fields);
 
  160            self::TEAM_LOG_ADD_MEMBER,
 
  187        $sql = 
"SELECT user_id" .
 
  188            " FROM il_exc_team" .
 
  189            " WHERE ass_id = " . 
$ilDB->quote($this->assignment_id, 
"integer");
 
  190        $set = 
$ilDB->query($sql);
 
  191        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  192            $ids[] = $row[
"user_id"];
 
  214            $fields = array(
"id" => array(
"integer", $this->
id),
 
  215                "ass_id" => array(
"integer", $this->assignment_id),
 
  216                "user_id" => array(
"integer", $a_user_id));
 
  217            $ilDB->insert(
"il_exc_team", $fields);
 
  224                self::TEAM_LOG_ADD_MEMBER,
 
  228            $this->
read($this->
id);
 
  250        $sql = 
"DELETE FROM il_exc_team" .
 
  251            " WHERE ass_id = " . 
$ilDB->quote($this->assignment_id, 
"integer") .
 
  252            " AND id = " . 
$ilDB->quote($this->
id, 
"integer") .
 
  253            " AND user_id = " . 
$ilDB->quote($a_user_id, 
"integer");
 
  254        $ilDB->manipulate($sql);
 
  261            self::TEAM_LOG_REMOVE_MEMBER,
 
  265        $this->
read($this->
id);
 
  282        $sql = 
"SELECT * FROM il_exc_team" .
 
  283            " WHERE ass_id = " . 
$ilDB->quote($a_ass_id, 
"integer");
 
  284        $set = 
$ilDB->query($sql);
 
  285        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  286            $map[$row[
"user_id"]] = $row[
"id"];
 
  292    public function writeLog($a_action, $a_details = 
null)
 
  304    public static function writeTeamLog($a_team_id, $a_action, $a_details = 
null)
 
  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);
 
  338        $sql = 
"SELECT * FROM il_exc_team_log" .
 
  339            " WHERE team_id = " . 
$ilDB->quote($this->
id, 
"integer") .
 
  340            " ORDER BY tstamp DESC";
 
  341        $set = 
$ilDB->query($sql);
 
  342        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  360        $set = 
$ilDB->query(
"SELECT DISTINCT(id)" .
 
  361            " FROM il_exc_team");
 
  362        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  363            $teams[] = $row[
"id"];
 
  366        $set = 
$ilDB->query(
"SELECT DISTINCT(team_id)" .
 
  367            " FROM il_exc_team_log");
 
  368        while ($row = 
$ilDB->fetchAssoc($set)) {
 
  369            $team_id = $row[
"team_id"];
 
  370            if (!in_array($team_id, $teams)) {
 
  371                $ilDB->manipulate(
"DELETE FROM il_exc_team_log" .
 
  372                    " WHERE team_id = " . 
$ilDB->quote($team_id, 
"integer"));
 
  389        if (!$a_exc_ref_id ||
 
  390            $ilUser->getId() == $a_user_id) {
 
  397        $ntf->setLangModules(array(
"exc"));
 
  398        $ntf->setRefId($a_exc_ref_id);
 
  399        $ntf->setChangedByUserId(
$ilUser->getId());
 
  400        $ntf->setSubjectLangId(
'exc_team_notification_subject_' . $a_action);
 
  401        $ntf->setIntroductionLangId(
'exc_team_notification_body_' . $a_action);
 
  402        $ntf->addAdditionalInfo(
"exc_assignment", $ass->getTitle());
 
  403        $ntf->setGotoLangId(
'exc_team_notification_link');
 
  404        $ntf->setReasonLangId(
'exc_team_notification_reason');
 
  405        $ntf->sendMail(array($a_user_id));
 
  414        foreach (
$data as $row) {
 
  415            if ($a_exclude_ass_id && $row[
"id"] == $a_exclude_ass_id) {
 
  422                if ($a_user_id && !array_key_exists($a_user_id, $map)) {
 
  429                        $user_team_id = $map[$a_user_id];
 
  430                        $user_team = array();
 
  431                        foreach ($map as $user_id => $team_id) {
 
  432                            if ($user_id != $a_user_id &&
 
  433                                $user_team_id == $team_id) {
 
  434                                $user_team[] = $user_id;
 
  440                        sizeof($user_team)) {
 
  441                        $res[$row[
"id"]] = array(
 
  442                            "title" => $row[
"title"],
 
  443                            "teams" => 
sizeof(array_flip($map)),
 
  447                            $res[$row[
"id"]][
"user_team"] = $user_team;
 
  457    public static function adoptTeams($a_source_ass_id, $a_target_ass_id, $a_user_id = 
null, $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()) {
 
  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 (
sizeof($missing)) {
 
  492                    $first = array_shift($missing);
 
  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);
 
  526        $tree = 
$DIC->repositoryTree();
 
  530        $parent_ref_id = $tree->getParentId($a_exc_ref_id);
 
  531        if ($parent_ref_id) {
 
  532            foreach ($tree->getChildsByType($parent_ref_id, 
"grp") as $group) {
 
  533                $res[] = $group[
"obj_id"];
 
  544        foreach (self::getAdoptableGroups($a_exc_ref_id) as $grp_obj_id) {
 
  547            $res[$grp_obj_id] = array(
 
  549                ,
"members" => $members_obj->getMembers()
 
  570    public function createRandomTeams($a_exercise_id, $a_assignment_id, $a_number_teams, $a_min_participants)
 
  573        if (count(self::getAssignmentTeamMap($a_assignment_id))) {
 
  578        $members = $obj_exc_members->getMembers();
 
  579        $total_exc_members = count(
$members);
 
  580        $number_of_teams = $a_number_teams;
 
  581        if (!$number_of_teams) {
 
  582            if ($a_min_participants) {
 
  583                $number_of_teams = round($total_exc_members / $a_min_participants);
 
  585                $number_of_teams = random_int(1, $total_exc_members);
 
  588        $members_per_team = round($total_exc_members / $number_of_teams);
 
  590        for (
$i = 0;
$i < $number_of_teams;
$i++) {
 
  591            $members_counter = 0;
 
  592            while (!empty(
$members) && $members_counter < $members_per_team) {
 
  594                if ($members_counter == 0) {
 
  595                    $team_id = $this->
createTeam($a_assignment_id, $member_id);
 
  596                    $this->
setId($team_id);
 
  597                    $this->assignment_id = $a_assignment_id;
 
  605        $teams = array_unique(array_values(self::getAssignmentTeamMap($a_assignment_id)));
 
  609            $team_id = array_pop($teams);
 
  610            $this->
setId($team_id);
 
An exception for terminatinating execution or to throw for unit testing.
Exercise assignment team.
sendNotification($a_exc_ref_id, $a_user_id, $a_action)
Send notification about team status.
getMembers()
Get members of assignment team.
addTeamMember($a_user_id, $a_exc_ref_id=null)
Add new member to team.
createTeam($a_assignment_id, $a_user_id)
static getAdoptableGroups($a_exc_ref_id)
createRandomTeams($a_exercise_id, $a_assignment_id, $a_number_teams, $a_min_participants)
Create random teams for assignment type "team upload" following specific rules.
getMembersOfAllTeams()
Get members for all teams of assignment.
getLog()
Get all log entries for team.
const TEAM_LOG_REMOVE_FILE
writeLog($a_action, $a_details=null)
const TEAM_LOG_REMOVE_MEMBER
static getGroupMembersMap($a_exc_ref_id)
removeTeamMember($a_user_id, $a_exc_ref_id=null)
Remove member from team.
static getAssignmentTeamMap($a_ass_id)
Get team structure for assignment.
static getInstanceByUserId($a_assignment_id, $a_user_id, $a_create_on_demand=false)
static getInstancesFromMap($a_assignment_id)
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 writeTeamLog($a_team_id, $a_action, $a_details=null)
Add entry to team log.
const TEAM_LOG_ADD_MEMBER
const TEAM_LOG_CREATE_TEAM
cleanLog()
Remove obsolete log entries.
static adoptTeams($a_source_ass_id, $a_target_ass_id, $a_user_id=null, $a_exc_ref_id=null)
static getAssignmentDataOfExercise($a_exc_id)
Get assignments data of an exercise in an array.
static getInstance($a_ass_id, $a_participant_id, $a_is_team=false)
Get instance.
static _lookupFullname($a_user_id)
Lookup Full Name.
static _lookupTitle($a_id)
lookup object title
Wrapper classes for system notifications.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
foreach($_POST as $key=> $value) $res