예제 #1
0
파일: Control.php 프로젝트: Max201/nanocore
 public function subjects(Request $request, $matches)
 {
     $title = $this->lang->translate('forum.list');
     // Delete topic
     if ($request->get('delete')) {
         $forum = \Forum::find_by_id(intval($request->get('delete')));
         if ($forum) {
             $forum->delete();
             $this->view->assign('message', $this->lang->translate('form.deleted'));
         }
     }
     // Filter
     $filter = ['conditions' => ['forum_id < 1']];
     if ($request->get('author')) {
         $author = \User::find($request->get('author'));
         if ($author) {
             $filter['conditions'] = ['author_id = ?', $author->id];
         }
     }
     // Parent
     if ($request->get('parent')) {
         $parent = \Forum::find($request->get('parent'));
         if ($parent) {
             $filter['conditions'] = ['forum_id = ?', $parent->id];
         }
     }
     $filter['order'] = 'id DESC';
     if ($request->order) {
         $filter['order'] = $request->order;
     }
     /** @var Listing $paginator */
     $paginator = NCService::load('Paginator.Listing', [$request->page, \Forum::count('all')]);
     $filter = array_merge($filter, $paginator->limit());
     // Filter topics
     $forums = \Forum::as_array(\Forum::all($filter));
     return $this->view->render('forum/list.twig', ['title' => $title, 'forums_list' => $forums, 'listing' => $paginator->pages(), 'page' => $paginator->cur_page]);
 }
예제 #2
0
 /**
  * Список форумов
  */
 public function index()
 {
     $forums = Forum::all(['conditions' => ['parent_id = ?', 0], 'order' => 'sort', 'include' => ['topic_count', 'children' => ['post_count', 'topic_count'], 'topic_last' => ['post_last' => ['user']]]]);
     App::view('forums.index', compact('forums'));
 }