public function getOrCreate(EGGame $game, $month) { $this->assertMonth($month); $stats = $this->findOneBy(['game' => $game->getId(), 'statsMonth' => $month]); if ($stats !== null) { return $stats; } $stats = new EGGameStats(); $stats->setGame($game)->setStatsMonth($month)->setRank(0)->setMonthPlays(0)->setMonthRatedFeedbacks(0)->setMonthVotes(0)->setLastUpdated(new \DateTime()); $this->getEntityManager()->persist($stats); return $stats; }
public static function make(EGGame $game, $month = '') { if (!$month) { $month = date('Y-m'); } if (!preg_match('/\\d{4}\\-\\d{2}/', $month)) { throw new \InvalidArgumentException("Month must be in the format 'Y-m' (e.g. 2013-12)."); } $stats = new EGGameStats(); $stats->setGame($game); $stats->setStatsMonth($month); return $stats; }