<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Admin\Controller; use Illuminate\Database\Eloquent\Model; 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\Dao\ModelUtil; 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\Field\Tree; use ModStart\Form\Form; use ModStart\Form\Type\FormMode; use ModStart\Show\Show; use ModStart\Grid\Grid; use ModStart\Grid\GridFilter; class AdminRoleController extends Controller { use HasAdminCRUD; protected function grid() { goto Nr2aN; ANC0H: if (AdminPermission::isNotPermit('AdminRoleManage')) { $QnI0I->canAdd(false)->canEdit(false)->canDelete(false); } goto JbAJL; JbAJL: $QnI0I->title(L('Admin Role')); goto r35qS; Nr2aN: $QnI0I = new Grid(AdminRole::class, function (Grid $QnI0I) { $QnI0I->display('id', L('ID'))->sortable(true)->width(80); $QnI0I->text('name', L('Role Name'))->width(200); $QnI0I->tree('rules', L('Role Permission'))->columnNameId('rule')->spread(false)->tree(AdminPermission::menuAll())->hookValueUnserialize(function ($tzAUI, AbstractField $Q2vn5) { return $tzAUI->pluck('rule'); }); $QnI0I->filter(function (GridFilter $cF9SB) { $cF9SB->eq('id', L('ID')); $cF9SB->like('name', L('Name')); }); }); goto ANC0H; r35qS: return $QnI0I; goto ded04; ded04: } protected function form() { goto R0ChJ; S8uCp: $Pl0Cf->title(L('Admin Role')); goto OClh_; Ut_cI: if (AdminPermission::isNotPermit('AdminRoleManage')) { $Pl0Cf->canAdd(false)->canEdit(false)->canDelete(false); } goto S8uCp; OClh_: return $Pl0Cf; goto NEw7z; R0ChJ: $Pl0Cf = new Form(AdminRole::class, function (Form $Pl0Cf) { $Pl0Cf->display('id', L('ID'))->editable(true); $Pl0Cf->text('name', L('Role Name'))->rules('required|unique:admin_role,name,' . CRUDUtil::id()); $Pl0Cf->tree('rules', L('Role Permission'))->rules('required')->columnNameId('rule')->tree(AdminPermission::menuAll())->hookValueUnserialize(function ($tzAUI, AbstractField $Q2vn5) { return collect($tzAUI)->pluck('rule'); })->hookValueSerialize(function ($tzAUI, AbstractField $Q2vn5) { return collect(json_decode($tzAUI, true))->map(function ($Nrp0b) { return array('rule' => $Nrp0b); }); }); $Pl0Cf->display('created_at', L('Created At')); $Pl0Cf->display('updated_at', L('Updated At')); $Pl0Cf->hookSaving(function (Form $Pl0Cf) { if (FormMode::EDIT == $Pl0Cf->mode()) { goto VAQWt; IvN3n: $Jid_3 = ConvertUtil::toArray($CGbra['rules']); goto eDC7G; Kn_p8: $Pl0Cf->dataEditing(array_merge($Pl0Cf->dataEditing(), array('rules' => $h48cP))); goto qD2KV; Ie8gL: $evcyN = $Pl0Cf->item()->users->pluck('id')->toArray(); goto iwwa7; YzPrp: $h48cP = collect($h48cP)->map(function ($yGFxf) { return array('rule' => $yGFxf); }); goto Kn_p8; qD2KV: if (!empty($yTCeu)) { AdminRoleRule::where(array('roleId' => $Pl0Cf->itemId()))->whereIn('rule', $yTCeu)->delete(); } goto Ie8gL; eDC7G: $A6f7Z = collect($Pl0Cf->item()->rules)->map(function ($bPX0o) { return $bPX0o['rule']; })->toArray(); goto s0aAm; VAQWt: $CGbra = $Pl0Cf->dataSubmitted(); goto IvN3n; iwwa7: if (!empty($evcyN)) { AdminUser::whereIn('id', $evcyN)->update(array('ruleChanged' => true)); } goto nUIO_; s0aAm: list($h48cP, $yTCeu) = ArrayUtil::diff($A6f7Z, $Jid_3); goto YzPrp; nUIO_: } }); }); goto Ut_cI; NEw7z: } protected function detail() { goto I5vJ_; hMBVN: return $z3x5T; goto vCMVr; UmKl6: $z3x5T->title(L('Admin Role')); goto hMBVN; I5vJ_: $z3x5T = new Detail(AdminRole::class, function (Detail $z3x5T) { $z3x5T->display('id', L('ID')); $z3x5T->text('name', L('Role Name')); $z3x5T->tree('rules', L('Role Permission'))->columnNameId('rule')->tree(AdminPermission::menuAll())->hookValueUnserialize(function ($tzAUI, AbstractField $Q2vn5) { return $tzAUI->map(function ($yGFxf) { return $yGFxf['rule']; })->toArray(); }); $z3x5T->display('created_at', L('Created At')); $z3x5T->display('updated_at', L('Updated At')); }); goto UmKl6; vCMVr: } }