/** * @return array */ public function to_array() { return array_merge(['author' => $this->author->to_array(), 'forum' => $this->forum->to_array(), 'close' => $this->close_id ? $this->close->to_array() : [], 'posts' => intval(ForumPost::count(['conditions' => ['theme_id = ?', $this->id]]))], parent::to_array()); }
/** * 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); }