Skip to content

add new property startOrder and fix readme #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,36 @@ public function actions()
}
```

If you're using another order field not 'order' (example 'sortingFieldName'), you must specify it in 'orderAttribute' parameter:

```php
public function actions()
{
return [
'sorting' => [
'class' => \kotchuprik\sortable\actions\Sorting::className(),
'query' => \vendor\namespace\Model::find(),
'orderAttribute' => 'sortingFieldName',
],
];
}
```

If you're need start ordering not 0 you must specify it in 'startOrder' parameter:

```php
public function actions()
{
return [
'sorting' => [
'class' => \kotchuprik\sortable\actions\Sorting::className(),
'query' => \vendor\namespace\Model::find(),
'startOrder' => 1
],
];
}
```

If you're using another primary key (not 'id'), you must specify it in 'pk' parameter:

```php
Expand Down
7 changes: 5 additions & 2 deletions actions/Sorting.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Sorting extends Action

/** @var string */
public $pk = 'id';


/** @var int */
public $startOrder = 0;

public function run()
{
$transaction = \Yii::$app->db->beginTransaction();
Expand All @@ -28,7 +31,7 @@ public function run()
if ($model === null) {
throw new BadRequestHttpException();
}
$model->{$this->orderAttribute} = $offset + $order;
$model->{$this->orderAttribute} = $offset + $order + $this->startOrder;
$model->update(false, [$this->orderAttribute]);
}
$transaction->commit();
Expand Down