/** * Save data for tab - temple relation * @access public * @param Lionleap_Temples_Model_Tab $tab * @return Lionleap_Temples_Model_Tab_Temple * @author Ultimate Module Creator */ public function saveTabRelation($tab) { $data = $tab->getTemplesData(); if (!is_null($data)) { $this->_getResource()->saveTabRelation($tab, $data); } return $this; }
/** * Save tab - temple relations * * @access public * @param Lionleap_Temples_Model_Tab $tab * @param array $data * @return Lionleap_Temples_Model_Resource_Tab_Temple * @author Ultimate Module Creator */ public function saveTabRelation($tab, $data) { if (!is_array($data)) { $data = array(); } $adapter = $this->_getWriteAdapter(); $bind = array(':tab_id' => (int) $tab->getId()); $select = $adapter->select()->from($this->getMainTable(), array('id', 'temple_id'))->where('tab_id = :tab_id'); $related = $adapter->fetchPairs($select, $bind); $deleteIds = array(); foreach ($related as $relId => $templeId) { if (!isset($data[$templeId])) { $deleteIds[] = (int) $relId; } } if (!empty($deleteIds)) { $adapter->delete($this->getMainTable(), array('id IN (?)' => $deleteIds)); } foreach ($data as $templeId => $info) { $adapter->insertOnDuplicate($this->getMainTable(), array('tab_id' => $tab->getId(), 'temple_id' => $templeId, 'position' => @$info['position']), array('position')); } return $this; }