src/Rhyme/WMassArtsHub/Module/Event/EventList.php line 245

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (C) 2021 Rhyme Digital, LLC.
  4.  *
  5.  * @link       https://rhyme.digital
  6.  * @license    http://www.gnu.org/licenses/lgpl-3.0.html LGPL
  7.  */
  8. namespace Rhyme\WMassArtsHub\Module\Event;
  9. use Contao\Config;
  10. use Contao\CoreBundle\Image\Studio\LegacyFigureBuilderTrait;
  11. use Contao\Date;
  12. use Contao\FilesModel;
  13. use Contao\Input;
  14. use Contao\PageModel;
  15. use Contao\Pagination;
  16. use Contao\Environment;
  17. use Contao\ModuleEventlist;
  18. use Contao\CoreBundle\Exception\PageNotFoundException;
  19. use Contao\StringUtil;
  20. use Haste\Generator\RowClass;
  21. use Rhyme\WMassArtsHub\Model\Event;
  22. /**
  23.  * Class Reader
  24.  * @package Rhyme\WMassArtsHub\Module\Event
  25.  */
  26. class EventList extends ModuleEventlist
  27. {
  28.     /**
  29.      * THIS IS THE SAME AS THE PARENT ASIDE FROM THE HIGHLIGHTED BLOCK BELOW
  30.      * Generate the module
  31.      */
  32.     protected function compile()
  33.     {
  34.         /** @var PageModel $objPage */
  35.         global $objPage;
  36.         $blnClearInput false;
  37.         $intYear Input::get('year');
  38.         $intMonth Input::get('month');
  39.         $intDay Input::get('day');
  40.         // Handle featured events
  41.         $blnFeatured null;
  42.         if ($this->cal_featured == 'featured')
  43.         {
  44.             $blnFeatured true;
  45.         }
  46.         elseif ($this->cal_featured == 'unfeatured')
  47.         {
  48.             $blnFeatured false;
  49.         }
  50.         // Jump to the current period
  51.         if (!isset($_GET['year']) && !isset($_GET['month']) && !isset($_GET['day']))
  52.         {
  53.             switch ($this->cal_format)
  54.             {
  55.                 case 'cal_year':
  56.                     $intYear date('Y');
  57.                     break;
  58.                 case 'cal_month':
  59.                     $intMonth date('Ym');
  60.                     break;
  61.                 case 'cal_day':
  62.                     $intDay date('Ymd');
  63.                     break;
  64.             }
  65.             $blnClearInput true;
  66.         }
  67.         $blnDynamicFormat = (!$this->cal_ignoreDynamic && \in_array($this->cal_format, array('cal_day''cal_month''cal_year')));
  68.         // Create the date object
  69.         try
  70.         {
  71.             if ($blnDynamicFormat && $intYear)
  72.             {
  73.                 $this->Date = new Date($intYear'Y');
  74.                 $this->cal_format 'cal_year';
  75.                 $this->headline .= ' ' date('Y'$this->Date->tstamp);
  76.             }
  77.             elseif ($blnDynamicFormat && $intMonth)
  78.             {
  79.                 $this->Date = new Date($intMonth'Ym');
  80.                 $this->cal_format 'cal_month';
  81.                 $this->headline .= ' ' Date::parse('F Y'$this->Date->tstamp);
  82.             }
  83.             elseif ($blnDynamicFormat && $intDay)
  84.             {
  85.                 $this->Date = new Date($intDay'Ymd');
  86.                 $this->cal_format 'cal_day';
  87.                 $this->headline .= ' ' Date::parse($objPage->dateFormat$this->Date->tstamp);
  88.             }
  89.             else
  90.             {
  91.                 $this->Date = new Date();
  92.             }
  93.         }
  94.         catch (\OutOfBoundsException $e)
  95.         {
  96.             throw new PageNotFoundException('Page not found: ' Environment::get('uri'));
  97.         }
  98.         list($intStart$intEnd$strEmpty) = $this->getDatesFromFormat($this->Date$this->cal_format);
  99.         // Get all events
  100.         $arrAllEvents $this->getAllEvents($this->cal_calendar$intStart$intEnd$blnFeatured);
  101.         $sort = ($this->cal_order == 'descending') ? 'krsort' 'ksort';
  102.         // Sort the days
  103.         $sort($arrAllEvents);
  104.         // Sort the events
  105.         foreach (array_keys($arrAllEvents) as $key)
  106.         {
  107.             $sort($arrAllEvents[$key]);
  108.         }
  109.         $arrEvents = array();
  110.         // Remove events outside the scope
  111.         foreach ($arrAllEvents as $key=>$days)
  112.         {
  113.             foreach ($days as $day=>$events)
  114.             {
  115.                 // Skip events before the start day if the "shortened view" option is not set.
  116.                 // Events after the end day are filtered in the Events::addEvent() method (see #8782).
  117.                 if (!$this->cal_noSpan && $day $intStart)
  118.                 {
  119.                     continue;
  120.                 }
  121.                 foreach ($events as $event)
  122.                 {
  123.                     // Use repeatEnd if > 0 (see #8447)
  124.                     if ($event['startTime'] > $intEnd || ($event['repeatEnd'] ?: $event['endTime']) < $intStart)
  125.                     {
  126.                         continue;
  127.                     }
  128.                     // Hide running events
  129.                     if ($this->cal_hideRunning && $event['begin'] < $intStart)
  130.                     {
  131.                         continue;
  132.                     }
  133.                     // Skip occurrences in the past
  134.                     if ($event['repeatEnd'] && $event['end'] < $intStart)
  135.                     {
  136.                         continue;
  137.                     }
  138.                     // Hide running non-recurring events (see #30)
  139.                     if ($this->cal_hideRunning && !$event['recurring'] && $event['startTime'] < time())
  140.                     {
  141.                         continue;
  142.                     }
  143.                     $event['firstDay'] = $GLOBALS['TL_LANG']['DAYS'][date('w'$day)];
  144.                     $event['firstDate'] = Date::parse($objPage->dateFormat$day);
  145.                     $arrEvents[] = $event;
  146.                 }
  147.             }
  148.         }
  149.         unset($arrAllEvents);
  150.         $total = \count($arrEvents);
  151.         $limit $total;
  152.         $offset 0;
  153.         // Overall limit
  154.         if ($this->cal_limit 0)
  155.         {
  156.             $total min($this->cal_limit$total);
  157.             $limit $total;
  158.         }
  159.         // Pagination
  160.         if ($this->perPage 0)
  161.         {
  162.             $id 'page_e' $this->id;
  163.             $page Input::get($id) ?? 1;
  164.             // Do not index or cache the page if the page number is outside the range
  165.             if ($page || $page max(ceil($total/$this->perPage), 1))
  166.             {
  167.                 throw new PageNotFoundException('Page not found: ' Environment::get('uri'));
  168.             }
  169.             $offset = ($page 1) * $this->perPage;
  170.             $limit min($this->perPage $offset$total);
  171.             $objPagination = new Pagination($total$this->perPageConfig::get('maxPaginationLinks'), $id);
  172.             $this->Template->pagination $objPagination->generate("\n  ");
  173.         }
  174.         $strMonth '';
  175.         $strDate '';
  176.         $arrParsedEvents = [];
  177.         $dayCount 0;
  178.         $eventCount 0;
  179.         $headerCount 0;
  180.         $uuids = array();
  181.         for ($i=$offset$i<$limit$i++)
  182.         {
  183.             if ($arrEvents[$i]['addImage'] && $arrEvents[$i]['singleSRC'])
  184.             {
  185.                 $uuids[] = $arrEvents[$i]['singleSRC'];
  186.             }
  187.         }
  188.         // Preload all images in one query so they are loaded into the model registry
  189.         FilesModel::findMultipleByUuids($uuids);
  190.         // Parse events
  191.         for ($i=$offset$i<$limit$i++)
  192.         {
  193.             //**********************************************************CUSTOM************************//
  194.             /** @var Event|null $model */
  195.             $model Event::findByPk($arrEvents[$i]['id']);
  196.             if(null !== $model) {
  197.                 $arrCSS StringUtil::deserialize($model->cssIDtrue);
  198.                 $arrParsedEvents[] = [
  199.                     'model' => $model,
  200.                     'class' => trim('event ' $arrCSS[1]),
  201.                     'content' => $model->generate($this->getModel())
  202.                 ];
  203.             }
  204.             //**********************************************************CUSTOM************************//
  205.             ++$eventCount;
  206.             ++$headerCount;
  207.         }
  208.         //**********************************************************CUSTOM************************//
  209.         // No events found
  210.         if (empty($arrParsedEvents))
  211.         {
  212.             $this->Template->isEmpty true;
  213.         }
  214.         RowClass::withKey('class')->addCount('event_')->addEvenOdd('event_')->addFirstLast('event_')->applyTo($arrParsedEvents);
  215.         // See #3672
  216.         $this->Template->headline $this->headline;
  217.         $this->Template->events $arrParsedEvents;
  218.         $this->Template->eventCount $eventCount;
  219.         //**********************************************************CUSTOM************************//
  220.         // Clear the $_GET array (see #2445)
  221.         if ($blnClearInput)
  222.         {
  223.             Input::setGet('year'null);
  224.             Input::setGet('month'null);
  225.             Input::setGet('day'null);
  226.         }
  227.     }
  228. }