Esempio n. 1
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);
 }