protected function compile()
	{
		/** @var PageModel $objPage */
		global $objPage;

		$limit = null;
		$offset = 0;
		$intBegin = 0;
		$intEnd = 0;

		$intYear = Input::get('year');
		$intMonth = Input::get('month');
		$intDay = Input::get('day');

		// Jump to the current period
		if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day']) && $this->news_jumpToCurrent != 'all_items')
		{
			switch ($this->news_format)
			{
				case 'news_year':
					$intYear = date('Y');
					break;

				default:
				case 'news_month':
					$intMonth = date('Ym');
					break;

				case 'news_day':
					$intDay = date('Ymd');
					break;
			}
		}

		// Create the date object
		try
		{
			if ($intYear)
			{
				$strDate = $intYear;
				$objDate = new Date($strDate, 'Y');
				$intBegin = $objDate->yearBegin;
				$intEnd = $objDate->yearEnd;
				$this->headline .= ' ' . date('Y', $objDate->tstamp);
			}
			elseif ($intMonth)
			{
				$strDate = $intMonth;
				$objDate = new Date($strDate, 'Ym');
				$intBegin = $objDate->monthBegin;
				$intEnd = $objDate->monthEnd;
				$this->headline .= ' ' . Date::parse('F Y', $objDate->tstamp);
			}
			elseif ($intDay)
			{
				$strDate = $intDay;
				$objDate = new Date($strDate, 'Ymd');
				$intBegin = $objDate->dayBegin;
				$intEnd = $objDate->dayEnd;
				$this->headline .= ' ' . Date::parse($objPage->dateFormat, $objDate->tstamp);
			}
			elseif ($this->news_jumpToCurrent == 'all_items')
			{
				$intBegin = 0; // 1970-01-01 00:00:00
				$intEnd = 2145913200; // 2038-01-01 00:00:00
			}
		}
		catch (\OutOfBoundsException $e)
		{
			throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
		}

		$this->Template->articles = array();

		// Split the result
		if ($this->perPage > 0)
		{
			// Get the total number of items
			$intTotal = NewsModel::countPublishedFromToByPids($intBegin, $intEnd, $this->news_archives);

			if ($intTotal > 0)
			{
				$total = $intTotal;

				// Get the current page
				$id = 'page_a' . $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))
				{
					throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
				}

				// Set limit and offset
				$limit = $this->perPage;
				$offset = (max($page, 1) - 1) * $this->perPage;

				// Add the pagination menu
				$objPagination = new Pagination($total, $this->perPage, Config::get('maxPaginationLinks'), $id);
				$this->Template->pagination = $objPagination->generate("\n  ");
			}
		}

		// Determine sorting
		$t = NewsModel::getTable();
		$arrOptions = array();

		switch ($this->news_order)
		{
			case 'order_headline_asc':
				$arrOptions['order'] = "$t.headline";
				break;

			case 'order_headline_desc':
				$arrOptions['order'] = "$t.headline DESC";
				break;

			case 'order_random':
				$arrOptions['order'] = "RAND()";
				break;

			case 'order_date_asc':
				$arrOptions['order'] = "$t.date";
				break;

			default:
				$arrOptions['order'] = "$t.date DESC";
		}

		// Get the news items
		if (isset($limit))
		{
			$objArticles = NewsModel::findPublishedFromToByPids($intBegin, $intEnd, $this->news_archives, $limit, $offset, $arrOptions);
		}
		else
		{
			$objArticles = NewsModel::findPublishedFromToByPids($intBegin, $intEnd, $this->news_archives, 0, 0, $arrOptions);
		}

		// Add the articles
		if ($objArticles !== null)
		{
			$this->Template->articles = $this->parseArticles($objArticles);
		}

		$this->Template->headline = trim($this->headline);
		$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
		$this->Template->empty = $GLOBALS['TL_LANG']['MSC']['empty'];
	}
protected function compile()
	{
		
		global $objPage;

		$limit = null;
		$offset = 0;
		$intBegin = 0;
		$intEnd = 0;

		$intYear = Input::get('year');
		$intMonth = Input::get('month');
		$intDay = Input::get('day');

		
		if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day']) && $this->news_jumpToCurrent != 'all_items')
		{
			switch ($this->news_format)
			{
				case 'news_year':
					$intYear = date('Y');
					break;

				default:
				case 'news_month':
					$intMonth = date('Ym');
					break;

				case 'news_day':
					$intDay = date('Ymd');
					break;
			}
		}

		
		try
		{
			if ($intYear)
			{
				$strDate = $intYear;
				$objDate = new Date($strDate, 'Y');
				$intBegin = $objDate->yearBegin;
				$intEnd = $objDate->yearEnd;
				$this->headline .= ' ' . date('Y', $objDate->tstamp);
			}
			elseif ($intMonth)
			{
				$strDate = $intMonth;
				$objDate = new Date($strDate, 'Ym');
				$intBegin = $objDate->monthBegin;
				$intEnd = $objDate->monthEnd;
				$this->headline .= ' ' . Date::parse('F Y', $objDate->tstamp);
			}
			elseif ($intDay)
			{
				$strDate = $intDay;
				$objDate = new Date($strDate, 'Ymd');
				$intBegin = $objDate->dayBegin;
				$intEnd = $objDate->dayEnd;
				$this->headline .= ' ' . Date::parse($objPage->dateFormat, $objDate->tstamp);
			}
			elseif ($this->news_jumpToCurrent == 'all_items')
			{
				$intBegin = 0; 
				$intEnd = 2145913200; 
			}
		}
		catch (\OutOfBoundsException $e)
		{
			throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
		}

		$this->Template->articles = array();

		
		if ($this->perPage > 0)
		{
			
			$intTotal = NewsModel::countPublishedFromToByPids($intBegin, $intEnd, $this->news_archives);

			if ($intTotal > 0)
			{
				$total = $intTotal;

				
				$id = 'page_a' . $this->id;
				$page = Input::get($id) ?? 1;

				
				if ($page < 1 || $page > max(ceil($total/$this->perPage), 1))
				{
					throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
				}

				
				$limit = $this->perPage;
				$offset = (max($page, 1) - 1) * $this->perPage;

				
				$objPagination = new Pagination($total, $this->perPage, Config::get('maxPaginationLinks'), $id);
				$this->Template->pagination = $objPagination->generate("\n  ");
			}
		}

		
		$t = NewsModel::getTable();
		$arrOptions = array();

		switch ($this->news_order)
		{
			case 'order_headline_asc':
				$arrOptions['order'] = "$t.headline";
				break;

			case 'order_headline_desc':
				$arrOptions['order'] = "$t.headline DESC";
				break;

			case 'order_random':
				$arrOptions['order'] = "RAND()";
				break;

			case 'order_date_asc':
				$arrOptions['order'] = "$t.date";
				break;

			default:
				$arrOptions['order'] = "$t.date DESC";
		}

		
		if (isset($limit))
		{
			$objArticles = NewsModel::findPublishedFromToByPids($intBegin, $intEnd, $this->news_archives, $limit, $offset, $arrOptions);
		}
		else
		{
			$objArticles = NewsModel::findPublishedFromToByPids($intBegin, $intEnd, $this->news_archives, 0, 0, $arrOptions);
		}

		
		if ($objArticles !== null)
		{
			$this->Template->articles = $this->parseArticles($objArticles);
		}

		$this->Template->headline = trim($this->headline);
		$this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
		$this->Template->empty = $GLOBALS['TL_LANG']['MSC']['empty'];
	}
protected function compile ( ) { /** @var PageModel $objPage */ global $ objPage ; $ limit = null ; $ offset = 0 ; $ intBegin = 0 ; $ intEnd = 0 ; $ intYear = Input :: get ( 'year' ) ; $ intMonth = Input :: get ( 'month' ) ; $ intDay = Input :: get ( 'day' ) ; // Jump to the current period if ( ! isset ( $ _GET [ 'year' ] ) && ! isset ( $ _GET [ 'month' ] ) && ! isset ( $ _GET [ 'day' ] ) && $ this -> news_jumpToCurrent != 'all_items' ) { switch ( $ this -> news_format ) { case 'news_year' : $ intYear = date ( 'Y' ) ; break ; default : case 'news_month' : $ intMonth = date ( 'Ym' ) ; break ; case 'news_day' : $ intDay = date ( 'Ymd' ) ; break ; } } // Create the date object try { if ( $ intYear ) { $ strDate = $ intYear ; $ objDate = new Date ( $ strDate , 'Y' ) ; $ intBegin = $ objDate -> yearBegin ; $ intEnd = $ objDate -> yearEnd ; $ this -> headline .= ' ' . date ( 'Y' , $ objDate -> tstamp ) ; } elseif ( $ intMonth ) { $ strDate = $ intMonth ; $ objDate = new Date ( $ strDate , 'Ym' ) ; $ intBegin = $ objDate -> monthBegin ; $ intEnd = $ objDate -> monthEnd ; $ this -> headline .= ' ' . Date :: parse ( 'F Y' , $ objDate -> tstamp ) ; } elseif ( $ intDay ) { $ strDate = $ intDay ; $ objDate = new Date ( $ strDate , 'Ymd' ) ; $ intBegin = $ objDate -> dayBegin ; $ intEnd = $ objDate -> dayEnd ; $ this -> headline .= ' ' . Date :: parse ( $ objPage -> dateFormat , $ objDate -> tstamp ) ; } elseif ( $ this -> news_jumpToCurrent == 'all_items' ) { $ intBegin = 0 ; // 1970-01-01 00:00:00 $ intEnd = 2145913200 ; // 2038-01-01 00:00:00 } } catch ( \ OutOfBoundsException $ e ) { throw new PageNotFoundException ( 'Page not found: ' . Environment :: get ( 'uri' ) ) ; } $ this -> Template -> articles = array ( ) ; // Split the result if ( $ this -> perPage > 0 ) { // Get the total number of items $ intTotal = NewsModel :: countPublishedFromToByPids ( $ intBegin , $ intEnd , $ this -> news_archives ) ; if ( $ intTotal > 0 ) { $ total = $ intTotal ; // Get the current page $ id = 'page_a' . $ 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 ) ) { throw new PageNotFoundException ( 'Page not found: ' . Environment :: get ( 'uri' ) ) ; } // Set limit and offset $ limit = $ this -> perPage ; $ offset = ( max ( $ page , 1 ) - 1 ) * $ this -> perPage ; // Add the pagination menu $ objPagination = new Pagination ( $ total , $ this -> perPage , Config :: get ( 'maxPaginationLinks' ) , $ id ) ; $ this -> Template -> pagination = $ objPagination -> generate ( "\n  " ) ; } } // Determine sorting $ t = NewsModel :: getTable ( ) ; $ arrOptions = array ( ) ; switch ( $ this -> news_order ) { case 'order_headline_asc' : $ arrOptions [ 'order' ] = "$t.headline" ; break ; case 'order_headline_desc' : $ arrOptions [ 'order' ] = "$t.headline DESC" ; break ; case 'order_random' : $ arrOptions [ 'order' ] = "RAND()" ; break ; case 'order_date_asc' : $ arrOptions [ 'order' ] = "$t.date" ; break ; default : $ arrOptions [ 'order' ] = "$t.date DESC" ; } // Get the news items if ( isset ( $ limit ) ) { $ objArticles = NewsModel :: findPublishedFromToByPids ( $ intBegin , $ intEnd , $ this -> news_archives , $ limit , $ offset , $ arrOptions ) ; } else { $ objArticles = NewsModel :: findPublishedFromToByPids ( $ intBegin , $ intEnd , $ this -> news_archives , 0 , 0 , $ arrOptions ) ; } // Add the articles if ( $ objArticles !== null ) { $ this -> Template -> articles = $ this -> parseArticles ( $ objArticles ) ; } $ this -> Template -> headline = trim ( $ this -> headline ) ; $ this -> Template -> back = $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'goBack' ] ; $ this -> Template -> empty = $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'empty' ] ; }
Generate the module
Generate the module