Exemple #1
0
 /**
  * Refreshes the forum's meta infos
  *
  * @return void
  */
 public function refresh()
 {
     if (!$this->forum_id) {
         return;
         // Root forums (level = 0) do not need refreshes
     }
     $forumThread = ForumThread::whereForumId($this->id)->orderBy('created_at', 'desc')->first();
     $threadsCount = ForumThread::whereForumId($this->id)->count();
     $childThreadsCount = 0;
     foreach ($this->forums as $forum) {
         $childThreadsCount += $forum->threads_count;
     }
     $this->latest_thread_id = null;
     if ($forumThread) {
         $this->latest_thread_id = $forumThread->id;
     }
     $this->threads_count = $threadsCount + $childThreadsCount;
     $this->forceSave();
     /*
      * Every forum has to call the refresh method of its parent forum,
      * because their meta infos all depend on their child forums.
      * Therefore we do a cascading method call.
      */
     if ($this->forum_id) {
         $this->forum->refresh();
     }
 }