/**
  * Save data for cmspage-product relation
  * @access public
  * @param  Ibrams_CmsExtended_Model_Cmspage $cmspage
  * @return Ibrams_CmsExtended_Model_Cmspage_Product
  * @author Ultimate Module Creator
  */
 public function saveCmspageRelation($cmspage)
 {
     $data = $cmspage->getProductsData();
     if (!is_null($data)) {
         $this->_getResource()->saveCmspageRelation($cmspage, $data);
     }
     return $this;
 }
 /**
  * Save cmspage - product relations
  *
  * @access public
  * @param Ibrams_CmsExtended_Model_Cmspage $cmspage
  * @param array $data
  * @return Ibrams_CmsExtended_Model_Resource_Cmspage_Product
  * @author Ultimate Module Creator
  */
 public function saveCmspageRelation($cmspage, $data)
 {
     if (!is_array($data)) {
         $data = array();
     }
     $deleteCondition = $this->_getWriteAdapter()->quoteInto('cmspage_id=?', $cmspage->getId());
     $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition);
     foreach ($data as $productId => $info) {
         $this->_getWriteAdapter()->insert($this->getMainTable(), array('cmspage_id' => $cmspage->getId(), 'product_id' => $productId, 'position' => @$info['position']));
     }
     return $this;
 }
 /**
  * Save cmspage - category relations
  *
  * @access public
  * @param Ibrams_CmsExtended_Model_Cmspage $cmspage
  * @param array $data
  * @return Ibrams_CmsExtended_Model_Resource_Cmspage_Category
  * @author Ultimate Module Creator
  */
 public function saveCmspageRelation($cmspage, $data)
 {
     if (!is_array($data)) {
         $data = array();
     }
     $deleteCondition = $this->_getWriteAdapter()->quoteInto('cmspage_id=?', $cmspage->getId());
     $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition);
     foreach ($data as $categoryId) {
         if (!empty($categoryId)) {
             $insert = array('cmspage_id' => $cmspage->getId(), 'category_id' => $categoryId, 'position' => 1);
             $this->_getWriteAdapter()->insertOnDuplicate($this->getMainTable(), $insert, array_keys($insert));
         }
     }
     return $this;
 }
 /**
  * Process positions of old parent cmspage children and new parent cmspage children.
  * Get position for moved cmspage
  *
  * @access protected
  * @param Ibrams_CmsExtended_Model_Cmspage $cmspage
  * @param Ibrams_CmsExtended_Model_Cmspage $newParent
  * @param null|int $afterCmspageId
  * @return int
  * @author Ultimate Module Creator
  */
 protected function _processPositions($cmspage, $newParent, $afterCmspageId)
 {
     $table = $this->getMainTable();
     $adapter = $this->_getWriteAdapter();
     $positionField = $adapter->quoteIdentifier('position');
     $bind = array('position' => new Zend_Db_Expr($positionField . ' - 1'));
     $where = array('parent_id = ?' => $cmspage->getParentId(), $positionField . ' > ?' => $cmspage->getPosition());
     $adapter->update($table, $bind, $where);
     /**
      * Prepare position value
      */
     if ($afterCmspageId) {
         $select = $adapter->select()->from($table, 'position')->where('entity_id = :entity_id');
         $position = $adapter->fetchOne($select, array('entity_id' => $afterCmspageId));
         $bind = array('position' => new Zend_Db_Expr($positionField . ' + 1'));
         $where = array('parent_id = ?' => $newParent->getId(), $positionField . ' > ?' => $position);
         $adapter->update($table, $bind, $where);
     } elseif ($afterCmspageId !== 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;
 }
示例#5
0
 /**
  * get data for api
  *
  * @access protected
  * @param Ibrams_CmsExtended_Model_Cmspage $cmspage
  * @return array()
  * @author Ultimate Module Creator
  */
 protected function _getApiData(Ibrams_CmsExtended_Model_Cmspage $cmspage)
 {
     return $cmspage->getData();
 }
 /**
  * get specific node
  *
  * @access public
  * @param Ibrams_CmsExtended_Model_Cmspage $parentNodeCmspage
  * @param $int $recursionLevel
  * @return Varien_Data_Tree_Node
  * @author Ultimate Module Creator
  */
 public function getNode($parentNodeCmspage, $recursionLevel = 2)
 {
     $tree = Mage::getResourceModel('ibrams_cmsextended/cmspage_tree');
     $nodeId = $parentNodeCmspage->getId();
     $parentId = $parentNodeCmspage->getParentId();
     $node = $tree->loadNode($nodeId);
     $node->loadChildren($recursionLevel);
     if ($node && $nodeId != Mage::helper('ibrams_cmsextended/cmspage')->getRootCmspageId()) {
         $node->setIsVisible(true);
     } elseif ($node && $node->getId() == Mage::helper('ibrams_cmsextended/cmspage')->getRootCmspageId()) {
         $node->setName(Mage::helper('ibrams_cmsextended')->__('Root'));
     }
     $tree->addCollectionData($this->getCmspageCollection());
     return $node;
 }