Пример #1
0
 /**
  * @return PHPUnit_Framework_MockObject_MockObject|Zend_Db_Adapter_Abstract
  */
 public function testSetAddOrder()
 {
     $adapter = $this->_getAdapterMock('Zend_Db_Adapter_Pdo_Mysql', array('fetchAll'), null);
     $this->_collection->setConnection($adapter);
     $select = $this->_collection->getSelect();
     $this->assertEmpty($select->getPart(Zend_Db_Select::ORDER));
     $this->_collection->addOrder('some_field', Varien_Data_Collection::SORT_ORDER_ASC);
     $this->_collection->setOrder('other_field', Varien_Data_Collection::SORT_ORDER_ASC);
     $this->_collection->addOrder('other_field', Varien_Data_Collection::SORT_ORDER_DESC);
     $this->_collection->load();
     $selectOrders = $select->getPart(Zend_Db_Select::ORDER);
     $this->assertEquals('some_field ASC', (string) array_shift($selectOrders));
     $this->assertEquals('other_field DESC', (string) array_shift($selectOrders));
     $this->assertEmpty(array_shift($selectOrders));
     return $adapter;
 }
Пример #2
0
 /**
  * @return PHPUnit_Framework_MockObject_MockObject|Zend_Db_Adapter_Abstract
  */
 public function testSetAddOrder()
 {
     $adapter = $this->_getAdapterMock('Zend_Db_Adapter_Pdo_Mysql', array('fetchAll'), null);
     $this->_collection->setConnection($adapter);
     $select = $this->_collection->getSelect();
     $this->assertEmpty($select->getPart(Zend_Db_Select::ORDER));
     /* Direct access to select object is available and many places are using it for sort order declaration */
     $select->order('select_field', Varien_Data_Collection::SORT_ORDER_ASC);
     $this->_collection->addOrder('some_field', Varien_Data_Collection::SORT_ORDER_ASC);
     $this->_collection->setOrder('other_field', Varien_Data_Collection::SORT_ORDER_ASC);
     $this->_collection->addOrder('other_field', Varien_Data_Collection::SORT_ORDER_DESC);
     $this->_collection->load();
     $selectOrders = $select->getPart(Zend_Db_Select::ORDER);
     $this->assertEquals(array('select_field', 'ASC'), array_shift($selectOrders));
     $this->assertEquals('some_field ASC', (string) array_shift($selectOrders));
     $this->assertEquals('other_field DESC', (string) array_shift($selectOrders));
     $this->assertEmpty(array_shift($selectOrders));
     return $adapter;
 }
 /**
  * Set navigation parameters and apply filters from URL params
  *
  * @param Varien_Data_Collection_Db $collection
  * @return Mage_Api2_Model_Resource
  */
 protected final function _applyCollectionModifiers(Varien_Data_Collection_Db $collection)
 {
     $pageNumber = $this->getRequest()->getPageNumber();
     if ($pageNumber != abs($pageNumber)) {
         $this->_critical(self::RESOURCE_COLLECTION_PAGING_ERROR);
     }
     $pageSize = $this->getRequest()->getPageSize();
     if (null == $pageSize) {
         $pageSize = self::PAGE_SIZE_DEFAULT;
     } else {
         if ($pageSize != abs($pageSize) || $pageSize > self::PAGE_SIZE_MAX) {
             $this->_critical(self::RESOURCE_COLLECTION_PAGING_LIMIT_ERROR);
         }
     }
     $orderField = $this->getRequest()->getOrderField();
     if (null !== $orderField) {
         $operation = Mage_Api2_Model_Resource::OPERATION_ATTRIBUTE_READ;
         if (!is_string($orderField) || !array_key_exists($orderField, $this->getAvailableAttributes($this->getUserType(), $operation))) {
             $this->_critical(self::RESOURCE_COLLECTION_ORDERING_ERROR);
         }
         $collection->setOrder($orderField, $this->getRequest()->getOrderDirection());
     }
     $collection->setCurPage($pageNumber)->setPageSize($pageSize);
     return $this->_applyFilter($collection);
 }
Пример #4
0
 /**
  * Set sorting order
  *
  * $attribute can also be an array of attributes
  *
  * @param string|array $attribute
  * @param string $dir
  * @return Mage_Eav_Model_Entity_Collection_Abstract
  */
 public function setOrder($attribute, $dir = self::SORT_ORDER_ASC)
 {
     if (is_array($attribute)) {
         foreach ($attribute as $attr) {
             parent::setOrder($attr, $dir);
         }
     }
     return parent::setOrder($attribute, $dir);
 }
Пример #5
0
 protected final function _applyCollectionModifiers(Varien_Data_Collection_Db $collection)
 {
     $pageNumber = $this->getRequest()->getPageNumber();
     if ($pageNumber != abs($pageNumber)) {
         throw new Mage_Webapi_Exception($this->_translationHelper->__("Page number is invalid."), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
     }
     $pageSize = $this->getRequest()->getPageSize();
     if (null == $pageSize) {
         $pageSize = self::PAGE_SIZE_DEFAULT;
     } else {
         if ($pageSize != abs($pageSize) || $pageSize > self::PAGE_SIZE_MAX) {
             throw new Mage_Webapi_Exception($this->_translationHelper->__('The paging limit exceeds the allowed number.'), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
         }
     }
     $orderField = $this->getRequest()->getOrderField();
     if (null !== $orderField) {
         if (!is_string($orderField)) {
             throw new Mage_Webapi_Exception($this->_translationHelper->__('Collection "order" value is invalid.'), Mage_Webapi_Exception::HTTP_BAD_REQUEST);
         }
         $collection->setOrder($orderField, $this->getRequest()->getOrderDirection());
     }
     $collection->setCurPage($pageNumber)->setPageSize($pageSize);
     return $collection;
 }