/** * Create a new Team object, given the set of initial attribute values. * @param String $name the name of the team * @param Entity\StudentImpl $student the student who is the captain of the new team * @param Entity\LeagueImpl $league the league in which the new team will participate * @return Entity\TeamImpl a new Team object instance with the given attribute values * @throws RDException in case name is null */ public function createTeam($name = null, $student = null, $league = null) { $aTeam = new Entity\TeamImpl(); if ($name != null && $student != null && $league != null) { $aTeam->setName($name); $aTeam->setCaptain($student); $aTeam->setParticipatesInLeague($league); //add team captain as a member of the team also. //moved up //$this->createStudentMemberOfTeam($student, $aTeam); } return $aTeam; }
/** * Called to join a player to a team * * When this method is called only set a values for $teamObj and $student OR $teamName and $studentId * Only those two combinations can be used: * e.g. joinTeam($teamObj=$myTeam, $user=$myUser); or joinTeam($teamName="Team Rocket", $userId=$myUserId); * * This is used to simulate overloading methods in PHP since this feature is unique to Java. * * @param Entity\TeamImpl $teamObj The team the player is joining * @param String $teamName The string name of the team to join * @param Entity\StudentImpl $studentObj The Student persistence object of the user joining the team * @param int $studentId The MySQL id of the student joining the team * @throws RDException if any parameter is null or if the max number of team members has been reached * @return int ID of the team joined */ public function joinTeam($teamObj = null, $teamName = null, $studentObj = null, $studentId = -1) { if ($teamName != null) { //create iter to find team with given team name $modelTeam = new Entity\TeamImpl(); $modelTeam->setName($teamName); $teamIter = $this->objectLayer->findTeam($modelTeam); $teamObj = $teamIter->current(); } if ($studentId > -1) { //create iter to find student with given id $modelStudent = new Entity\StudentImpl(); $modelStudent->setId($studentId); $studentIter = $this->objectLayer->findStudent($modelStudent); $studentObj = $studentIter->current(); } //check for maximum number of players in the team $teamMemberIter = $this->objectLayer->restoreStudentMemberOfTeam($teamObj); $leagueIter = $this->objectLayer->restoreTeamParticipatesInLeague($teamObj); $league = $leagueIter->current(); if ($teamMemberIter->size() >= $league->getMaxMembers()) { throw new RDException("Maximum number of members has been reached."); } $this->objectLayer->createStudentMemberOfTeam($studentObj, $teamObj); }