<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Admin\Controller; use Illuminate\Routing\Controller; use Illuminate\Support\Collection; use ModStart\Admin\Auth\AdminPermission; use ModStart\Admin\Concern\HasAdminCRUD; use ModStart\Admin\Model\AdminRole; use ModStart\Admin\Model\AdminRoleRule; use ModStart\Admin\Model\AdminUser; use ModStart\Core\Util\ArrayUtil; use ModStart\Core\Util\ConvertUtil; use ModStart\Core\Util\CRUDUtil; use ModStart\Detail\Detail; use ModStart\Field\AbstractField; use ModStart\Form\Form; use ModStart\Form\Type\FormMode; use ModStart\Grid\Grid; use ModStart\Grid\GridFilter; class AdminRoleController extends Controller { use HasAdminCRUD; protected function grid() { goto BxbaI; BxbaI: $aGu71 = new Grid(AdminRole::class, function (Grid $aGu71) { $aGu71->display('id', L('ID'))->sortable(true)->width(80); $aGu71->text('name', L('Role Name'))->width(200); $aGu71->tree('rules', L('Role Permission'))->columnNameId('rule')->spread(false)->tree(AdminPermission::menuAll(null, true))->hookValueUnserialize(function ($FT9zA, AbstractField $SQ6_6) { return $FT9zA->pluck('rule'); }); $aGu71->textarea('remark', L('Remark')); $aGu71->gridFilter(function (GridFilter $JCV6U) { $JCV6U->eq('id', L('ID')); $JCV6U->like('name', L('Name')); }); }); goto OVgFJ; H2VLC: return $aGu71; goto GCOxs; F9nGR: $aGu71->title(L('Admin Role')); goto H2VLC; OVgFJ: if (AdminPermission::isNotPermit('AdminRoleManage')) { $aGu71->canAdd(false)->canEdit(false)->canDelete(false); } goto F9nGR; GCOxs: } protected function form() { goto lIbtV; xNCKz: return $u4AHU; goto ti9qa; Iq5Hx: $u4AHU->title(L('Admin Role')); goto xNCKz; lIbtV: $u4AHU = new Form(AdminRole::class, function (Form $u4AHU) { $u4AHU->display('id', L('ID'))->editable(true); $u4AHU->text('name', L('Role Name'))->required()->rules('unique:admin_role,name,' . CRUDUtil::id()); $u4AHU->tree('rules', L('Role Permission'))->rules('required')->columnNameId('rule')->tree(AdminPermission::menuAll(null, true))->hookValueUnserialize(function ($FT9zA, AbstractField $SQ6_6) { return collect($FT9zA)->pluck('rule'); })->hookValueSerialize(function ($FT9zA, AbstractField $SQ6_6) { return collect(json_decode($FT9zA, true))->map(function ($El_MH) { return array('rule' => $El_MH); }); }); $u4AHU->textarea('remark', L('Remark')); $u4AHU->display('created_at', L('Created At')); $u4AHU->display('updated_at', L('Updated At')); $u4AHU->hookSaving(function (Form $u4AHU) { if (FormMode::EDIT == $u4AHU->mode()) { goto PGoer; WqUem: $xfBWx = collect($u4AHU->item()->rules)->map(function ($xZ9fp) { return $xZ9fp['rule']; })->toArray(); goto Q_rtz; Hf_4n: $u4AHU->dataEditing(array_merge($u4AHU->dataEditing(), array('rules' => $uaAVC))); goto X5a8M; SeguQ: $YMOHj = ConvertUtil::toArray($XJykw['rules']); goto WqUem; PGoer: $XJykw = $u4AHU->dataSubmitted(); goto SeguQ; jxJgQ: if (!empty($xvvq2)) { AdminUser::whereIn('id', $xvvq2)->update(array('ruleChanged' => true)); } goto VgFh_; Q_rtz: list($uaAVC, $swAWg) = ArrayUtil::diff($xfBWx, $YMOHj); goto Nik4G; Nik4G: $uaAVC = collect($uaAVC)->map(function ($u7ouj) { return array('rule' => $u7ouj); }); goto Hf_4n; XIhLW: $xvvq2 = $u4AHU->item()->users->pluck('id')->toArray(); goto jxJgQ; X5a8M: if (!empty($swAWg)) { AdminRoleRule::where(array('roleId' => $u4AHU->itemId()))->whereIn('rule', $swAWg)->delete(); } goto XIhLW; VgFh_: } }); }); goto Cm_9y; Cm_9y: if (AdminPermission::isNotPermit('AdminRoleManage')) { $u4AHU->canAdd(false)->canEdit(false)->canDelete(false); } goto Iq5Hx; ti9qa: } protected function detail() { goto g9RN2; g9RN2: $jDI3Z = new Detail(AdminRole::class, function (Detail $jDI3Z) { $jDI3Z->display('id', L('ID')); $jDI3Z->text('name', L('Role Name')); $jDI3Z->tree('rules', L('Role Permission'))->columnNameId('rule')->tree(AdminPermission::menuAll(null, true))->hookValueUnserialize(function ($FT9zA, AbstractField $SQ6_6) { return $FT9zA->map(function ($u7ouj) { return $u7ouj['rule']; })->toArray(); }); $jDI3Z->display('remark', L('Remark')); $jDI3Z->display('created_at', L('Created At')); $jDI3Z->display('updated_at', L('Updated At')); }); goto Kgmts; i3yJT: return $jDI3Z; goto z1k0g; Kgmts: $jDI3Z->title(L('Admin Role')); goto i3yJT; z1k0g: } }