Example #1
0
 /**
  * @param  string $userIdentifier
  * @param  string $scope |null
  * @return boolean
  */
 public function removeUserScope($userIdentifier, $scope = null)
 {
     $condition = ['user_id' => $userIdentifier];
     if ($scope) {
         $condition['scope_id'] = $scope;
     }
     $scopes = UserScopesModel::findAll($condition);
     $db = CommonModel::getDb();
     $transaction = $db->beginTransaction();
     try {
         foreach ($scopes as $scope) {
             $scope->delete();
         }
         $transaction->commit();
         return true;
     } catch (\Exception $e) {
         $transaction->rollBack();
         return false;
     }
 }
Example #2
0
 /**
  * @param $userId
  * @param ActiveQuery|null $query
  * @return ActiveQuery
  */
 public static function findByUserId($userId, ActiveQuery $query = null)
 {
     $query = $query ?: static::find();
     return $query->andWhere(['id' => UserScopesModel::findByUserId($userId)->select(['scope_id'])]);
 }