Exemplo n.º 1
0
 /**
  * Get a list of threads for a forum category
  *
  * @param   string   $rtrn     What data to return?
  * @param   array    $filters  Filters to apply to data fetch
  * @param   boolean  $clear    Clear cached data?
  * @return  mixed
  */
 public function threads($rtrn = 'list', $filters = array(), $clear = false)
 {
     $filters['category_id'] = isset($filters['category_id']) ? $filters['category_id'] : $this->get('id');
     $filters['state'] = isset($filters['state']) ? $filters['state'] : array(self::APP_STATE_PUBLISHED, self::APP_STATE_FLAGGED);
     $filters['parent'] = isset($filters['parent']) ? $filters['parent'] : 0;
     switch (strtolower($rtrn)) {
         case 'count':
             if (!isset($this->_cache['threads_count']) || $clear) {
                 $tbl = new Tables\Post($this->_db);
                 $this->_cache['threads_count'] = $tbl->getCount($filters);
             }
             return $this->_cache['threads_count'];
             break;
         case 'first':
             return $this->threads('list', $filters)->first();
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_cache['threads'] instanceof ItemList || $clear) {
                 $tbl = new Tables\Post($this->_db);
                 if ($results = $tbl->getRecords($filters)) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Thread($result);
                         $results[$key]->set('category', $this->get('alias'));
                         $results[$key]->set('section', $this->adapter()->get('section'));
                     }
                 } else {
                     $results = array();
                 }
                 $this->_cache['threads'] = new ItemList($results);
             }
             return $this->_cache['threads'];
             break;
     }
 }
Exemplo n.º 2
0
 /**
  * Display all posts in a thread
  *
  * @return	void
  */
 public function threadTask()
 {
     // Filters
     $this->view->filters = array('limit' => Request::getState($this->_option . '.thread.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.thread.limitstart', 'limitstart', 0, 'int'), 'group' => Request::getState($this->_option . '.thread.group', 'group', -1, 'int'), 'section_id' => Request::getState($this->_option . '.thread.section_id', 'section_id', -1, 'int'), 'category_id' => Request::getState($this->_option . '.thread.category_id', 'category_id', -1, 'int'), 'thread' => Request::getState($this->_option . '.thread.thread', 'thread', 0, 'int'), 'sort' => Request::getState($this->_option . '.thread.sort', 'filter_order', 'c.id'), 'sort_Dir' => Request::getState($this->_option . '.thread.sortdir', 'filter_order_Dir', 'ASC'), 'sticky' => false);
     // Get the section
     $this->view->section = new Section($this->database);
     $this->view->section->load($this->view->filters['section_id']);
     if (!$this->view->section->id) {
         // No section? Load a default blank section
         $this->view->section->loadDefault();
     }
     // Get the category
     $this->view->category = new Category($this->database);
     $this->view->category->load($this->view->filters['category_id']);
     if (!$this->view->category->id) {
         // No category? Load a default blank catgory
         $this->view->category->loadDefault();
     }
     $this->view->cateories = array();
     $categories = $this->view->category->getRecords();
     if ($categories) {
         foreach ($categories as $c) {
             if (!isset($this->view->cateories[$c->section_id])) {
                 $this->view->cateories[$c->section_id] = array();
             }
             $this->view->cateories[$c->section_id][] = $c;
             asort($this->view->cateories[$c->section_id]);
         }
     }
     // Get the sections for this group
     $this->view->sections = array();
     $sections = $this->view->section->getRecords();
     if ($sections) {
         foreach ($sections as $s) {
             $ky = $s->scope . ' (' . $s->scope_id . ')';
             if ($s->scope == 'site') {
                 $ky = '[ site ]';
             }
             if (!isset($this->view->sections[$ky])) {
                 $this->view->sections[$ky] = array();
             }
             $s->categories = isset($this->view->cateories[$s->id]) ? $this->view->cateories[$s->id] : array();
             //$this->view->category->getRecords(array('section_id'=>$s->id));
             $this->view->sections[$ky][] = $s;
             asort($this->view->sections[$ky]);
         }
     } else {
         $default = new Section($this->database);
         $default->loadDefault($this->view->section->scope, $this->view->section->scope_id);
         $this->view->sections[] = $default;
     }
     asort($this->view->sections);
     $model = new Post($this->database);
     // Get a record count
     $this->view->total = $model->getCount($this->view->filters);
     // Get records
     $this->view->results = $model->getRecords($this->view->filters);
     $model->load($this->view->filters['thread']);
     $this->view->thread = $model;
     // Output the HTML
     $this->view->display();
 }