<commit_before><?php
/**
 * @link https://github.com/gromver/yii2-platform-basic.git#readme
 * @copyright Copyright (c) <NAME>, 2014
 * @license https://github.com/gromver/yii2-platform-basic/blob/master/LICENSE
 * @package yii2-platform-basic
 * @version 1.0.0
 */

namespace gromver\platform\core\modules\user\models;


use yii\db\ActiveQuery;

/**
 * Class UserQuery
 * @package yii2-platform-basic
 * @author <NAME> <<EMAIL>>
 */
class UserQuery extends ActiveQuery {
    /**
     * Все элементы не отправленные в корзину
     * @return static
     */
    public function published()
    {
        return $this->andWhere(['deleted_at' => null]);
    }

    /**
     * Элементы отправленные в корзину
     * @return static
     */
    public function trashed()
    {
        return $this->andWhere(['not', ['deleted_at' => null]]);
    }

    /**
     * Активные пользователи
     * @return static
     */
    public function active()
    {
        return $this->andWhere(['status' => User::STATUS_ACTIVE, 'deleted_at' => null]);
    }

    /**
     * Неактивные пользователи
     * @return static
     */
    public function inactive()
    {
        return $this->andWhere(['status' => User::STATUS_INACTIVE, 'deleted_at' => null]);
    }

    /**
     * Пользователи ожидающие активации
     * @return static
     */
    public function suspended()
    {
        return $this->andWhere(['status' => User::STATUS_SUSPENDED, 'deleted_at' => null]);
    }
}<commit_msg>UserQuery add can condition<commit_after><?php
/**
 * @link https://github.com/gromver/yii2-platform-basic.git#readme
 * @copyright Copyright (c) <NAME>, 2014
 * @license https://github.com/gromver/yii2-platform-basic/blob/master/LICENSE
 * @package yii2-platform-basic
 * @version 1.0.0
 */

namespace gromver\platform\core\modules\user\models;


use yii\db\ActiveQuery;

/**
 * Class UserQuery
 * @package yii2-platform-basic
 * @author <NAME> <<EMAIL>>
 */
class UserQuery extends ActiveQuery {
    /**
     * Все элементы не отправленные в корзину
     * @return static
     */
    public function published()
    {
        return $this->andWhere(['deleted_at' => null]);
    }

    /**
     * Элементы отправленные в корзину
     * @return static
     */
    public function trashed()
    {
        return $this->andWhere(['not', ['deleted_at' => null]]);
    }

    /**
     * Активные пользователи
     * @return static
     */
    public function active()
    {
        return $this->andWhere(['status' => User::STATUS_ACTIVE, 'deleted_at' => null]);
    }

    /**
     * Неактивные пользователи
     * @return static
     */
    public function inactive()
    {
        return $this->andWhere(['status' => User::STATUS_INACTIVE, 'deleted_at' => null]);
    }

    /**
     * Пользователи ожидающие активации
     * @return static
     */
    public function suspended()
    {
        return $this->andWhere(['status' => User::STATUS_SUSPENDED, 'deleted_at' => null]);
    }

    /**
     * Фильтрация по принадлежности пользователя к правилам доступа
     * Если передан массив правил - то проверка осуществляется через 'OR'
     * @param string|array $permissions
     * @return $this
     */
    public function can($permissions)
    {
        /** @var \yii\rbac\DbManager $auth */
        $auth = \Yii::$app->authManager;

        return $this->leftJoin($auth->assignmentTable . ' auth', 'auth.user_id=id')
            ->andWhere(['auth.item_name' => $permissions]);
    }
}
{'fraction_non_alphanumeric': 0.15037593984962405, 'fraction_numerical': 0.006362058993637941, 'mean_word_length': 2.5919003115264796, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 42, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7466135', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1182, 'n_words': 224}