Example #1
0
 /**
  * @param Post $post
  * @return boolean
  */
 public function mentionHandler($post)
 {
     $usernames = MentionHelper::find($post->message);
     if (!empty($usernames)) {
         foreach ($usernames as $username) {
             /** @var User $mentioned */
             $mentioned = User::findByUsername($username);
             if (!$mentioned instanceof User) {
                 continue;
             }
             $exist = UserMention::find()->where(['post_id' => $post->id, 'mention_user_id' => $mentioned->id, 'status' => UserMention::MENTION_SATUS_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_SATUS_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;
 }
Example #2
0
 /**
  * @param $id
  * @return string
  */
 public function actionView($id)
 {
     /** @var Post $post */
     $post = Post::findOne(['id' => $id]);
     /** @var Topic $topic */
     $topic = Topic::find()->where(['id' => $post->topic_id])->one();
     if (!$topic) {
         throw new NotFoundHttpException();
     }
     $topic->updateCounters(['number_views' => 1]);
     $topic->save();
     if (!Yii::$app->getUser()->getIsGuest()) {
         $userMentions = UserMention::findAll(['post_id' => $id, 'mention_user_id' => Yii::$app->getUser()->getId(), 'status' => UserMention::MENTION_SATUS_UNVIEWED]);
         foreach ($userMentions as $userMention) {
             $userMention->status = UserMention::MENTION_SATUS_VIEWED;
             $userMention->save();
         }
     }
     $dataProvider = Post::getDataProviderByTopic($topic->id);
     $dataProvider->pagination->route = '/topic/default/view';
     $dataProvider->pagination->params = ['id' => $topic->id, 'page' => $this->getPostPage($post)];
     $posts = $dataProvider->getModels();
     $model = new PostForm();
     return $this->render('/default/view', ['dataProvider' => $dataProvider, 'model' => $model, 'topic' => $topic, 'posts' => $posts]);
 }
 /**
  * @param $id topic identificator.
  * @return string
  */
 public function actionView($id)
 {
     /** @var Topic $topic */
     $topic = Topic::find()->where(['id' => $id])->one();
     if (!$topic) {
         throw new NotFoundHttpException();
     }
     $topic->updateCounters(['number_views' => 1]);
     $topic->save();
     $dataProvider = Post::getDataProviderByTopic($topic->id);
     $posts = $dataProvider->getModels();
     if (!Yii::$app->getUser()->getIsGuest()) {
         $userMentions = UserMention::findAll(['topic_id' => $id, 'mention_user_id' => Yii::$app->getUser()->getId(), 'status' => UserMention::MENTION_SATUS_UNVIEWED]);
         // user mention update
         foreach ($userMentions as $userMention) {
             $userMention->status = UserMention::MENTION_SATUS_VIEWED;
             $userMention->save();
         }
         $model = new PostForm();
         if ($model->load(Yii::$app->getRequest()->post()) && $model->create($topic)) {
             $this->redirect(['/topic/post/view', 'id' => $model->post->id, '#' => 'p' . $model->post->id]);
         }
         return $this->render('view', ['dataProvider' => $dataProvider, 'model' => $model, 'topic' => $topic, 'posts' => $posts]);
     } else {
         return $this->render('view', ['dataProvider' => $dataProvider, 'topic' => $topic, 'posts' => $posts]);
     }
 }
 public function actionView()
 {
     if (!Yii::$app->getUser()->getIsGuest()) {
         $user = \Yii::$app->getUser()->getIdentity();
         $userMentions = UserMention::find()->with('topic')->where(['mention_user_id' => $user->id])->andWhere(['status' => UserMention::MENTION_SATUS_UNVIEWED])->all();
         return $this->render('view', ['userMentions' => $userMentions, 'user' => $user]);
     }
     throw new NotFoundHttpException();
 }
 /**
  * @param integer $id
  * @param integer $page
  * @return string
  */
 public function actionView($id, $page = 1)
 {
     /** @var Topic $topic */
     $topic = Topic::find()->with('tags')->where(['id' => $id])->one();
     if (!$topic) {
         throw new NotFoundHttpException();
     }
     $topic->updateCounters(['number_views' => 1]);
     $topic->save();
     if (!Yii::$app->getUser()->getIsGuest()) {
         UserMention::markAsViewedByTopicID($id);
     }
     $dataProvider = Post::getDataProvider(['topic_id' => $topic->id, 'page' => $page]);
     $model = new CreatePostForm();
     if ($model->load(Yii::$app->getRequest()->post()) && $model->validate()) {
         if ($model->create($topic->id)) {
             $this->redirect('');
         }
     }
     return $this->render('view', ['dataProvider' => $dataProvider, 'model' => $model]);
 }
Example #6
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     if (strtolower($this->position) == 'header') {
         if (!Yii::$app->user->isGuest) {
             $user = Yii::$app->user->identity;
             $avatar = \cebe\gravatar\Gravatar::widget(['email' => $user->email, 'options' => ['alt' => '', 'class' => 'avatar', 'width' => 24, 'height' => 24], 'defaultImage' => 'retro', 'size' => 24]);
             $items[] = ['label' => $avatar . Yii::$app->user->identity->username, 'url' => ['/user/default/view', 'id' => Yii::$app->user->id], 'options' => ['class' => 'navbar-nav-profile']];
         }
         if (Yii::$app->user->isGuest) {
             $items[] = ['label' => 'Регистрация', 'url' => ['/user/identity/registration']];
             $items[] = ['label' => 'Вход', 'url' => ['/user/identity/login']];
         } else {
             $items[] = ['label' => 'Выход', 'url' => ['/user/identity/logout']];
         }
         return Menu::widget(['items' => $items, 'encodeLabels' => false, 'options' => ['class' => 'navbar-nav']]);
     } elseif (strtolower($this->position) == 'sub_header') {
         $items[] = ['label' => 'Последние темы', 'url' => ['/topic/default/list']];
         if (!Yii::$app->getUser()->getIsGuest()) {
             $id = Yii::$app->getUser()->getIdentity()->id;
             $notifications = UserMention::countByUser($id);
             if ($notifications > 0) {
                 $items[] = ['label' => 'Уведомления <span class="counter">' . $notifications . '</span>', 'url' => ['/notify/default/view']];
             } else {
                 $items[] = ['label' => 'Уведомления', 'url' => ['/notify/default/view']];
             }
         }
         $items[] = ['label' => 'Пользователи', 'url' => ['/user/default/list']];
         if (!Yii::$app->getUser()->getIsGuest()) {
             $items[] = ['label' => 'Создать тему', 'url' => ['/topic/default/create']];
         }
         return Menu::widget(['items' => $items, 'encodeLabels' => false, 'options' => ['class' => 'sub-navbar-nav']]);
     } elseif (strtolower($this->position) == 'footer') {
         $items = [['label' => 'Правила пользования', 'url' => ['/frontend/default/terms']], ['label' => '&bull;'], ['label' => 'Обратная связь', 'url' => ['/frontend/default/feedback']]];
         return Menu::widget(['encodeLabels' => false, 'items' => $items]);
     }
     return null;
 }