/** * Saves the given news object to the db * * @param \News\Model\News $news * * @throws \Exception */ public function saveNews(News $news) { $data = ['account_id' => $news->getAccountId(), 'title' => $news->getTitle(), 'content' => $news->getContent(), 'category_id' => $news->getCategoryId(), 'date_posted' => $news->getDatePosted()]; $id = (int) $news->getId(); if ($id == 0) { $this->tableGateway->insert($data); } else { if ($this->getNews($id)) { $this->tableGateway->update($data, ['id' => $id]); } else { throw new \Exception('News id does not exist'); } } }