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)) {
 
   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);
 
  120        if (!
$id && $a_create_on_demand) {
 
  124            include_once(
"./Modules/Exercise/classes/class.ilExcIndividualDeadline.php");
 
  127            $fields = array(
"id" => array(
"integer", 
$id),
 
  128                "ass_id" => array(
"integer", $a_assignment_id),
 
  129                "user_id" => array(
"integer", $a_user_id));
 
  130            $ilDB->insert(
"il_exc_team", $fields);
 
  133            if ($idl->getStartingTimestamp() > 0) {
 
  135                $idl_team->setStartingTimestamp($idl->getStartingTimestamp());
 
  142                self::TEAM_LOG_ADD_MEMBER,
 
  154        $fields = array(
"id" => array(
"integer", 
$id),
 
  155            "ass_id" => array(
"integer", $a_assignment_id),
 
  156            "user_id" => array(
"integer", $a_user_id));
 
  157        $ilDB->insert(
"il_exc_team", $fields);
 
  161            self::TEAM_LOG_ADD_MEMBER,
 
  188        $sql = 
"SELECT user_id" .
 
  189            " FROM il_exc_team" .
 
  190            " WHERE ass_id = " . 
$ilDB->quote($this->assignment_id, 
"integer");
 
  191        $set = 
$ilDB->query($sql);
 
  193            $ids[] = 
$row[
"user_id"];
 
  215            $fields = array(
"id" => array(
"integer", $this->
id),
 
  216                "ass_id" => array(
"integer", $this->assignment_id),
 
  217                "user_id" => array(
"integer", $a_user_id));
 
  218            $ilDB->insert(
"il_exc_team", $fields);
 
  225                self::TEAM_LOG_ADD_MEMBER,
 
  229            $this->
read($this->
id);
 
  251        $sql = 
"DELETE FROM il_exc_team" .
 
  252            " WHERE ass_id = " . 
$ilDB->quote($this->assignment_id, 
"integer") .
 
  253            " AND id = " . 
$ilDB->quote($this->
id, 
"integer") .
 
  254            " AND user_id = " . 
$ilDB->quote($a_user_id, 
"integer");
 
  255        $ilDB->manipulate($sql);
 
  262            self::TEAM_LOG_REMOVE_MEMBER,
 
  266        $this->
read($this->
id);
 
  283        $sql = 
"SELECT * FROM il_exc_team" .
 
  284            " WHERE ass_id = " . 
$ilDB->quote($a_ass_id, 
"integer");
 
  285        $set = 
$ilDB->query($sql);
 
  293    public function writeLog($a_action, $a_details = 
null)
 
  305    public static function writeTeamLog($a_team_id, $a_action, $a_details = 
null)
 
  311        $id = 
$ilDB->nextId(
'il_exc_team_log');
 
  314            "log_id" => array(
"integer", 
$id),
 
  315            "team_id" => array(
"integer", $a_team_id),
 
  316            "user_id" => array(
"integer", 
$ilUser->getId()),
 
  317            "action" => array(
"integer", $a_action),
 
  318            "details" => array(
"text", $a_details),
 
  319            "tstamp" => array(
"integer", time())
 
  322        $ilDB->insert(
"il_exc_team_log", $fields);
 
  339        $sql = 
"SELECT * FROM il_exc_team_log" .
 
  340            " WHERE team_id = " . 
$ilDB->quote($this->
id, 
"integer") .
 
  341            " ORDER BY tstamp DESC";
 
  342        $set = 
$ilDB->query($sql);
 
  361        $set = 
$ilDB->query(
"SELECT DISTINCT(id)" .
 
  362            " FROM il_exc_team");
 
  364            $teams[] = 
$row[
"id"];
 
  367        $set = 
$ilDB->query(
"SELECT DISTINCT(team_id)" .
 
  368            " FROM il_exc_team_log");
 
  370            $team_id = 
$row[
"team_id"];
 
  371            if (!in_array($team_id, $teams)) {
 
  372                $ilDB->manipulate(
"DELETE FROM il_exc_team_log" .
 
  373                    " WHERE team_id = " . 
$ilDB->quote($team_id, 
"integer"));
 
  390        if (!$a_exc_ref_id ||
 
  391            $ilUser->getId() == $a_user_id) {
 
  397        include_once 
"./Services/Notification/classes/class.ilSystemNotification.php";
 
  399        $ntf->setLangModules(array(
"exc"));
 
  400        $ntf->setRefId($a_exc_ref_id);
 
  401        $ntf->setChangedByUserId(
$ilUser->getId());
 
  402        $ntf->setSubjectLangId(
'exc_team_notification_subject_' . $a_action);
 
  403        $ntf->setIntroductionLangId(
'exc_team_notification_body_' . $a_action);
 
  404        $ntf->addAdditionalInfo(
"exc_assignment", $ass->getTitle());
 
  405        $ntf->setGotoLangId(
'exc_team_notification_link');
 
  406        $ntf->setReasonLangId(
'exc_team_notification_reason');
 
  407        $ntf->sendMail(array($a_user_id));
 
  417            if ($a_exclude_ass_id && 
$row[
"id"] == $a_exclude_ass_id) {
 
  424                if ($a_user_id && !array_key_exists($a_user_id, 
$map)) {
 
  431                        $user_team_id = 
$map[$a_user_id];
 
  432                        $user_team = array();
 
  433                        foreach (
$map as $user_id => $team_id) {
 
  434                            if ($user_id != $a_user_id &&
 
  435                                $user_team_id == $team_id) {
 
  436                                $user_team[] = $user_id;
 
  442                        sizeof($user_team)) {
 
  444                            "title" => 
$row[
"title"],
 
  445                            "teams" => 
sizeof(array_flip(
$map)),
 
  449                            $res[
$row[
"id"]][
"user_team"] = $user_team;
 
  459    public static function adoptTeams($a_source_ass_id, $a_target_ass_id, $a_user_id = 
null, $a_exc_ref_id = 
null)
 
  464        foreach (self::getAssignmentTeamMap($a_source_ass_id) as $user_id => $team_id) {
 
  465            $teams[$team_id][] = $user_id;
 
  467            if ($a_user_id && $user_id == $a_user_id) {
 
  468                $old_team = $team_id;
 
  475                self::getInstanceByUserId($a_target_ass_id, $a_user_id)->
getId()) {
 
  482        foreach ($teams as $team_id => $user_ids) {
 
  483            if (!$old_team || $team_id == $old_team) {
 
  486                foreach ($user_ids as $user_id) {
 
  487                    if (!array_key_exists($user_id, $current_map)) {
 
  488                        $missing[] = $user_id;
 
  492                if (
sizeof($missing)) {
 
  494                    $first = array_shift($missing);
 
  498                    if ($a_user_id > 0 && $old_team > 0) {
 
  500                        if ($idl->getStartingTimestamp()) {
 
  502                            $idl_team->setStartingTimestamp($idl->getStartingTimestamp());
 
  509                        $new_team->sendNotification($a_exc_ref_id, $first, 
"add");
 
  512                    foreach ($missing as $user_id) {
 
  513                        $new_team->addTeamMember($user_id, $a_exc_ref_id);
 
  532        $parent_ref_id = 
$tree->getParentId($a_exc_ref_id);
 
  533        if ($parent_ref_id) {
 
  534            foreach (
$tree->getChildsByType($parent_ref_id, 
"grp") as $group) {
 
  535                $res[] = $group[
"obj_id"];
 
  546        include_once 
"Modules/Group/classes/class.ilGroupParticipants.php";
 
  547        foreach (self::getAdoptableGroups($a_exc_ref_id) as $grp_obj_id) {
 
  550            $res[$grp_obj_id] = array(
 
  552                ,
"members" => $members_obj->getMembers()
 
  573    public function createRandomTeams($a_exercise_id, $a_assignment_id, $a_number_teams, $a_min_participants)
 
  576        if (count(self::getAssignmentTeamMap($a_assignment_id))) {
 
  581        $members = $obj_exc_members->getMembers();
 
  582        $total_exc_members = count(
$members);
 
  583        $number_of_teams = $a_number_teams;
 
  584        if (!$number_of_teams) {
 
  585            if ($a_min_participants) {
 
  586                $number_of_teams = round($total_exc_members / $a_min_participants);
 
  588                $number_of_teams = random_int(1, $total_exc_members);
 
  591        $members_per_team = round($total_exc_members / $number_of_teams);
 
  593        for (
$i = 0;
$i < $number_of_teams;
$i++) {
 
  594            $members_counter = 0;
 
  595            while (!empty(
$members) && $members_counter < $members_per_team) {
 
  597                if ($members_counter == 0) {
 
  598                    $team_id = $this->
createTeam($a_assignment_id, $member_id);
 
  599                    $this->
setId($team_id);
 
  600                    $this->assignment_id = $a_assignment_id;
 
  608        $teams = array_unique(array_values(self::getAssignmentTeamMap($a_assignment_id)));
 
  612            $team_id = array_pop($teams);
 
  613            $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