/** * Inserts or updates a page model in the database. * * @param PageModel $page */ public function save(PageModel $page) { if ($page->getId()) { if ($this->getPageByIdLocale($page->getId(), $page->getLocale())) { $this->db()->update('pages_content')->values(array('title' => $page->getTitle(), 'description' => $page->getDescription(), 'content' => $page->getContent(), 'perma' => $page->getPerma()))->where(array('page_id' => $page->getId(), 'locale' => $page->getLocale()))->execute(); } else { $this->db()->insert('pages_content')->values(array('page_id' => $page->getId(), 'description' => $page->getDescription(), 'title' => $page->getTitle(), 'content' => $page->getContent(), 'perma' => $page->getPerma(), 'locale' => $page->getLocale()))->execute(); } } else { $date = new \Ilch\Date(); $pageId = $this->db()->insert('pages')->values(array('date_created' => $date->toDb()))->execute(); $this->db()->insert('pages_content')->values(array('page_id' => $pageId, 'description' => $page->getDescription(), 'title' => $page->getTitle(), 'content' => $page->getContent(), 'perma' => $page->getPerma(), 'locale' => $page->getLocale()))->execute(); } }