/** * Method save template instance to db * @param $template Application_Model_Models_Template Template object * @param bool $forceNew * @return mixed * @throws Exceptions_SeotoasterException */ public function save($template) { if (!$template instanceof Application_Model_Models_Template) { throw new Exceptions_SeotoasterException('Given parameter should be and Application_Model_Models_Template instance'); } $data = array('name' => $template->getName(), 'content' => $template->getContent(), 'type' => $template->getType()); if ($template->getOldName() === null && null === $this->find($template->getName())) { return $this->getDbTable()->insert($data); } else { $whereName = $template->getOldName() === null ? $template->getName() : $template->getOldName(); $status = $this->getDbTable()->update($data, array('name = ?' => $whereName)); if ($status && $template->getOldName() != $template->getName()) { $pagesTable = new Application_Model_DbTable_Page(); $updatedPageCount = $pagesTable->update(array('template_id' => $template->getName()), array('template_id = ?' => $template->getOldName())); } return $status; } }
/** * Load langs from db * * @return mixed */ private function _loadLangs() { if ($this->_langsLoaded) { return; } /* @var $select Zend_Db_Select */ $select = $this->_dbTable->getAdapter()->select(); $select->from(array('l' => 'translate_language'), array('l.code', 'l.id', 'l.name', 'l.default', 'l.front_enabled')); $stmt = $select->query(); $langs = $stmt->fetchAll(); foreach ($langs as $lang) { self::$_languages[$lang['code']] = array('id' => $lang['id'], 'code' => $lang['code'], 'name' => $lang['name'], 'default' => $lang['default'] == 'yes', 'front_enabled' => $lang['front_enabled'] == 'yes'); //if default lang is not defined use first one as default if ($lang['default'] == 'yes' || !isset($this->_defaultLang)) { $this->_defaultLang = $lang['code']; } } $this->_langsLoaded = true; }
public function findAreasByPageId($pageId, $loadPages = false) { $pageDbTable = new Application_Model_DbTable_Page(); $pageRow = $pageDbTable->find($pageId)->current(); $areasRowset = $pageRow->findManyToManyRowset('Application_Model_DbTable_Featuredarea', 'Application_Model_DbTable_PageFeaturedarea'); //$areasRowset = $areasRowset->toArray(); $areas = array(); if ($areasRowset) { foreach ($areasRowset as $row) { $farea = new $this->_model($row->toArray()); if ($loadPages) { $farea->setPages($this->_findFarowPages($row)); } $areas[] = $farea; } } return $areas; }
public static function getPagesCountByTemplate($templateName) { $pageDbTable = new Application_Model_DbTable_Page(); return $pageDbTable->getAdapter()->query($pageDbTable->select()->where('template_id="' . $templateName . '"'))->rowCount(); }