/**
  * Load edit models
  * @return array
  */
 protected function loadEditModels()
 {
     $models = [];
     $models['rbacRoles'] = RbacRole::find()->with(['rbacRoleI18ns' => function ($query) {
         $query->select(['rbac_role_id', 'title'])->onCondition(['rbac_role_i18n.i18n_id' => Yii::$app->language]);
     }])->all();
     $models['rbacPermissions'] = RbacPermission::find()->with(['rbacPermissionI18ns' => function ($query) {
         $query->select(['rbac_permission_id', 'title'])->onCondition(['rbac_permission_i18n.i18n_id' => Yii::$app->language]);
     }])->all();
     $models['rbacRolesPermissions'] = [];
     foreach (RbacRolePermission::find()->all() as $rbacRolePermission) {
         $models['rbacRolesPermissions'][$rbacRolePermission->rbac_role_id][$rbacRolePermission->rbac_permission_id] = $rbacRolePermission;
         $models['rbacRolesPermissions'][$rbacRolePermission->rbac_role_id][$rbacRolePermission->rbac_permission_id]->scenario = 'update';
     }
     foreach ($models['rbacRoles'] as $rbacRole) {
         if (isset($rbacRole->rbacRoleI18ns[0])) {
             foreach ($models['rbacPermissions'] as $rbacRolePermission) {
                 if (isset($rbacRolePermission->rbacPermissionI18ns[0]) && !isset($models['rbacRolesPermissions'][$rbacRole->id][$rbacRolePermission->id])) {
                     $models['rbacRolesPermissions'][$rbacRole->id][$rbacRolePermission->id] = new RbacRolePermission(['scenario' => 'insert']);
                 }
             }
         }
     }
     return $models;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRbacPermission()
 {
     return $this->hasOne(RbacPermission::className(), ['id' => 'rbac_permission_id']);
 }
示例#3
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     $attributeLabels = parent::attributeLabels();
     $attributeLabels['rbac_permission_i18n_title'] = Yii::t('kalibao', 'model:title');
     return $attributeLabels;
 }