/** * Create a new Match object, given the set of initial attribute values. * @param homePoints the points won by the home team (must be non-negative) * @param awayPoints the points won by the away team (must be non-negative) * @param date the date of the match * @param isCompleted has the match been completed? * @param homeTeam the team which is the home team in this match * @param awayTeam the team which is the away team in this match * @param Entity\RoundImpl the round in which this match is played * @return Entity\MatchImpl t new Match object instance with the given attribute values * @throws RDException in case any of the po$arguments is negative or either of the teams is null or if the given teams are not in the same league */ public function createMatch($homePoints = null, $awayPoints = null, $date = null, $isCompleted = null, $homeTeam = null, $awayTeam = null, $sportsVenue = null, $round = null) { $aMatch = new Entity\MatchImpl(); if ($homePoints != null && $awayPoints != null && $date != null && $isCompleted != null && $homeTeam != null && $awayTeam != null) { $aMatch->setHomePoints($homePoints); $aMatch->setAwayPoints($awayPoints); $aMatch->setDate($date); $aMatch->setIsCompleted($isCompleted); $aMatch->setHomeTeam($homeTeam); //echo 'match' . var_dump($aMatch); $aMatch->setAwayTeam($awayTeam); $aMatch->setSportsVenue($sportsVenue); $aMatch->setRound($round); } return $aMatch; }
/** * Creates Match in database. * * @param Entity\MatchImpl $match * @throws RDException */ public function save($match) { if ($match->isPersistent()) { //update $q = "UPDATE " . DB_NAME . ".match " . "set home_points = ?,\n away_points = ?,\n match.date = CURRENT_TIMESTAMP,\n is_completed = ?,\n home_team_id = ?,\n away_team_id = ?,\n sports_venue_id = ?,\n round_id = ?\n WHERE match_id = ?;"; //create prepared statement from query $stmt = $this->dbConnection->prepare($q . ';'); $homePoints = $match->getHomePoints(); $awayPoints = $match->getAwayPoints(); $date = $match->getDate(); //bind parameters to prepared statement $stmt->bindParam(1, $homePoints, \PDO::PARAM_INT); $stmt->bindParam(2, $awayPoints, \PDO::PARAM_INT); //$stmt->bindParam(3, $date); $completed = $match->getIsCompleted() ? 1 : 0; $stmt->bindParam(3, $completed, \PDO::PARAM_INT); if ($match->getHomeTeam() != NULL) { $homeTeam = $match->getHomeTeam()->getId(); $stmt->bindParam(4, $homeTeam, \PDO::PARAM_INT); } if ($match->getAwayTeam() != NULL) { $awayTeam = $match->getAwayTeam()->getId(); $stmt->bindParam(5, $awayTeam, \PDO::PARAM_INT); } if ($match->getSportsVenue() != NULL) { $sportsVenue = $match->getSportsVenue()->getId(); $stmt->bindParam(6, $sportsVenue, \PDO::PARAM_INT); } $round = $match->getRound()->getId(); $matchID = $match->getId(); $stmt->bindParam(7, $round, \PDO::PARAM_INT); $stmt->bindParam(8, $matchID, \PDO::PARAM_INT); if ($stmt->execute()) { echo 'Match updated successfully'; } else { die($q); throw new RDException('Error updating match' . print_r($stmt->errorInfo())); } } else { //insert //create Query $q = "INSERT INTO " . DB_NAME . ".match (home_points, away_points, match.date, is_completed,\n home_team_id, away_team_id, sports_venue_id, round_id)\n VALUES(?, ?, ?, ?, ?, ?, ?, ?);"; //create prepared statement from query $stmt = $this->dbConnection->prepare($q . ';'); //bind parameters to prepared statement $homePoints = $match->getHomePoints(); $awayPoints = $match->getAwayPoints(); $date = $match->getDate(); //bind parameters to prepared statement $stmt->bindParam(1, $homePoints, \PDO::PARAM_INT); $stmt->bindParam(2, $awayPoints, \PDO::PARAM_INT); $stmt->bindParam(3, $date); $completed = $match->getIsCompleted() ? 1 : 0; $stmt->bindParam(4, $completed, \PDO::PARAM_INT); if ($match->getHomeTeam() != NULL) { $homeTeam = $match->getHomeTeam()->getId(); $stmt->bindParam(5, $homeTeam, \PDO::PARAM_INT); } if ($match->getAwayTeam() != NULL) { $awayTeam = $match->getAwayTeam()->getId(); $stmt->bindParam(6, $awayTeam, \PDO::PARAM_INT); } if ($match->getSportsVenue() != NULL) { $sportsVenue = $match->getSportsVenue()->getId(); $stmt->bindParam(7, $sportsVenue, \PDO::PARAM_INT); } if ($match->getRound() != NULL) { $round = $match->getRound(); $roundId = $round->getId(); $stmt->bindParam(8, $roundId, \PDO::PARAM_INT); } if ($stmt->execute()) { $match->setId($this->dbConnection->lastInsertId()); echo 'Match created successfully'; } else { throw new RDException('Error creating match: ' . print_r($stmt->errorInfo())); } } }
/** * resolves match score when 2 score reports differ. * * @param int $fixedHomeScore * @param int $fixedAwayScore * @param Entity\MatchImpl $match * @throws RDException if match is null or scores are negative * @return void */ public function resolveMatchScore($fixedHomeScore, $fixedAwayScore, $match) { $match->setHomePoints($fixedHomeScore); $match->setAwayPoints($fixedAwayScore); $this->objectLayer->storeMatch($match); /*$homeTeam = $match->getHomeTeam(); $awayTeam = $match->getAwayTeam(); //create empty score report $modelScoreReport = $this->objectLayer->createScoreReport(); $modelScoreReport->setMatch($match); //get both score reports for this match $scoreReportIter = $this->objectLayer->findScoreReport($modelScoreReport); //go through both reports and update the scores while($scoreReportIter->current()){ $scoreReport = $scoreReportIter->current(); //TODO figure out how to set the currect values of the score reports $scoreReportIter->next(); }*/ }
/** * @param \edu\uga\cs\recdawgs\entity\impl\MatchImpl $match * @param int $matchId * @return string */ public function listMatchInfo($match = null, $matchId = -1, $homeScore = -1, $awayScore = -1) { $html = ""; try { if ($match) { $leagueName = $match->getHomeTeam()->getParticipatesInLeague()->getName(); $roundNumber = strval($match->getRound()->getNumber()); $date = $match->getDate() ? $match->getDate() : "Date not set yet"; $homeTeamName = $match->getHomeTeam()->getName(); $awayTeamName = $match->getAwayTeam()->getName(); $venueName = $match->getSportsVenue()->getName(); $homeTeamScore = $homeScore > -1 && strval($match->getHomePoints()) == "" ? $homeScore : strval($match->getHomePoints()); $awayTeamScore = $awayScore > -1 && strval($match->getHomePoints()) == "" ? $awayScore : strval($match->getAwayPoints()); $html .= "<h1>League: {$leagueName} Round: {$roundNumber} Date: {$date}</h1><br/>"; $html .= "<h2>Home team: {$homeTeamName} Away team: {$awayTeamName} Venue: {$venueName}</h2><br/>"; //TODO ADD IF statement to show score only if game is done $html .= "<h3>Home team score: {$homeTeamScore} Away team Score: {$awayTeamScore}</h3>"; } else { if ($matchId > -1) { $match = $this->logicLayer->findMatch(null, $matchId)->current(); //die(var_dump($match)); $leagueName = $match->getHomeTeam()->getParticipatesInLeague()->getName(); $roundNumber = strval($match->getRound()->getNumber()); $date = $match->getDate(); if ($date == null) { $date = "Not set"; } $homeTeamName = $match->getHomeTeam()->getName(); $awayTeamName = $match->getAwayTeam()->getName(); $venueName = $match->getSportsVenue()->getName(); $homeTeamScore = $homeScore > -1 && strval($match->getHomePoints()) == "" ? $homeScore : strval($match->getHomePoints()); $awayTeamScore = $awayScore > -1 && strval($match->getHomePoints()) == "" ? $awayScore : strval($match->getAwayPoints()); $html .= "<h1>League: {$leagueName}<br/> Round: {$roundNumber}<br/> Date: {$date}</h1><br/>"; $html .= "<h2>Home team: {$homeTeamName} <br/> Away team: {$awayTeamName} <br/> Venue: {$venueName}</h2><br/>"; //TODO ADD IF statement to show score only if game is done $html .= "<h3>Home team score: {$homeTeamScore} <br/>Away team Score: {$awayTeamScore}</h3><br/>"; if ($match->getDate() == null) { $html .= "<br/><form method='POST' action='php/doScheduleMatch.php'><label for='date'>Schedule match date</label><input id='date' type='date' name='date'><input type='hidden' name='matchId' value='{$matchId}'><input type='submit' value='Schedule!'></form>"; } } } } catch (\Exception $e) { echo $e->getTraceAsString(); } return $html; }