Skip to content

Commit

Permalink
Merge pull request #20 from tsanchev/master
Browse files Browse the repository at this point in the history
add option for start position
  • Loading branch information
richardfan1126 authored Mar 9, 2020
2 parents e74effb + 20284e0 commit e7726b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function actions(){
'class' => SortableAction::className(),
'activeRecordClassName' => YourActiveRecordClass::className(),
'orderColumn' => 'name_of_field_storing_ordering',
'startPosition' => 1, // optional, default is 0
],
// your other actions
];
Expand Down
10 changes: 9 additions & 1 deletion SortableAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use yii\base\InvalidConfigException;

class SortableAction extends Action {

/**
* (required) The ActiveRecord Class name
*
Expand All @@ -21,6 +22,13 @@ class SortableAction extends Action {
*/
public $orderColumn;

/**
* Start index/position default 0
*
* @var integer
*/
public $startPosition = 0;

public function init(){
parent::init();
if(!isset($this->activeRecordClassName)){
Expand All @@ -41,7 +49,7 @@ public function run(){
$page = $activeRecordClassName::findOne($item);
//$page = $activeRecordClassName::find()->where($item);
$page->updateAttributes([
$this->orderColumn => $i,
$this->orderColumn => $i + $this->startPosition,
]);
}
}
Expand Down

0 comments on commit e7726b4

Please sign in to comment.