Example #1
0
 /**
  * Find posts
  */
 public function actionFind($categoryId = null)
 {
     $data = [];
     $category = new Category();
     if (isset($categoryId) && (!is_numeric($categoryId) || ($category = Category::get($categoryId)) === null)) {
         $this->page404();
         return;
     } else {
         $data['category'] = $category;
         $data['subs'] = $category->children();
     }
     $page = $this->getPage("page");
     $pageSize = $this->getPageSize("pagesize", 10);
     $count = 0;
     $cat = new Category();
     if ($categoryId === null) {
         $count = $cat->getActivePostsCount();
         $data['posts'] = $cat->getActivePosts(null, ($page - 1) * $pageSize, $pageSize);
     } else {
         $count = $cat->getActivePostsCount($categoryId);
         $data['posts'] = $cat->getActivePosts($categoryId, ($page - 1) * $pageSize, $pageSize);
     }
     if ($count > $pageSize) {
         $url = RHtml::siteUrl("post/find" . ($categoryId != null ? "/" . $categoryId : ""));
         $pager = new RPager("page", $count, $pageSize, $url, $page);
         $data['pager'] = $pager->showPager();
     }
     $this->setHeaderTitle("Find posts");
     $this->addCss("/public/css/post.css");
     $this->addCss("/public/css/group.css");
     $this->render('find', $data, false);
 }