Exemplo n.º 1
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     $this->import('Sermoner');
     $offset = intval($this->skipFirst);
     $limit = null;
     $this->Template->sermons = array();
     // Maximum number of items
     if ($this->numberOfItems > 0) {
         $limit = $this->numberOfItems;
     }
     // Get the total number of items
     $intTotal = \SermonerItemsModel::countPublishedByPids($this->serm_sermonarchive);
     if ($intTotal < 1) {
         $this->Template = new \FrontendTemplate('mod_sermonlist_empty');
         $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList'];
         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, $GLOBALS['TL_CONFIG']['maxPaginationLinks'], $id);
         $this->Template->pagination = $objPagination->generate("\n  ");
     }
     //Configuration
     $objConfig = new \stdClass();
     $objConfig->feedHref = sprintf("%s/share/%s.xml", \Environment::get('path'), \SermonFeedModel::findByPk($this->linkedRssFeed)->alias);
     $objConfig->feedIcon = $this->iconSRC;
     $objConfig->template = $this->serm_template;
     // Get the items
     if (isset($limit)) {
         $objSermons = \SermonerItemsModel::findPublishedByPids($this->serm_sermonarchive, $limit, $offset);
     } else {
         $objSermons = \SermonerItemsModel::findPublishedByPids($this->serm_sermonarchive, 0, $offset);
     }
     // No items found
     if ($objSermons === null) {
         $this->Template = new \FrontendTemplate('mod_sermonlist_empty');
         $this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList'];
     } else {
         $this->Template->sermons = $this->Sermoner->parseSermons($objSermons, $objConfig);
     }
 }
Exemplo n.º 2
0
 /**
  * Return the names of the existing feeds so they are not removed
  * @return array
  */
 public function purgeOldFeeds()
 {
     $arrFeeds = array();
     $objFeeds = \SermonFeedModel::findAll();
     if ($objFeeds !== null) {
         while ($objFeeds->next()) {
             $arrFeeds[] = $objFeeds->alias ?: 'sermon' . $objFeeds->id;
         }
     }
     return $arrFeeds;
 }