elmys/status-filter-behave

典型的辅助器,用于显示状态下拉列表并验证它们的顺序

安装: 72

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

dev-master 2022-01-28 13:27 UTC

This package is auto-updated.

Last update: 2024-09-15 13:21:15 UTC


README

典型的辅助器,用于显示状态下拉列表并验证它们的顺序

为什么你需要这个扩展

通过数组中允许的状态序列或/和权限来过滤模型的扩展状态。同时进行预验证。您的模型应具有额外的状态历史表和相应的关联方法。

安装

安装此扩展的首选方式是通过 composer

  • 运行以下命令
php composer.phar require --prefer-dist "elmys/status-filter-behave" : "master@dev"

或者

"elmys/status-filter-behave" : "master@dev"

将以下内容添加到您的应用程序的 composer.json 文件的 require 部分中。

用法

在您的状态模型中

// Import
use elmys\helpers\statusfilterbehave;

class YourStatusHistoryModel{

//constants section
const STATUS_ONE = 1; // status_one
const STATUS_TWO = 2; // status_two
const STATUS_THREE = 3; // status_three

const ALLOWED_STATUSES = [
        self::STATUS_ONE => [
            self::STATUS_TWO,
        ],
        self::STATUS_TWO => [
            self::STATUS_ONE,
            self::STATUS_THREE,
        ],
];

const STATUSES_BY_PERMISSIONS = [
        'permissionOne' => [
            self::STATUS_ONE,
        ],
];

//behave section
public function behaviors()
    {
        return [
            [
                'class' => StatusFilterBehave::class,
                'getParentMethodName' => 'order', // YourStatusHistoryModel->getOrder() = order
                //'sortListAsc' => false, // sort list of statuses
                //'parentStatusAttributeName' => 'current_status_id', // if general model store current status id and have different field name
                //'childStatusIdAttributeName' => 'status_id', // if model of statuses has different field name
                //'errorMsgEmptyStatus' => 'You must fill "Status"', // error message 1
                //'errorMsgWrongJumpStatus' => 'Incorrect sequence of statuses', // error message 2
                //'errorMsgPermission' => 'You haven\'t permission', // error message 3
            ],
        ];
    }
}

在 activeForm 视图文件中

// $model - model of statuses
<?= $form->field($model, 'status_id')->dropDownList($model->getAvailableStatuses($model)) ?>