backend/controllers/PostController.php
/**
     * Bulk action for Post triggered when button 'Apply' clicked.
     * The action depends on the value of the dropdown next to the button.
     * Only accept POST HTTP method.
     */
Bulk action for Post triggered when button 'Apply' clicked.
The action depends on the value of the dropdown next to the button.
Only accept POST HTTP method.
Bulk action for Post triggered when button ' Apply ' clicked . The action depends on the value of the dropdown next to the button . Only accept POST HTTP method .
public function actionBulkAction()
    {
        if (Yii::$app->request->post('action') === Post::STATUS_PUBLISH) {
            foreach (Yii::$app->request->post('ids', []) as $id) {
                $model = $this->findModel($id);
                $this->getPermission($model);
                $model->updateAttributes(['status' => Post::STATUS_PUBLISH]);
            }
        } elseif (Yii::$app->request->post('action') === Post::STATUS_DRAFT) {
            foreach (Yii::$app->request->post('ids', []) as $id) {
                $model = $this->findModel($id);
                $this->getPermission($model);
                $model->updateAttributes(['status' => Post::STATUS_DRAFT]);
            }
        } elseif (Yii::$app->request->post('action') === Post::STATUS_PRIVATE) {
            foreach (Yii::$app->request->post('ids', []) as $id) {
                $model = $this->findModel($id);
                $this->getPermission($model);
                $model->updateAttributes(['status' => Post::STATUS_PRIVATE]);
            }
        } elseif (Yii::$app->request->post('action') === Post::STATUS_TRASH) {
            foreach (Yii::$app->request->post('ids', []) as $id) {
                $model = $this->findModel($id);
                $this->getPermission($model);
                $model->updateAttributes(['status' => Post::STATUS_TRASH]);
            }
        } elseif (Yii::$app->request->post('action') === Post::STATUS_REVIEW) {
            foreach (Yii::$app->request->post('ids', []) as $id) {
                $model = $this->findModel($id);
                $this->getPermission($model);
                $model->updateAttributes(['status' => Post::STATUS_REVIEW]);
            }
        } elseif (Yii::$app->request->post('action') === 'delete') {
            foreach (Yii::$app->request->post('ids', []) as $id) {
                $model = $this->findModel($id);
                $this->getPermission($model);
                $terms = $model->terms;
                if ($model->delete()) {
                    foreach ($terms as $term) {
                        $term->updateAttributes(['count' => --$term->count]);
                    }
                }
            }
        }
    }
public function actionBulkAction ( ) { if ( Yii :: $ app -> request -> post ( 'action' ) === Post :: STATUS_PUBLISH ) { foreach ( Yii :: $ app -> request -> post ( 'ids' , [ ] ) as $ id ) { $ model = $ this -> findModel ( $ id ) ; $ this -> getPermission ( $ model ) ; $ model -> updateAttributes ( [ 'status' => Post :: STATUS_PUBLISH ] ) ; } } elseif ( Yii :: $ app -> request -> post ( 'action' ) === Post :: STATUS_DRAFT ) { foreach ( Yii :: $ app -> request -> post ( 'ids' , [ ] ) as $ id ) { $ model = $ this -> findModel ( $ id ) ; $ this -> getPermission ( $ model ) ; $ model -> updateAttributes ( [ 'status' => Post :: STATUS_DRAFT ] ) ; } } elseif ( Yii :: $ app -> request -> post ( 'action' ) === Post :: STATUS_PRIVATE ) { foreach ( Yii :: $ app -> request -> post ( 'ids' , [ ] ) as $ id ) { $ model = $ this -> findModel ( $ id ) ; $ this -> getPermission ( $ model ) ; $ model -> updateAttributes ( [ 'status' => Post :: STATUS_PRIVATE ] ) ; } } elseif ( Yii :: $ app -> request -> post ( 'action' ) === Post :: STATUS_TRASH ) { foreach ( Yii :: $ app -> request -> post ( 'ids' , [ ] ) as $ id ) { $ model = $ this -> findModel ( $ id ) ; $ this -> getPermission ( $ model ) ; $ model -> updateAttributes ( [ 'status' => Post :: STATUS_TRASH ] ) ; } } elseif ( Yii :: $ app -> request -> post ( 'action' ) === Post :: STATUS_REVIEW ) { foreach ( Yii :: $ app -> request -> post ( 'ids' , [ ] ) as $ id ) { $ model = $ this -> findModel ( $ id ) ; $ this -> getPermission ( $ model ) ; $ model -> updateAttributes ( [ 'status' => Post :: STATUS_REVIEW ] ) ; } } elseif ( Yii :: $ app -> request -> post ( 'action' ) === 'delete' ) { foreach ( Yii :: $ app -> request -> post ( 'ids' , [ ] ) as $ id ) { $ model = $ this -> findModel ( $ id ) ; $ this -> getPermission ( $ model ) ; $ terms = $ model -> terms ; if ( $ model -> delete ( ) ) { foreach ( $ terms as $ term ) { $ term -> updateAttributes ( [ 'count' => -- $ term -> count ] ) ; } } } } }
Bulk action for Post triggered when button 'Apply' clicked.
Bulk action for Post triggered when button ' Apply ' clicked .