Esempio n. 1
0
 public function mentionHandler($post)
 {
     $usernames = MentionHelper::find($post->message);
     if (!empty($usernames)) {
         foreach ($usernames as $username) {
             /** @var UserModels $mentioned */
             $mentioned = UserModels::findByUsername($username);
             if (!$mentioned instanceof UserModels) {
                 continue;
             }
             $exist = UserMention::find()->where(['post_id' => $post->id, 'mention_user_id' => $mentioned->id, 'status' => UserMention::MENTION_STATUS_UNVIEWED])->exists();
             if ($exist) {
                 continue;
             }
             $currentUser = Yii::$app->getUser()->getIdentity();
             $model = new UserMention();
             $model->user_id = $currentUser->id;
             $model->mention_user_id = $mentioned->id;
             $model->post_id = $post->id;
             $model->topic_id = $post->topic->id;
             $model->status = UserMention::MENTION_STATUS_UNVIEWED;
             if ($mentioned->notify_mention_web == 1) {
                 $model->save();
             }
             if ($mentioned->notify_mention_email == 1) {
                 \Yii::$app->mailer->compose(['text' => 'mention'], ['model' => $model, 'topic' => $post->topic])->setFrom([Yii::$app->config->get('support_email') => Yii::$app->config->get('site_title')])->setTo([$model->mentionUser->email => $model->mentionUser->username])->setSubject('#' . $post->id . ' ' . $post->topic->subject)->send();
             }
         }
         return true;
     }
     return false;
 }
 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 = UserModels::find()->select(['id', 'username'])->where(['IN', 'id', $ids])->asArray()->all();
     if (!ArrayHelper::keyExists('0', $users, false)) {
         $users = [0 => ['id' => '0', 'username' => 'Ninguno']];
     }
     return $users;
 }
 protected function inlineUserMention($Excerpt)
 {
     if (preg_match('/\\B@([a-zA-Z][\\w-]+)/', $Excerpt['context'], $matches)) {
         /** @var UserModels $user */
         $user = UserModels::findByUsername($matches[1]);
         if ($user) {
             return ['extent' => strlen($matches[0]), 'element' => ['name' => 'a', 'text' => $matches[0], 'attributes' => ['href' => '/user/' . $user->id, 'class' => 'user-mention']]];
         } else {
             return ['markup' => $matches[0], 'extent' => strlen($matches[0])];
         }
     }
 }
Esempio n. 4
0
?>
</strong></li>
                <li><?php 
echo Yii::t('forum', 'Сообщений:');
?>
 <strong><?php 
echo $formatter->asInteger(PostModels::find()->count());
?>
</strong></li>
            </ul>
            <ul class="left">
                <li><?php 
echo Yii::t('forum', 'Количество пользователей:');
?>
 <strong><?php 
echo $formatter->asInteger(UserModels::find()->count());
?>
</strong></li>
                <li><?php 
echo Yii::t('forum', 'Последним зарегистрировался:');
?>
 <?php 
echo Html::a('X', '#');
?>
            </ul>
        </div>
        <div class="onlinelist">
            <span><strong><?php 
echo Yii::t('forum', 'Сейчас на форуме:');
?>
 </strong><?php 
 /**
  * @return ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(UserModels::className(), ['id' => 'user_id'])->inverseOf('posts');
 }
 /**
  * @return ActiveQuery
  */
 public function getMentionUser()
 {
     return $this->hasOne(UserModels::className(), ['id' => 'mention_user_id']);
 }