/**
  * 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;
 }