/** * Specify category filter for post collection * * @param EM_Blog_Model_Category $category * @return EM_Blog_Model_Resource_Post_Collection */ public function addCategoryFilter(EM_Blog_Model_Category $category) { $this->_productLimitationFilters['category_id'] = $category->getId(); if ($category->getIsAnchor()) { unset($this->_productLimitationFilters['category_is_anchor']); } else { $this->_productLimitationFilters['category_is_anchor'] = 1; } if ($this->getStoreId() == EM_Blog_Model_Abstract::DEFAULT_STORE_ID) { $this->_applyZeroStoreProductLimitations(); } else { $this->_applyProductLimitations(); } return $this; }
/** * Process positions of old parent category children and new parent category children. * Get position for moved category * * @param EM_Blog_Model_Category $category * @param EM_Blog_Model_Category $newParent * @param null|int $afterCategoryId * @return int */ protected function _processPositions($category, $newParent, $afterCategoryId) { $table = $this->getEntityTable(); $adapter = $this->_getWriteAdapter(); $positionField = $adapter->quoteIdentifier('position'); $bind = array('position' => new Zend_Db_Expr($positionField . ' - 1')); $where = array('parent_id = ?' => $category->getParentId(), $positionField . ' > ?' => $category->getPosition()); $adapter->update($table, $bind, $where); /** * Prepare position value */ if ($afterCategoryId) { $select = $adapter->select()->from($table, 'position')->where('entity_id = :entity_id'); $position = $adapter->fetchOne($select, array('entity_id' => $afterCategoryId)); $bind = array('position' => new Zend_Db_Expr($positionField . ' + 1')); $where = array('parent_id = ?' => $newParent->getId(), $positionField . ' > ?' => $position); $adapter->update($table, $bind, $where); } elseif ($afterCategoryId !== null) { $position = 0; $bind = array('position' => new Zend_Db_Expr($positionField . ' + 1')); $where = array('parent_id = ?' => $newParent->getId(), $positionField . ' > ?' => $position); $adapter->update($table, $bind, $where); } else { $select = $adapter->select()->from($table, array('position' => new Zend_Db_Expr('MIN(' . $positionField . ')')))->where('parent_id = :parent_id'); $position = $adapter->fetchOne($select, array('parent_id' => $newParent->getId())); } $position += 1; return $position; }