示例#1
0
 /**
  * @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;
 }
示例#2
0
 /**
  * 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()));
         }
     }
 }