mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-13 04:38:03 +08:00
Added yii\data\Sort::setAttributeOrders()
This commit is contained in:
@@ -30,6 +30,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #11541: Fixed default MySQL integer display width for unsigned primary key (h311ion, rob006, cebe)
|
||||
- Bug #12143: Fixed `yii\db\BaseActiveRecord::updateAttributes()` change `isNewRecord` state for the new model (klimov-paul)
|
||||
- Enh #9708: Added `yii\console\controllers\AssetController::deleteSource` option allowing deletion of the source asset files after compression (pana1990, klimov-paul)
|
||||
- Enh #10243: Added `yii\data\Sort::setAttributeOrders()` method allowing manual setup of current sort (klimov-paul)
|
||||
- Enh #10583: Do not silence session errors in debug mode (samdark)
|
||||
- Enh #11658: Added argument to `yii\grid\ActionColumn::urlCreator` callback, which holds reference to the column instance (klimov-paul)
|
||||
- Enh #11804: Added `yii\behaviors\AttributeTypecastBehavior` for maintaining of strict ActiveRecord attribute types (klimov-paul)
|
||||
|
||||
@@ -67,7 +67,7 @@ use yii\web\Request;
|
||||
* that can lead to pages with the data sorted by the corresponding attributes.
|
||||
*
|
||||
* @property array $attributeOrders Sort directions indexed by attribute names. Sort direction can be either
|
||||
* `SORT_ASC` for ascending order or `SORT_DESC` for descending order. This property is read-only.
|
||||
* `SORT_ASC` for ascending order or `SORT_DESC` for descending order.
|
||||
* @property array $orders The columns (keys) and their corresponding sort directions (values). This can be
|
||||
* passed to [[\yii\db\Query::orderBy()]] to construct a DB query. This property is read-only.
|
||||
*
|
||||
@@ -265,6 +265,32 @@ class Sort extends Object
|
||||
return $this->_attributeOrders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the currently sort information.
|
||||
* @param array|null $attributeOrders sort directions indexed by attribute names.
|
||||
* Sort direction can be either `SORT_ASC` for ascending order or
|
||||
* `SORT_DESC` for descending order.
|
||||
* @param boolean $validate whether to validate given attribute orders against [[attributes]] and [[enableMultiSort]].
|
||||
* If validation is enabled incorrect entries will be removed.
|
||||
* @since 2.0.10
|
||||
*/
|
||||
public function setAttributeOrders($attributeOrders, $validate = true)
|
||||
{
|
||||
if ($attributeOrders === null || !$validate) {
|
||||
$this->_attributeOrders = $attributeOrders;
|
||||
} else {
|
||||
$this->_attributeOrders = [];
|
||||
foreach ($attributeOrders as $attribute => $order) {
|
||||
if (isset($this->attributes[$attribute])) {
|
||||
$this->_attributeOrders[$attribute] = $order;
|
||||
if (!$this->enableMultiSort) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sort direction of the specified attribute in the current request.
|
||||
* @param string $attribute the attribute name
|
||||
|
||||
Reference in New Issue
Block a user