/** * 与我相关 */ public function actionMention() { $notices = Notice::getAllNotice(); $user = $this->findUserModel(); Yii::$app->userData->updateKey('unread_comment_count', $user->id, 0, false); return $this->render('mention', ['notices' => $notices, 'count' => $this->getMessageCount(), 'user' => $user]); }
/** * @param boolean $insert * @param array $changedAttributes * @return bool */ public function afterSave($insert, $changedAttributes) { $this->PostCuntPlus(); $connection = Yii::$app->db; //查询帖子信息 $thread = $connection->createCommand('SELECT id, user_id, title FROM {{%forum_thread}} WHERE id=' . $this->thread_id)->queryOne(); //更新帖子最后回复时间 $connection->createCommand('UPDATE {{%forum_thread}} SET updated_at=:time WHERE id=:id')->bindValues([':time' => time(), ':id' => $thread['id']])->execute(); //给用户发回复或者@通知,回复自己的不通知 if (Yii::$app->user->id != $thread['user_id']) { Notice::sendNotice('NEW_COMMENT', ['title' => $thread['title']], $this->content, ['/forum/thread/view', 'id' => $thread['id']], $thread['user_id'], $this->user_id); //添加未读消息数 Yii::$app->userData->updateKey('unread_notice_count', $thread['user_id']); } //回复中提到其他人,通知其他人 if (strstr($this->content, '@')) { preg_match_all('/@(.*?)\\s/', $this->content, $match); if (isset($match[1]) && count($match[1]) > 0) { $notice_user = array_unique($match[1]); foreach ($notice_user as $v) { $toUserId = $connection->createCommand('SELECT id FROM {{%user}} WHERE username=:name')->bindValue(':name', $v)->queryScalar(); if ($toUserId == $thread['user_id'] || $toUserId == Yii::$app->user->id || empty($toUserId)) { continue; } Notice::sendNotice('MENTION_ME', ['title' => $thread['title']], $this->content, ['/forum/thread/view', 'id' => $thread['id']], $toUserId, $this->user_id); } } } return parent::afterSave($insert, $changedAttributes); }
/** * @param boolean $insert * @param array $changedAttributes * @return bool */ public function afterSave($insert, $changedAttributes) { $connection = Yii::$app->db; $thread = $connection->createCommand('SELECT * FROM {{%forum_thread}} WHERE id=' . $this->thread_id)->queryOne(); //给用户发回复或者@通知,回复自己的不通知 if (Yii::$app->user->id != $thread['user_id']) { Notice::sendNotice('COMMENT', ['title' => $thread['title']], $this->content, ['/forum/thread/view', 'id' => $thread['id']], $thread['user_id'], $this->user_id); } //回复中提到其他人,通知其他人 if (strstr($this->content, '@')) { preg_match_all('/@(.*?)\\s/', $this->content, $match); if (isset($match[1]) && count($match[1]) > 0) { $notice_user = array_unique($match[1]); foreach ($notice_user as $v) { $toUserId = $connection->createCommand('SELECT id FROM {{%user}} WHERE username=:name')->bindValue(':name', $v)->queryScalar(); if ($toUserId == $thread['user_id'] || $toUserId == Yii::$app->user->id || empty($toUserId)) { continue; } Notice::sendNotice('MENTION_ME', ['title' => $thread['title']], $this->content, ['/forum/thread/view', 'id' => $thread['id']], $toUserId, $this->user_id); } } } return parent::afterSave($insert, $changedAttributes); }