/** * 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; }