/** * Generate the module */ protected function compile() { $offset = intval($this->skipFirst); $limit = null; // Maximum number of items if ($this->numberOfItems > 0) { $limit = $this->numberOfItems; } // Handle featured news if ($this->news_featured == 'featured') { $blnFeatured = true; } elseif ($this->news_featured == 'unfeatured') { $blnFeatured = false; } else { $blnFeatured = null; } $this->Template->articles = array(); $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList']; // Get the total number of items $intTotal = \NewsModel::countPublishedByPids($this->news_archives, $blnFeatured); if ($intTotal < 1) { return; } $total = $intTotal - $offset; // Split the results if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) { // Adjust the overall limit if (isset($limit)) { $total = min($limit, $total); } // Get the current page $id = 'page_n' . $this->id; $page = \Input::get($id) ?: 1; // Do not index or cache the page if the page number is outside the range if ($page < 1 || $page > max(ceil($total / $this->perPage), 1)) { global $objPage; $objPage->noSearch = 1; $objPage->cache = 0; // Send a 404 header header('HTTP/1.1 404 Not Found'); return; } // Set limit and offset $limit = $this->perPage; $offset += (max($page, 1) - 1) * $this->perPage; $skip = intval($this->skipFirst); // Overall limit if ($offset + $limit > $total + $skip) { $limit = $total + $skip - $offset; } // Add the pagination menu $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id); $this->Template->pagination = $objPagination->generate("\n "); } // Get the items if (isset($limit)) { $objArticles = \NewsModel::findPublishedByPids($this->news_archives, $blnFeatured, $limit, $offset); } else { $objArticles = \NewsModel::findPublishedByPids($this->news_archives, $blnFeatured, 0, $offset); } // Add the articles if ($objArticles !== null) { $this->Template->articles = $this->parseArticles($objArticles); } $this->Template->archives = $this->news_archives; }
/** * Count the total matching items * * @param array $newsArchives * @param boolean $blnFeatured * * @return integer */ protected function countItems($newsArchives, $blnFeatured) { // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['newsListCountItems']) && is_array($GLOBALS['TL_HOOKS']['newsListCountItems'])) { foreach ($GLOBALS['TL_HOOKS']['newsListCountItems'] as $callback) { if (($intResult = \System::importStatic($callback[0])->{$callback[1]}($newsArchives, $blnFeatured, $this)) === false) { continue; } if (is_int($intResult)) { return $intResult; } } } return \NewsModel::countPublishedByPids($newsArchives, $blnFeatured); }