/** * @dataProvider setOrderDataProvider */ public function testSetOrder($order, $expectedOrder) { $this->_collection->setOrder($order); $this->_collection->load(); // perform real SQL query $selectOrder = $this->_collection->getSelect()->getPart(\Zend_Db_Select::ORDER); foreach ($expectedOrder as $field) { $orderBy = array_shift($selectOrder); $this->assertArrayHasKey(0, $orderBy); $this->assertTrue(false !== strpos($orderBy[0], $field), 'Ordering by same column more than once is restricted by multiple RDBMS requirements.'); } }
/** * Add sorting * * @param string $attribute * @param string $dir * @return $this */ public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) { if ($attribute == 'purchases' || $attribute == 'downloads' || $attribute == 'link_title') { $this->getSelect()->order($attribute . ' ' . $dir); } else { parent::setOrder($attribute, $dir); } return $this; }
/** * Set order * * @param string $attribute * @param string $dir * @return $this */ public function setOrder($attribute, $dir = self::SORT_ORDER_DESC) { if (in_array($attribute, ['carts'])) { $this->getSelect()->order($attribute . ' ' . $dir); } else { parent::setOrder($attribute, $dir); } return $this; }
/** * Set order to attribute * * @param string $attribute * @param string $dir * @return $this */ public function setOrder($attribute, $dir = 'DESC') { switch ($attribute) { case 'rt.review_id': case 'rt.created_at': case 'rt.status_id': case 'rdt.title': case 'rdt.nickname': case 'rdt.detail': $this->getSelect()->order($attribute . ' ' . $dir); break; case 'stores': // No way to sort break; case 'type': $this->getSelect()->order('rdt.customer_id ' . $dir); break; default: parent::setOrder($attribute, $dir); break; } return $this; }
/** * Set Order field * * @param string $attribute * @param string $dir * @return $this */ public function setOrder($attribute, $dir = 'desc') { if ($attribute == 'relevance') { $this->getSelect()->order("relevance {$dir}"); } else { parent::setOrder($attribute, $dir); } return $this; }
/** * Set Order field * * @param string $attribute * @param string $dir * @return $this */ public function setOrder($attribute, $dir = Select::SQL_DESC) { $this->order = ['field' => $attribute, 'dir' => $dir]; if ($attribute != 'relevance') { parent::setOrder($attribute, $dir); } return $this; }
/** * Set sorting order * * $attribute can also be an array of attributes * * @param string|array $attribute * @param string $dir * @return $this */ public function setOrder($attribute, $dir = self::SORT_ORDER_ASC) { if ($attribute == 'position') { return $this->setPositionOrder($dir); } elseif ($attribute == 'attribute_set_id') { return $this->setAttributeSetIdOrder($dir); } return parent::setOrder($attribute, $dir); }