Example #1
0
 /**
  * @param Application_Model_Models_Page $page
  * @return mixed
  * @throws Exceptions_SeotoasterException
  */
 public function save($page)
 {
     if (!$page instanceof Application_Model_Models_Page) {
         throw new Exceptions_SeotoasterException('Given parameter should be and Application_Model_Models_Page instance');
     }
     $data = array('template_id' => $page->getTemplateId(), 'parent_id' => $page->getParentId(), 'h1' => $page->getH1(), 'header_title' => $page->getHeaderTitle(), 'url' => $page->getUrl(), 'nav_name' => $page->getNavName(), 'meta_description' => $page->getMetaDescription(), 'meta_keywords' => $page->getMetaKeywords(), 'teaser_text' => $page->getTeaserText(), 'show_in_menu' => $page->getShowInMenu(), 'order' => $page->getOrder(), 'silo_id' => $page->getSiloId(), 'targeted_key_phrase' => $page->getTargetedKeyPhrase(), 'system' => intval($page->getSystem()), 'draft' => intval($page->getDraft()), 'news' => intval($page->getNews()), 'publish_at' => !$page->getPublishAt() ? null : date('Y-m-d', strtotime($page->getPublishAt())), 'preview_image' => $page->getPreviewImage());
     if ($page->getId()) {
         $this->getDbTable()->update($data, array('id = ?' => $page->getId()));
     } else {
         $pageId = $this->getDbTable()->insert($data);
         $page->setId($pageId);
     }
     //save page options
     $options = $page->getExtraOptions();
     $pageHasOptionTable = new Application_Model_DbTable_PageHasOption();
     if (!empty($options)) {
         $pageHasOptionTable->getAdapter()->beginTransaction();
         $pageHasOptionTable->delete($pageHasOptionTable->getAdapter()->quoteInto('page_id = ?', $page->getId()));
         foreach ($options as $option) {
             $pageHasOptionTable->insert(array('page_id' => $page->getId(), 'option_id' => $option));
         }
         $pageHasOptionTable->getAdapter()->commit();
     } else {
         $pageHasOptionTable->delete($pageHasOptionTable->getAdapter()->quoteInto('page_id = ?', $page->getId()));
     }
     return $page;
 }