Exemplo n.º 1
0
 public function view()
 {
     $c = Page::getCurrentPage();
     parent::view();
     $this->set('im', Loader::helper('image'));
     $this->set('u', new User());
     $this->set('rssUrl', $showRss ? $controller->getRssUrl($b) : '');
     $this->set('show', $_REQUEST['show']);
     /* Set the page lists which are walk related, as they have json we need */
     switch ($this->block->getBlockFilename()) {
         case 'walkcards':
             $this->set('cards', $this->loadCards());
             break;
         case 'walk_filters':
             Loader::helper('theme');
             $cards = $this->loadCards();
             // Build a separate walk card for each date
             $walksByDate = [];
             foreach ($cards as $walk) {
                 foreach ((array) $walk->time['slots'] as $slot) {
                     $dateWalk = clone $walk;
                     $dateWalk->time['slots'] = [$slot];
                     $walksByDate[] = $dateWalk;
                 }
             }
             usort($walksByDate, function ($a, $b) {
                 $ta = $a->time['slots'][0][0];
                 $tb = $b->time['slots'][0][0];
                 return $ta < $tb ? -1 : 1;
             });
             $this->set('cards', $walksByDate);
             break;
     }
     // Set walk-filter specific filtering data
     if ($this->block->getBlockFilename() === 'walk_filters') {
         // Set up walk filters
         // Wards
         $wards = array();
         $wardObjects = $c->getAttribute('city_wards');
         if ($wardObjects !== false) {
             foreach ($wardObjects->getOptions() as $ward) {
                 $val = $ward->value;
                 $wards[] = $val;
             }
         }
         natcasesort($wards);
         // Themes
         $themes = ThemeHelper::getAll('themes');
         asort($themes);
         // Accessibility
         $accessibilities = ThemeHelper::getAll('accessibilities');
         asort($accessibilities);
         // Initiatives
         $initiatives = [];
         if (strpos($c->getCollectionPath(), 'burlington') !== false) {
             $initAttr = $c->getAttribute('walk_initiatives');
             if ($initAttr) {
                 foreach ($c->getAttribute('walk_initiatives') as $initiative) {
                     $initiatives[$initiative->ID] = $initiative->value;
                 }
                 unset($initiative);
             }
         }
         // Ward semantics
         $wardName = 'Region';
         if ($c->getCollectionName() === 'Toronto') {
             $wardName = 'Ward';
         }
         /* Set variables needed for rendering show all walks */
         $this->set('wardName', $wardName);
         $this->set('initiatives', $initiatives);
         $this->set('accessibilities', $accessibilities);
         $this->set('themes', $themes);
         $this->set('wards', $wards);
     }
 }