本文整理汇总了PHP中Varien_Data_Collection_Db::setOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Collection_Db::setOrder方法的具体用法?PHP Varien_Data_Collection_Db::setOrder怎么用?PHP Varien_Data_Collection_Db::setOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Data_Collection_Db
的用法示例。
在下文中一共展示了Varien_Data_Collection_Db::setOrder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetAddOrder
/**
* @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: testSetAddOrder
/**
* @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;
}
示例3: _applyCollectionModifiers
/**
* 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: setOrder
/**
* 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);
}