/**
  * Display a wildcard in the back end
  * @return string
  */
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['newslist_plus'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
         return $objTemplate->parse();
     }
     $this->news_archives = $this->sortOutProtected(deserialize($this->news_archives));
     // Return if there are no archives
     if (!is_array($this->news_archives) || empty($this->news_archives)) {
         return '';
     }
     $this->news_featured = 'featured';
     // unset search string for highlighted section
     \Input::setGet('searchKeywords', null);
     $this->objArticles = NewsPlusModel::findPublishedByPids($this->news_archives, array(), array(), $this->news_featured == 'featured', $this->numberOfItems, 0);
     if ($this->objArticles === null) {
         return '';
     }
     return parent::generate();
 }
Ejemplo n.º 2
0
 public static function getAllPublishedNews($archives, $arrCategories)
 {
     $objAllArticles = NewsPlusModel::findPublishedByPids($archives, $arrCategories);
     foreach ($objAllArticles as $article) {
         $arrIds[] = $article->id;
     }
     return $arrIds;
 }
 /**
  * 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;
     }
     // show all news items, filter is active - TODO: make configurable in tl_module
     if ($this->filterActive) {
         $blnFeatured = null;
     }
     $this->Template->articles = array();
     $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList'];
     $arrIds = array();
     // get items by tag tid
     if (in_array('tags', \ModuleLoader::getActive())) {
         $arrIds = NewsPlusTagHelper::getNewsIdByTableAndTag(\Input::get("tag"));
     }
     if ($this->filterSearch) {
         $arrIds = array_merge($arrIds, $this->findNewsInSearchIndex($limit ?: 0, $offset));
     }
     // Get the total number of items
     $intTotal = NewsPlusModel::countPublishedByPids($this->news_archives, $this->news_categories, $arrIds, $blnFeatured, array(), $this->startDate, $this->endDate);
     if ($intTotal < 1 && !$this->filterSearch) {
         return;
     }
     $total = $intTotal - $offset;
     // Adjust the overall limit
     if (isset($limit)) {
         $total = min($limit, $total);
     }
     // Split the results
     if ($this->perPage > 0 && (!isset($limit) || $this->numberOfItems > $this->perPage)) {
         // Get the current page
         $id = 'page_n' . $this->id;
         $page = \Input::get($id) ?: 1;
         //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;
         }
     }
     $objArticles = NewsPlusModel::findPublishedByPids($this->news_archives, $this->news_categories, $arrIds, $blnFeatured, $limit ?: 0, $offset, array(), $this->startDate, $this->endDate);
     // store all events ids in session
     $arrUrlParam = array();
     if (\Input::get("newscategories")) {
         $arrUrlParam[] = 'newscategories=' . \Input::get("newscategories");
     }
     if (\Input::get("searchKeywords")) {
         $arrUrlParam[] = 'searchKeywords=' . \Input::get("searchKeywords");
     }
     if (\Input::get("startDate")) {
         $arrUrlParam[] = 'startDate=' . \Input::get("startDate");
     }
     if (\Input::get("endDate")) {
         $arrUrlParam[] = 'endDate=' . \Input::get("endDate");
     }
     $arrIds = NewsPlus::getAllPublishedNews($this->news_archives, $this->news_categories);
     //        // show only news by tag
     //        if(\Input::get("tag")) $arrUrlParam[] = 'tag=' . \Input::get("tag");
     //
     //        if(count($arrTagIds)) $arrIds = array_intersect($arrIds, $arrTagIds);
     $session = \Session::getInstance()->getData();
     $session[NEWSPLUS_SESSION_NEWS_IDS] = array();
     $session[NEWSPLUS_SESSION_NEWS_IDS] = $arrIds;
     \Session::getInstance()->setData($session);
     // Split the results
     if ($limit > 0 && $limit < $total) {
         // 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;
         }
         // load specific pagination template if infiniteScroll is used
         // otherwise keep standard pagination
         $objT = $this->news_useInfiniteScroll ? new \FrontendTemplate('infinite_pagination') : null;
         if (!is_null($objT)) {
             $objT->triggerText = $this->news_changeTriggerText ? $this->news_triggerText : $GLOBALS['TL_LANG']['news_plus']['loadMore'];
         }
         // Add the pagination menu
         $objPagination = new \Pagination($total, $this->perPage, \Config::get('maxPaginationLinks'), $id, $objT);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     // Add the articles
     if ($objArticles !== null) {
         $this->Template->articles = $this->parseArticles($objArticles);
     }
     $this->Template->archives = $this->news_archives;
     // add triggerText for infiniteScroll
 }