public function JoinTeam($ttid)
 {
     //Check not anonymous
     if ($this->user_id == 0) {
         return "Anonymous users cannot join teams!";
     }
     if (null == $ttid) {
         return "Programming error: No timetable ID passed!";
     }
     //Check allow signup
     $timetable = new Lan_timetable();
     $timetable->id = $ttid;
     //$timetable->allowsignups = 1;
     $timetable->teambased = 1;
     if (1 != $timetable->find()) {
         return "This event does not allow joining teams.";
     }
     //Check not already in a team
     $team = new Lan_timetable_teams();
     $member = new Lan_timetable_team_members();
     $member->user_id = $this->user_id;
     $team->timetable_id = $ttid;
     $team->joinAdd($member);
     if ($team->count() != 0) {
         return "This user cannot join a team twice!";
     }
     //Check max team size
     $timetable->fetch();
     $team->team_id = $this->team_id;
     $team->PopulateMembers();
     $teamsize = count($team->members);
     if (!streq($teamsize, "0") && $timetable->teamsize < $teamsize + 1) {
         return "Max team size reached!";
     }
     //Join team
     if ($this->insert() == 0) {
         return "This user is already in a team for this event!";
     }
     //Remove pug if needed.
     $signup = new Lan_timetable_signups();
     $signup->timetable_id = $ttid;
     $signup->user_id = $this->user_id;
     while ($signup->fetch()) {
         $signup->delete();
     }
     return false;
 }
Beispiel #2
0
$biggame->type = "food";
if (isset($_GET["tid"])) {
    $user = new Lan_users();
    $biggame->joinAdd($user, "LEFT");
    if ($biggame->get($biggame->escape($_GET["tid"]))) {
        $biggame->fetch();
        //Find sign ups
        $tts = new Lan_timetable_signups();
        $user = new Lan_users();
        $tts->joinAdd($user);
        $tts->timetable_id = $biggame->id;
        $list = array();
        $tts->find();
        $currentUserSignedUp = false;
        $signups = 0;
        while ($tts->fetch()) {
            if (streq($tts->user_id, getCurrentUID())) {
                $currentUserSignedUp = true;
            }
            $list[] = clone $tts;
            $signups++;
        }
        $biggame->signups = $signups;
        $game = new Lan_games();
        if (1 == $game->get($biggame->game)) {
            $master->Smarty->assign("image", "images/games/" . $game->picture);
            $master->Smarty->assign("gamename", $game->name);
        }
        $biggame->occurs = date("l jS H:i", strtotime($biggame->occurs));
        $master->Smarty->assign("currentUserSignedUp", $currentUserSignedUp);
        $master->Smarty->assign("foodrun", $biggame);
 /**
  * Create a team
  * @param $name
  * @param $tag
  */
 public function CreateTeam()
 {
     //Anonymous users cannot register.
     if (streq($this->owner, "0")) {
         return "Anonymous users cannot register teams!";
     }
     //Validate against team name being in use.
     $test = new Lan_timetable_teams();
     $test->name = $this->name;
     $test->tag = $this->tag;
     $test->timetable_id = $this->timetable_id;
     if ($test->count() != 0) {
         return "A team with this name already exists!";
     }
     //Validate against the captain already being in a team
     $tm = new Lan_timetable_team_members();
     $tm->user_id = $this->owner;
     $test = new Lan_timetable_teams();
     $test->joinAdd($tm, "CENTER");
     if ($test->count() != 0) {
         return "You cannot create a team whilst you are in a team!";
     }
     //Check that teams are being used
     $tt = new Lan_timetable();
     $tt->id = $this->timetable_id;
     $tt->teambased = 1;
     if ($tt->find() != 1) {
         return "This event is not team based!";
     }
     $tt->fetch();
     $test = new Lan_timetable_teams();
     $test->timetable_id = $this->timetable_id;
     if (!streq("0", $tt->maxplayers) && $tt->maxplayers < $test->count() + 1) {
         return "Max team count reached for this event.";
     }
     //All is ok, so insert the team
     if (0 == $this->insert()) {
         return "Team creation failed!";
     }
     //Add the captain as a member
     $tm = new Lan_timetable_team_members();
     $tm->team_id = $this->team_id;
     $tm->user_id = $this->owner;
     if (0 == $tm->insert()) {
         return "Error adding captain as team member!";
     }
     //If the player is a PUG player then remove them from the list.
     $signup = new Lan_timetable_signups();
     $signup->timetable_id = $this->timetable_id;
     $signup->user_id = $this->owner;
     while ($signup->fetch()) {
         $signup->delete();
     }
     return false;
 }