/** * Display a list of blog entries * * @return void */ public function displayTask() { $this->view->filters = array('pageid' => Request::getState($this->_option . '.' . $this->_controller . '.pageid', 'pageid', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int')); $this->view->entry = new Page($this->view->filters['pageid']); // Instantiate our HelloEntry object $obj = new Tables\Comment($this->database); // Get records $rows = $obj->find('list', $this->view->filters); $levellimit = $this->view->filters['limit'] == 0 ? 500 : $this->view->filters['limit']; $list = array(); $children = array(); if ($rows) { // First pass - collect children foreach ($rows as $v) { //$v->name = ''; $pt = $v->parent; $list = @$children[$pt] ? $children[$pt] : array(); array_push($list, $v); $children[$pt] = $list; } // Second pass - get an indent list of the items $list = $this->treeRecurse(0, '', array(), $children, max(0, $levellimit - 1)); } // Get record count $this->view->total = count($list); $this->view->rows = array_slice($list, $this->view->filters['start'], $this->view->filters['limit']); // Set any errors foreach ($this->getErrors() as $error) { $this->view->setError($error); } // Output the HTML $this->view->display(); }
/** * Get a count or list of comments * * @param string $rtrn Data format to return * @param array $filters Filters to apply to data fetch * @param boolean $clear Clear cached data? * @return mixed Returns an integer or array depending upon format chosen */ public function comments($rtrn = 'list', $filters = array(), $clear = false) { if (!isset($filters['pageid'])) { $filters['pageid'] = $this->get('id'); } if (!isset($filters['parent'])) { $filters['parent'] = '0'; } if (!isset($filters['status'])) { $filters['status'] = array(self::APP_STATE_PUBLISHED, self::APP_STATE_FLAGGED); } switch (strtolower($rtrn)) { case 'count': if (!is_numeric($this->_comments_count) || $clear) { $tbl = new Tables\Comment($this->_db); $this->_comments_count = $tbl->find('count', $filters); } return $this->_comments_count; break; case 'list': case 'results': default: if (!$this->_comments instanceof ItemList || $clear) { if (!isset($filters['parent'])) { $filters['parent'] = 0; } $tbl = new Tables\Comment($this->_db); if ($results = $tbl->find('list', $filters)) { foreach ($results as $key => $result) { $results[$key] = new Comment($result); } } else { $results = array(); } $this->_comments = new ItemList($results); } return $this->_comments; break; } }