/** * Shows latest posts by category * * @param int $categoryId Category Id * @param string $slug Category Slug * @param int $offset Posts offset */ public function viewAction($categoryId, $slug, $offset = 0) { if (!($category = Categories::findFirstById($categoryId))) { $this->flashSession->notice("The category doesn't exist"); $this->logger->error("The category doesn't exist"); $this->response->redirect(); return; } $this->tag->setTitle("Discussions in category {$category->name}"); $readposts = []; if ($userId = $this->session->get('identity')) { $ur = TopicTracking::findFirst(['user_id= ?0', 'bind' => [$userId]]); $readposts = $ur ? explode(',', $ur->topic_id) : []; } /** * @var \Phalcon\Mvc\Model\Query\BuilderInterface $itemBuilder * @var \Phalcon\Mvc\Model\Query\BuilderInterface $totalBuilder */ list($itemBuilder, $totalBuilder) = $this->prepareQueries(); $totalBuilder->where('p.categories_id = ?0 AND p.deleted = 0'); $posts = $itemBuilder->where('p.categories_id = ?0 AND p.deleted = 0')->orderBy('p.created_at DESC')->offset((int) $offset)->getQuery()->execute([$categoryId]); if (!count($posts)) { $this->flashSession->notice('There are no posts in category: ' . $category->name); $this->response->redirect(); return; } $totalPosts = $totalBuilder->getQuery()->setUniqueRow(true)->execute([$categoryId]); $this->view->setVars(['readposts' => $readposts, 'posts' => $posts, 'totalPosts' => $totalPosts, 'currentOrder' => null, 'offset' => (int) $offset, 'paginatorUri' => "category/{$category->id}/{$category->slug}", 'logged' => $userId]); }
/** * Check whether the user can have the badge * * @param Users $user * @return boolean */ public function canHave(Users $user) { $ids = []; $categories = $this->getExpertQuery($user)->execute([$user->id]); foreach ($categories as $categoryRow) { $category = Categories::findFirstById($categoryRow->categories_id); if ($category) { $ids[] = $category; } } return $ids; }
/** * Shows latest posts by category */ public function categoryAction($categoryId, $slug, $offset = 0) { $this->assets->addCss('css/index.css'); $category = Categories::findFirstById($categoryId); if (!$category) { $this->flashSession->notice('The category doesn\'t exist'); return $this->response->redirect(); } $this->tag->setTitle($category->name); /** @var \Phalcon\Mvc\Model\Query\BuilderInterface $itemBuilder */ /** @var \Phalcon\Mvc\Model\Query\BuilderInterface $totalBuilder */ list($itemBuilder, $totalBuilder) = $this->prepareQueries(); $totalBuilder->where('p.categories_id = ?0 AND p.deleted = 0'); $posts = $itemBuilder->where('p.categories_id = ?0 AND p.deleted = 0')->orderBy('p.created_at DESC')->offset((int) $offset)->getQuery()->execute(array($categoryId)); if (!count($posts)) { $this->flashSession->notice('There are no posts in category: ' . $category->name); return $this->response->redirect(); } $totalPosts = $totalBuilder->getQuery()->setUniqueRow(true)->execute(array($categoryId)); $this->view->posts = $posts; $this->view->totalPosts = $totalPosts; $this->view->currentOrder = null; $this->view->offset = (int) $offset; $this->view->paginatorUri = 'category/' . $category->id . '/' . $category->slug; }
/** * Shows latest posts by category */ public function categoryAction($categoryId, $slug, $offset = 0) { $this->tag->setTitle('Discussions'); $userId = $this->session->get('identity'); if ($userId != '') { $ur = TopicTracking::findFirst("user_id='" . $userId . "'"); $this->view->readposts = explode(",", $ur->topic_id); } $category = Categories::findFirstById($categoryId); if (!$category) { $this->flashSession->notice('The category doesn\'t exist'); return $this->response->redirect(); } /** @var \Phalcon\Mvc\Model\Query\BuilderInterface $itemBuilder */ /** @var \Phalcon\Mvc\Model\Query\BuilderInterface $totalBuilder */ list($itemBuilder, $totalBuilder) = $this->prepareQueries(); $totalBuilder->where('p.categories_id = ?0 AND p.deleted = 0'); $posts = $itemBuilder->where('p.categories_id = ?0 AND p.deleted = 0')->orderBy('p.created_at DESC')->offset((int) $offset)->getQuery()->execute(array($categoryId)); if (!count($posts)) { $this->flashSession->notice('There are no posts in category: ' . $category->name); return $this->response->redirect(); } $totalPosts = $totalBuilder->getQuery()->setUniqueRow(true)->execute(array($categoryId)); $this->view->posts = $posts; $this->view->totalPosts = $totalPosts; $this->view->currentOrder = null; $this->view->offset = (int) $offset; $this->view->paginatorUri = 'category/' . $category->id . '/' . $category->slug; $this->view->logged = $this->session->get('identity'); }