/** * Create a new ScoreReport 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 student the Student submitting the match score report * @param match the Match for which the score is reported * @return Entity\ScoreReportImpl a new ScoreReport object instance with the given attribute values * @throws RDException in case any of the po$arguments is negative, either student or match is null, or if the student is not the captain of one of the teams in the match */ public function createScoreReport($homePoints = null, $awayPoints = null, $date = null, $student = null, $match = null) { $aScoreReport = new Entity\ScoreReportImpl(); if ($homePoints != null && $awayPoints != null && $date != null && $student != null && $match != null) { $aScoreReport->setHomePoints($homePoints); $aScoreReport->setAwayPoints($awayPoints); $aScoreReport->setDate($date); $aScoreReport->setMatch($match); $aScoreReport->setStudent($student); } return $aScoreReport; }
/** * Allow a captain to input score of his/her match * ScoreReport is created linking Student (Captain) and Match with the scores * If this is the second ScoreReport of the Match, invoke the ConfirmMatchScore extension * * @param Entity\StudentImpl $captain Must be a captain of a team * @param Entity\MatchImpl $match * @param int $homeTeamScore * @param int $awayTeamScore * @throws RDException if student is not a captain of a team, if scores are negative or if any obj is null. * @return int $scoreReportId */ public function enterMatchScore($captain, $match, $homeTeamScore, $awayTeamScore) { if ($captain == null || $match == null || $homeTeamScore < 0 || $awayTeamScore < 0) { throw new RDException($string = "check params"); } //first check if there are already 2 score reports for this match. $modelScoreReport = new Entity\ScoreReportImpl(); $modelScoreReport->setMatch($match); //returns iter of all reports of this match $scoreReportIter = $this->objectLayer->findScoreReport($modelScoreReport); if ($scoreReportIter->size() >= 2) { throw new RDException($string = "There's already 2 score reports for this match."); } //now create it. $date = new \DateTime(date('Y-m-d H:i:s', time())); $scoreReport = $this->objectLayer->createScoreReport($homeTeamScore, $awayTeamScore, $date, $captain, $match); $this->objectLayer->storeScoreReport($scoreReport); if ($scoreReportIter->size() == 1) { $this->confirmMatchScore($scoreReportIter->current(), $scoreReport, $match); } }