Beispiel #1
0
 /**
  * Delete child forums & topics
  */
 public function dispose()
 {
     // Drop subjects
     $subjects = Forum::find('all', ['conditions' => ['forum_id = ?', $this->id]]);
     foreach ($subjects as $sbj) {
         $sbj->delete();
     }
     // Drop themes
     $themes = ForumTheme::find('all', ['conditions' => ['forum_id = ?', $this->id]]);
     foreach ($themes as $thm) {
         $thm->delete();
     }
 }
Beispiel #2
0
 /**
  * @param $postId
  * @param \User $author
  * @return bool|void
  */
 public static function minus($postId, \User $author)
 {
     $forum = \ForumTheme::find(intval($postId));
     if (!$forum) {
         return false;
     }
     if ($forum->author_id == $author->id) {
         return $forum->author_id;
     }
     if ($forum->author->rate(-1)) {
         return $forum->author_id;
     }
     return false;
 }
Beispiel #3
0
 /**
  * Comments list
  *
  * @param $request
  * @param $matches
  * @return mixed
  */
 public function posts_list($request, $matches)
 {
     $topic = $this->view->get('topic', $matches->get('topic'));
     $topic = $topic instanceof \ForumTheme ? $topic : \ForumTheme::find($topic);
     $filter = ['conditions' => ['theme_id = ?', $topic->id], 'order' => 'created_at DESC'];
     /** @var Listing $paginator */
     $paginator = NCService::load('Paginator.Listing', [$request->page, \ForumPost::count($filter)]);
     $filter = array_merge($filter, $paginator->limit());
     // Comments
     $comments = \ForumPost::find('all', $filter);
     $comments = \ForumPost::as_array($comments);
     // Context
     $context = ['topic' => $topic, 'posts_list' => $comments, 'page' => $paginator->cur_page, 'listing' => $paginator->pages()];
     // Add comment status
     if ($status = $this->view->get('status', false)) {
         $context['status'] = $status;
     }
     // Build response
     if ($request->get('type', 'html') == 'json') {
         unset($context['listing']);
         $context['pages'] = $paginator->pages;
         $context['rows'] = $paginator->num_rows;
         return static::json_response($context);
     }
     return $this->view->render('forum/posts.twig', $context);
 }