/** * Saves an game into the database. * * @param \GamyGoody\Domain\game $game The game to save */ public function save(game $game) { $logo = $game->getLogo(); $bg = $game->getBackground(); $this->imageDAO->save($logo); $this->imageDAO->save($bg); $gameData = array('game_title' => $game->getTitle(), 'game_logo_id' => $logo->getId(), 'game_bg_id' => $bg->getId()); if ($game->getId()) { // The game has already been saved : update it $this->getDb()->update('game', $gameData, array('game_id' => $game->getId())); } else { // The game has never been saved : insert it $this->getDb()->insert('game', $gameData); // Get the id of the newly created game and set it on the entity. $id = $this->getDb()->lastInsertId(); $game->setId($id); } }