Beispiel #1
0
 /**
  * @param string|integer $user the user ID.
  * @param Item $item the role or permission that this rule is associated with
  * @param array $params parameters passed to ManagerInterface::checkAccess().
  * @return boolean a value indicating whether the rule permits the role or permission it is associated with.
  */
 public function execute($user, $item, $params)
 {
     if (!Yii::$app->user->isGuest) {
         foreach (Yii::$app->getModule('rbac')->roles as $role) {
             if ($item->name === $role) {
                 return UserRole::find()->joinWith('role')->andWhere(['{{%user_role}}.user_id' => $user, '{{%role}}.name' => $role])->exists();
             }
         }
         return false;
     }
     return false;
 }
Beispiel #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserRole::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'role_id' => $this->role_id, 'tenant_id' => $this->tenant_id, 'created_at' => $this->created_at, 'create_user_id' => $this->create_user_id, 'updated_at' => $this->updated_at, 'update_user_id' => $this->update_user_id]);
     return $dataProvider;
 }
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserRole()
 {
     return UserRole::find()->andWhere(['user_id' => $this->id]);
 }