public function actionIndex($id, $page = 1)
 {
     $page = $page < 1 ? 1 : $page;
     $this->assign("subcategory", ForumSubcategory::findByPk($id));
     $this->assign('threads', ForumThread::findAllForSubcategory($id, $page));
     $this->assign('currentPage', $page);
     $this->assign('categories', ForumCategory::findAllBySection($this->sectionId, true));
 }
 /**
  * @return $this
  */
 public function checkLastActivity()
 {
     $thread = ForumThread::findByAttributes(['subcategory_id' => $this->id, 'deleted' => 0], ['order' => 'IF(last_reply_date > create_time & last_reply_date > edit_time, last_reply_date,
         (IF(edit_time > create_time & edit_time > last_reply_date, edit_time, create_time))) DESC']);
     if (!$thread) {
         $this->last_active_thread_id = 0;
         $this->last_active_user_id = 0;
         $this->last_activity_time = null;
         return $this;
     }
     $this->last_active_thread_id = $thread->id;
     if ($thread->last_reply_date >= max($thread->create_time, $thread->edit_time)) {
         $this->last_activity = 'reply';
         $this->last_active_user_id = $thread->last_reply_user_id;
     } elseif ($thread->edit_time >= max($thread->create_time, $thread->last_reply_date)) {
         $this->last_activity = 'edit';
         $this->last_active_user_id = $thread->edit_user_id;
     } else {
         $this->last_activity = 'create';
         $this->last_active_user_id = $thread->user_id;
     }
     $this->last_activity_time = max($thread->create_time, $thread->edit_time, $thread->last_reply_date);
     return $this;
 }
Beispiel #3
0
 public function actionRecent()
 {
     $this->assign("threads", ForumThread::findRecent($this->sectionId));
 }
Beispiel #4
0
 public function actionIndex($id, $currentPage = 1)
 {
     $this->assign('user', ForumUser2Section::findByAttributes(['user_id' => $id, 'section_id' => $this->sectionId]));
     $this->assign("threads", ForumThread::findAllByUser($id, $this->sectionId, $currentPage));
 }
Beispiel #5
0
 /**
  * It will save thread info(update with last reply info) + subcategory info
  * @param int $sectionId
  * @param int $level
  * @param int $userId
  * @param int $userGroupID
  * @param int $time
  * @return bool
  */
 public function saveReply($sectionId, $level = 1, $userId = null, $userGroupID = null, $time = null)
 {
     $this->user_id = is_null($userId) ? WebApp::get()->user()->id : $userId;
     $this->time = date('Y-m-d H:i:s', $time ?: time());
     $this->section_id = $sectionId;
     $this->score = $this->edited = $this->edit_user_id = $this->deleted = $this->deleted_user_id = 0;
     $this->user_group_id = $userGroupID ?: UserAccess::get()->getUserGroup($sectionId, true);
     if (!$this->save()) {
         return false;
     }
     $thread = ForumThread::findByPk($this->thread_id);
     $thread->replies = ($firstLevelReplies = ForumReply::countByAttributes(['thread_id' => $this->thread_id])) + ForumReplySecond::countByAttributes(['thread_id' => $this->thread_id]) + ForumReplyThird::countByAttributes(['thread_id' => $this->thread_id]) + ForumReplyForth::countByAttributes(['thread_id' => $this->thread_id]) + ForumReplyFifth::countByAttributes(['thread_id' => $this->thread_id]) + ForumReplySixth::countByAttributes(['thread_id' => $this->thread_id]) + ForumReplySeventh::countByAttributes(['thread_id' => $this->thread_id]) + ForumReplyEighth::countByAttributes(['thread_id' => $this->thread_id]) + ForumReplyNth::countByAttributes(['thread_id' => $this->thread_id]);
     $thread->first_level_replies = $firstLevelReplies;
     $thread->last_reply_id = $this->id;
     $thread->last_reply_user_id = $this->user_id;
     $thread->last_reply_level = $level;
     $thread->last_reply_date = $this->time;
     $thread->save(false);
     $thread->subcategory->last_active_thread_id = $thread->id;
     $thread->subcategory->last_activity_time = $this->time;
     $thread->subcategory->last_activity = 'reply';
     $thread->subcategory->last_active_user_id = $this->user_id;
     $thread->subcategory->recalculateNumbers()->save();
     return true;
 }