Skip to content

Commit 6c86d27

Browse files
committed
Release update
1 parent 7efb344 commit 6c86d27

File tree

4 files changed

+59
-59
lines changed

4 files changed

+59
-59
lines changed

BulkCheckboxAction.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*/
1414
class BulkCheckboxAction extends Action
1515
{
16+
const UPDATE_TYPE_ALL = 1;
17+
const UPDATE_TYPE_ONEBYONE = 0;
18+
1619
/**
1720
* @var \yii\db\ActiveRecord
1821
*/
@@ -28,6 +31,11 @@ class BulkCheckboxAction extends Action
2831
*/
2932
public $statusField;
3033

34+
/**
35+
* @var int
36+
*/
37+
public $updateType = self::UPDATE_TYPE_ALL;
38+
3139
/**
3240
* @inheritdoc
3341
*/
@@ -36,7 +44,16 @@ public function run()
3644
$postUrl = Yii::$app->request->get();
3745
$data = empty(Yii::$app->request->get($this->gridId . '_' . $this->statusField)) ? false : Json::decode(Yii::$app->request->get($this->gridId . '_' . $this->statusField), true);
3846
if ($data && count($data) >= 1) {
39-
$this->modelClass::updateAll([$this->statusField => $data['status']], [$this->modelClass::primaryKey()[0] => $data['ids']]);
47+
if ($this->updateType === self::UPDATE_TYPE_ALL) {
48+
$this->modelClass::updateAll([$this->statusField => $data['status']], [$this->modelClass::primaryKey()[0] => $data['ids']]);
49+
} elseif ($this->updateType === self::UPDATE_TYPE_ONEBYONE) {
50+
$models = $this->modelClass::find()->where([$this->modelClass::primaryKey()[0] => $data['ids']])->all();
51+
foreach ($models as $model) {
52+
$model->{$this->statusField} = $data['status'];
53+
$model->save();
54+
}
55+
}
56+
4057
}
4158

4259
if (!empty($postUrl[$this->gridId . '_' . $this->statusField])) {

ButtonDropdown.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class ButtonDropdown extends Widget
1212
{
13-
1413
/**
1514
* @var string
1615
*/
@@ -96,7 +95,6 @@ public function run()
9695
*/
9796
public function registerAssets()
9897
{
99-
10098
$view = $this->getView();
10199
ButtonDropdownAssets::register($view);
102100
$options = [

Module.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,21 @@ The preferred way to install this extension is through [composer](http://getcomp
99
Either run
1010

1111
```
12-
composer require --prefer-dist integready/yii2-bulkactionscheckboxcolumn "@dev"
12+
composer require --prefer-dist integready/yii2-bulkactionscheckboxcolumn "~1.0"
1313
```
1414

1515
or add
1616

1717
```
18-
"integready/yii2-bulkactionscheckboxcolumn": "@dev"
18+
"integready/yii2-bulkactionscheckboxcolumn": "~1.0"
1919
```
2020

2121
to the require section of your `composer.json` file.
2222

23-
Inserting a widget in GridView:
23+
Usage example:
2424
--
25+
###### GridView id must be set.
2526

26-
### Included variables (`#INCLUDED`):
27-
###### # These are NOT variables, you do not need to write them into the code, replace them with the correct strings or your variables! They are for what would be clear where you need to write the same para- meters.
28-
* `$idGrid // string`
29-
* `$fieldFirst // string`
30-
* `$itemsFirst // array(1 => 'On', 0 => 'Off')`
31-
* `$nameActionFirst // string`
32-
* `$fieldNext // string`
33-
* `$itemsNext // array(1 => 'On', 0 => 'Off')`
34-
* `$nameActionNext // string`
35-
* `$perPageName // string`
36-
37-
### Example:
3827
* index.php `(View)`:
3928
```php
4029
<?php
@@ -43,23 +32,29 @@ use kartik\grid\GridView;
4332

4433
?>
4534
<?= GridView::widget([
46-
'id' => $idGrid, #INCLUDED
47-
'dataProvider' => $dataProvider,
48-
'filterModel' => $searchModel,
49-
'columns' => [
35+
'id' => 'books-grid',
36+
'dataProvider' => $dataProvider,
37+
'filterModel' => $searchModel,
38+
'columns' => [
5039
[
51-
'class' => 'integready\bulkactionscheckboxcolumn\BulkCheckboxColumn',
52-
'elements' => [
40+
'class' => 'integready\bulkactionscheckboxcolumn\BulkCheckboxColumn',
41+
'elements' => [
5342
[
54-
'label' => 'Text first button',
55-
'field' => $fieldFirst, #INCLUDED
56-
'items' => $itemsFirst, #INCLUDED
43+
'label' => 'Change Availability',
44+
'field' => 'available',
45+
'items' => [
46+
1 => 'Yes',
47+
0 => 'No',
48+
],
5749
],
5850
// ...Many elements
5951
[
60-
'label' => 'Text next button',
61-
'field' => $fieldNext, #INCLUDED
62-
'items' => $itemsNext, #INCLUDED
52+
'label' => 'Change International Shipping',
53+
'field' => 'intl_shipping',
54+
'items' => [
55+
1 => 'Yes',
56+
0 => 'No',
57+
],
6358
]
6459
],
6560
],
@@ -68,42 +63,42 @@ use kartik\grid\GridView;
6863
]); ?>
6964
```
7065

71-
* SiteController.php `(Controller)`:
66+
* BookController.php `(Controller)`:
7267
```php
7368
<?php
7469

7570
namespace app\controllers;
7671

7772
use Yii;
7873
use yii\web\Controller;
79-
use backend\models\Site;
74+
use backend\models\Book;
8075
use yii\helpers\ArrayHelper;
81-
use backend\models\SiteSearch;
82-
use integready\bulkactionscheckboxcolumn\BulkStatusAction;
76+
use backend\models\BookSearch;
8377

8478
/**
85-
* SiteController implements the CRUD actions for Site model.
79+
* BookController implements the CRUD actions for Site model.
8680
*/
87-
class SiteController extends Controller
81+
class BookController extends Controller
8882
{
8983
/**
9084
* @inheritdoc
9185
*/
9286
public function actions()
9387
{
9488
return ArrayHelper::merge(parent::actions(), [
95-
$nameActionFirst => [ #INCLUDED
96-
'class' => BulkStatusAction::className(),
97-
'modelClass' => Site::className(),
98-
'gridId' => $idGrid, #INCLUDED
99-
'statusField' => $fieldFirst, #INCLUDED
89+
'bulk_available' => [
90+
'class' => BulkCheckboxAction::className(),
91+
'modelClass' => Book::className(),
92+
'gridId' => 'books-grid',
93+
'statusField' => 'available',
94+
'updateType' => BulkCheckboxAction::UPDATE_TYPE_ONEBYONE,
10095
],
10196
// ...Many actions
102-
$nameActionNext => [ #INCLUDED
103-
'class' => BulkStatusAction::className(),
104-
'modelClass' => Site::className(),
105-
'gridId' => $idGrid, #INCLUDED
106-
'statusField' => $fieldNext, #INCLUDED
97+
'bulk_intl_shipping' => [
98+
'class' => BulkCheckboxAction::className(),
99+
'modelClass' => Book::className(),
100+
'gridId' => 'books-grid',
101+
'statusField' => 'intl_shipping',
107102
],
108103
]);
109104
}
@@ -115,11 +110,11 @@ class SiteController extends Controller
115110
*/
116111
public function actionIndex()
117112
{
118-
$this->runAction($nameActionFirst); #INCLUDED
113+
$this->runAction('bulk_available');
119114
// ...Many actions with run
120-
$this->runAction($nameActionNext); #INCLUDED
115+
$this->runAction('bulk_intl_shipping');
121116

122-
$searchModel = new SiteSearch();
117+
$searchModel = new BookSearch();
123118
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
124119

125120
return $this->render('index', [

0 commit comments

Comments
 (0)