public static function updateLastData($threadId) { $attributes = []; $attributes['posts'] = new Expression("[[posts]]+:bp0", [":bp0" => 1]); $attributes['last_user_id'] = YiiForum::getIdentity()->id; $attributes['last_user_name'] = YiiForum::getIdentity()->username; $attributes['last_modify_time'] = TTimeHelper::getCurrentTime(); Thread::updateAll($attributes, ['id' => intval($threadId)]); }
public static function updateLastData($boardId, $threadId, $threadTitle, $isThread = True) { $attributes = []; $attributes['modify_time'] = TTimeHelper::getCurrentTime(); if ($isThread) { $attributes['threads'] = new Expression("[[threads]]+:bp0", [":bp0" => 1]); } else { $attributes['posts'] = new Expression("[[posts]]+:bp0", [":bp0" => 1]); } $attributes['user_id'] = YiiForum::getIdentity()->id; $attributes['user_name'] = YiiForum::getIdentity()->username; $attributes['thread_id'] = $threadId; $attributes['thread_title'] = $threadTitle; YiiForum::info($attributes); Board::updateAll($attributes, ['id' => intval($boardId)]); }
<tr style="height: 80px;"> <td class="post-left-column body"> <div> <span></span> </div> </td> <td class="post-right-column body content"> <div> <?php echo $row['body']; ?> </div> </td> </tr> <?php if ($row['user_id'] == YiiForum::getIdentity()->id) { ?> <tr> <td class="post-left-column footer"> </td> <td class="post-right-column footer"> <div class="dashed-border-t"> <span>回复</span> <span> <?php if ($floor == 1) { echo Html::a('编辑', ['edit-thread', 'id' => $thread['id'], 'boardid' => $currentBoard['id']]) . '</span><span>'; echo Html::a('删除', ['delete', 'id' => $thread->id, 'boardid' => $currentBoard['id']], ['data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); } else { echo Html::a('编辑', ['edit-post', 'id' => $row['id'], 'boardid' => $currentBoard['id']]); }
public function actionNewPost() { if (!YiiForum::checkAuth('post_add')) { return $this->noPermission(); } YiiForum::checkIsGuest(); $post = new Post(); $threadId = YiiForum::getGetValue('threadid'); $data = YiiForum::getPostValue('Post'); if ($data == null) { $thread = Thread::findOne(['id' => $threadId]); $locals = []; $locals['thread'] = $thread; $locals['currentBoard'] = $this->getBoard($thread['board_id']); $locals['model'] = $post; return $this->render('new-post', $locals); } $boardId = $data['board_id']; $threadId = $data['thread_id']; $threadTitle = $data['thread_title']; $post->thread_id = $threadId; $post->user_id = YiiForum::getIdentity()->id; $post->user_name = YiiForum::getIdentity()->username; $post->title = isset($data['title']) ? $data['title'] : ''; $post->body = $data['body']; $post->create_time = TTimeHelper::getCurrentTime(); $post->modify_time = TTimeHelper::getCurrentTime(); $post->supports = 0; $post->againsts = 0; $post->floor = 0; $post->note = ''; if ($post->save()) { Thread::updateLastData($threadId); Board::updateLastData($boardId, $threadId, $threadTitle, false); } return $this->redirect(['view', 'id' => $threadId]); }