/** * Insert/update record in DB * * @return mixed */ public function save() { $needUpdateCategories = false; $needUpdateChannels = false; if (array_key_exists('categories', $this->_modifiedFields) && $this->_modifiedFields['categories'] == true) { $needUpdateCategories = true; } if (array_key_exists('channels', $this->_modifiedFields) && $this->_modifiedFields['channels'] == true) { $needUpdateChannels = true; } $result = parent::save(); if ($needUpdateCategories) { $siteCategoryModel = new Sppc_Site_CategoryModel(); $siteCategories = $this->findDependentRowset('Sppc_Site_CategoryModel', 'Site'); $categories = $this->getCategories(); foreach ($siteCategories as $siteCategory) { if (!array_key_exists($siteCategory->getIdCategory(), $categories)) { $siteCategory->delete(); } } foreach ($categories as $category) { $needToCreate = true; foreach ($siteCategories as $siteCategory) { if ($siteCategory->getIdCategory() == $category->getId()) { $needToCreate = false; break; } } if ($needToCreate) { $data = array('id_site' => $this->getId(), 'id_category' => $category->getId()); $row = $siteCategoryModel->createRow($data); $row->save(); } } } if ($needUpdateChannels) { $siteChannelModel = new Sppc_Site_ChannelModel(); $siteChannels = $this->findDependentRowset('Sppc_Site_Channel', 'Site'); $channels = $this->getChannels(); foreach ($siteChannels as $siteChannel) { if (!array_key_exists($siteChannel->getIdChannel(), $channels)) { $siteChannel->setStatus('deleted'); $siteChannel->save(); } } foreach ($channels as $channel) { $needToCreate = true; foreach ($siteChannels as $siteChannel) { if ($siteChannel->getIdChannel() == $channel->getId()) { $needToCreate = false; break; } } if ($needToCreate) { $data = array('id_site' => $this->getId(), 'id_channel' => $channel->getId()); $row = $siteChannelModel->createRow($data); $row->save(); } } } return $result; }
/** * Find layout for site * * @param Sppc_Db_Table_Row_Abstract $site * @return Sppc_Site_Layout */ public function findBySite(Sppc_Db_Table_Row_Abstract $site) { $select = $this->select(); $select->where('id_site=?', $site->getId()); return $this->fetchRow($select); }
public function save() { parent::save(); }