/** * Save post - product relations * * @access public * @param Tech_Blog_Model_Post $post * @param array $data * @return Tech_Blog_Model_Resource_Post_Product * @author Ultimate Module Creator */ public function savePostRelation($post, $data) { if (!is_array($data)) { $data = array(); } $deleteCondition = $this->_getWriteAdapter()->quoteInto('post_id=?', $post->getId()); $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); foreach ($data as $productId => $info) { $this->_getWriteAdapter()->insert($this->getMainTable(), array('post_id' => $post->getId(), 'product_id' => $productId, 'position' => @$info['position'])); } return $this; }
/** * Save post - category relations * * @access public * @param Tech_Blog_Model_Post $post * @param array $data * @return Tech_Blog_Model_Resource_Post_Category * @author Ultimate Module Creator */ public function savePostRelation($post, $data) { if (!is_array($data)) { $data = array(); } $deleteCondition = $this->_getWriteAdapter()->quoteInto('post_id=?', $post->getId()); $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); foreach ($data as $categoryId) { if (!empty($categoryId)) { $insert = array('post_id' => $post->getId(), 'category_id' => $categoryId, 'position' => 1); $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), $insert, array_keys($insert)); } } return $this; }