Пример #1
0
 public static function getActiveUsers()
 {
     $array_ids = static::find()->select(['user_id'])->where('user_id > 0')->asArray()->all();
     $ids = \yii\helpers\ArrayHelper::getColumn($array_ids, 'user_id');
     $users = User::find()->select(['id', 'username'])->where(['IN', 'id', $ids])->asArray()->all();
     return $users;
 }
 /**
  * Send emails to reviewers with contributions to need review.
  * If reviewer has no any reviews - does not send it.
  * Collect contributions by project IDs.
  */
 public function actionSendReviewerEmail()
 {
     // get projects
     /* @var $projects Project */
     $projects = Project::find()->all();
     // get active reviewers
     /* @var $reviewers User[] */
     $reviewers = User::find(['status' => User::STATUS_ACTIVE])->indexBy('id')->all();
     // collect contributions to need review for each project
     foreach ($reviewers as $reviewer) {
         $this->logInfo('Collect reviews for: ', $reviewer->getContributorName());
         $contributionsByProjects = [];
         foreach ($projects as $project) {
             $aggregator = new ContributionAggregator(['projectId' => $project->id, 'reviewerId' => $reviewer->id, 'type' => ContributionAggregator::TYPE_NOT_FINISHED]);
             $statistic = $aggregator->aggregateByContributor();
             if (!empty($statistic)) {
                 $contributionsByProjects[$project->id] = ['project' => $project, 'statistic' => $statistic];
             }
         }
         $this->logInfo('Total projects to review: ', count($contributionsByProjects));
         if (!empty($contributionsByProjects)) {
             // send email to reviewer
             $result = $this->sendEmailToReviewer($reviewer, $contributionsByProjects);
             $this->logInfo('Send e-mail to ' . $reviewer->getContributorEmail() . ': ', $result ? 'done' : 'error');
         }
     }
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
Пример #4
0
 /**
  * @name 角色用户分配列表
  */
 public function actionUser($id)
 {
     $auth = Yii::$app->authManager;
     $users = User::find()->where(['status' => 10])->andWhere('id>1')->orderBy('username')->all();
     $users_info = [];
     foreach ($users as $k => $v) {
         $pin = strtoupper(substr(Pinyin::pinyin($v['username']), 0, 1));
         $users_info[$pin][$v['id']] = ['username' => $v['username'], 'pinyin' => Pinyin::pinyin($v['username']), 'is_sel' => $auth->getAssignment($id, $v['id']) ? 1 : 0];
     }
     $keys = array_keys($users_info);
     return $this->render('user', ['user' => $users_info, 'keys' => $keys, 'role_name' => $id]);
 }
Пример #5
0
 /**
  * Retrieve contributor model by vcs type, contributorName, contributorEmail.
  *
  * If contributor registered at the system, returns it, if else - returns UnregisteredContributor model.
  *
  * @see UserAccount
  * @see User
  *
  * @param string $vcsType VCS type (git, hg, etc.)
  * @param string $contributorName VCS contributor name (e.g. commiter name)
  * @param string $contributorEmail VCS contributor e-mail (e.g. commiter e-mail, if exists)
  *
  * @return ContributorInterface Returns registered user, or UnregisteredContributor model.
  */
 public function getContributor($vcsType, $contributorName, $contributorEmail = null)
 {
     /* @var $cached ContributorInterface[] */
     static $cached = [];
     $cacheKey = $vcsType . '_' . $contributorName . '_' . $contributorEmail;
     if (!isset($cached[$cacheKey])) {
         /* @var $res ActiveQuery */
         $res = User::find()->joinWith('accounts')->orWhere([UserAccount::tableName() . '.username' => $contributorName, UserAccount::tableName() . '.type' => $vcsType]);
         if (!empty($contributorEmail)) {
             $res->orWhere([User::tableName() . '.email' => $contributorEmail]);
         }
         $res->groupBy(User::tableName() . '.id');
         $cached[$cacheKey] = $res->one();
         if (!$cached[$cacheKey]) {
             // contributor not found
             // set as unregistered
             $cached[$cacheKey] = new UnregisteredContributor(['contributorName' => $contributorName, 'contributorEmail' => $contributorEmail]);
         }
     }
     return $cached[$cacheKey];
 }
Пример #6
0
 /**
  * @return string
  */
 public function actionMention()
 {
     if (Yii::$app->getRequest()->getIsAjax()) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $id = substr(Yii::$app->getRequest()->get('id'), 1);
         $query = Yii::$app->getRequest()->get('query');
         if (is_numeric($id)) {
             $posts = Post::find()->with(['user' => function ($query) {
                 /** @var \yii\db\Query $query */
                 $query->andWhere(['not in', 'id', Yii::$app->getUser()->getId()]);
             }])->where(['topic_id' => $id])->orderBy(['created_at' => SORT_DESC])->asArray()->all();
             $users = ArrayHelper::getColumn($posts, 'user');
             $usernames = array_unique(ArrayHelper::getColumn($users, 'username'));
             $usernames = array_diff($usernames, ['']);
         } else {
             $usernames = User::find()->where(['like', 'username', $query . '%', false])->orderBy(['number_posts' => SORT_DESC])->limit(5)->asArray()->all();
             $usernames = ArrayHelper::getColumn($usernames, 'username');
         }
         $usernames = array_values($usernames);
         return $usernames;
     }
     throw new NotFoundHttpException();
 }
Пример #7
0
 /**
  * Filters for userlist page.
  * @param $params array
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     // create ActiveQuery
     $query = User::find()->select(['id', 'username', 'number_posts', 'created_at']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->pagination = new Pagination(['forcePageParam' => false, 'pageSizeLimit' => false, 'defaultPageSize' => 50]);
     if (!($this->load($params) && $this->validate())) {
         $query->addOrderBy(['created_at' => SORT_ASC]);
         return $dataProvider;
     }
     $query->andFilterWhere(['like', 'username', $this->username]);
     $colomn = 'created_at';
     if (strcasecmp($this->sort_by, 'username') == 0) {
         $colomn = 'username';
     } elseif (strcasecmp($this->sort_by, 'number_posts') == 0) {
         $colomn = 'number_posts';
     }
     if (strcasecmp($this->sort_dir, 'ASC') == 0) {
         $query->addOrderBy([$colomn => SORT_ASC]);
     } elseif (strcasecmp($this->sort_dir, 'DESC') == 0) {
         $query->addOrderBy([$colomn => SORT_DESC]);
     }
     return $dataProvider;
 }
Пример #8
0
 /**
  * Retreive user model by user VCS bind account (UserAccount model).
  *
  * @see UserAccount
  * @see User
  *
  * @param string $vcsType VCS type (git, hg, etc.)
  * @param string $contributorName VCS contributor name (e.g. commiter name)
  * @param string $contributorEmail VCS contributor e-mail (e.g. commiter e-mail, if exists)
  *
  * @return User|null Returns user model if it exists
  */
 public function getUserByUsername($vcsType, $contributorName, $contributorEmail = null)
 {
     /* @var $cached User[] */
     static $cached = [];
     $cacheKey = $vcsType . '_' . $contributorName . '_' . $contributorEmail;
     if (!isset($cached[$cacheKey])) {
         /* @var $res ActiveQuery */
         $res = User::find()->joinWith('accounts')->orWhere([UserAccount::tableName() . '.username' => $contributorName, UserAccount::tableName() . '.type' => $vcsType]);
         if (!empty($contributorEmail)) {
             $res->orWhere([User::tableName() . '.email' => $contributorEmail]);
         }
         $res->groupBy(User::tableName() . '.id');
         $cached[$cacheKey] = $res->one();
     }
     return $cached[$cacheKey];
 }
Пример #9
0
?>
    <div class="statistic">
        <div class="clearfix">
            <ul class="right">
                <li>Тем: <strong><?php 
echo $formatter->asInteger(\topic\models\Topic::countAll());
?>
</strong></li>
                <li>Сообщений: <strong><?php 
echo $formatter->asInteger(\post\models\Post::find()->count());
?>
</strong></li>
            </ul>
            <ul class="left">
                <li>Количество пользователей: <strong><?php 
echo $formatter->asInteger(User::find()->count());
?>
</strong></li>
                <li>Последним зарегистрировался: <a href="">X</a></li>
            </ul>
        </div>
        <div class="onlinelist">
            <span><strong>Сейчас на форуме: </strong> <?php 
echo UserOnline::countGuests();
?>
 гостей, <?php 
echo UserOnline::countUsers();
?>
 пользователей, <?php 
echo implode(', ', \yii\helpers\ArrayHelper::getColumn(UserOnline::getActiveUsers(), 'username'));
?>