Example #1
0
 /**
  * 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;
 }
Example #2
0
 /**
  * Team is set as league winner
  *
  * @param Entity\LeagueImpl $league
  * @param Entity\TeamImpl $team
  * @throws RDException is thrown if team is not in the league.
  * @return void
  */
 public function selectLeagueWinner($league, $team)
 {
     if ($team->getParticipatesInLeague()->getName() != $league->getName()) {
         throw new RDException($string = "Team is not in this league.");
     }
     $this->objectLayer->createTeamWinnerOfLeague($team, $league);
 }
Example #3
0
 /**
  * Deletes winner.
  *
  * @param Entity\TeamImpl $team
  * @param Entity\LeagueImpl $league
  * @throws RDException
  */
 public function deleteWinner($team, $league)
 {
     $q = 'DELETE FROM is_winner_of WHERE team_id = ? AND league_id = ?;';
     //create Prepared statement
     $stmt = $this->dbConnection->prepare($q);
     //bind parameter to query
     $teamId = $team->getId();
     $leagueId = $league->getId();
     $stmt->bindParam(1, $teamId, \PDO::PARAM_INT);
     $stmt->bindParam(2, $leagueId, \PDO::PARAM_INT);
     //execute query
     if ($stmt->execute()) {
         echo 'link deleted successfully';
     } else {
         throw new RDException('Deletion of link unsuccessful');
     }
 }
Example #4
0
 /**
  * Restores winner of league.
  * 
  * @param Entity\TeamImpl $team
  * @return Entity\LeagueImpl
  * @throws RDException
  */
 public function restoreLeagueWinnerOf($team)
 {
     if ($team == null) {
         throw new RDException('Team parameter is null');
     }
     $q = 'SELECT * from league WHERE league_id = (SELECT league_id FROM league_team WHERE team_id = ? LIMIT 1);';
     $stmt = $this->dbConnection->prepare($q);
     $teamID = $team->getId();
     $stmt->bindParam(1, $teamID, \PDO::PARAM_INT);
     if ($stmt->execute()) {
         //get results from Query
         $resultSet = $stmt->fetchAll(\PDO::FETCH_ASSOC);
         // return first obj
         return (new LeagueIterator($resultSet, $this->objLayer))->current();
     } else {
         throw new RDException('Error restoring league');
     }
 }