/** * Saves a movie into the database. * * @param \MyMovies\Domain\Article $article The article to save */ public function save(Movie $movie) { $movieData = array('mov_title' => $movie->getTitle(), 'mov_description_long' => $movie->getDescriptionLong(), 'mov_description_short' => $movie->getDescriptionShort(), 'mov_director' => $movie->getDirector(), 'mov_year' => $movie->getYear(), 'mov_image' => $movie->getImage()); if ($movie->getId()) { // The article has already been saved : update it $this->getDb()->update('movie', $movieData, array('mov_id' => $movie->getId())); } else { // The article has never been saved : insert it $this->getDb()->insert('movie', $movieData); // Get the id of the newly created user and set it on the entity. $id = $this->getDb()->lastInsertId(); $movie->setId($id); } }