Esempio n. 1
0
 public function renderDefault()
 {
     $httpRequest = $this->context->getService('httpRequest');
     $this->template->hash = $hash = $httpRequest->getUrl()->path;
     $cache = new \Nette\Caching\Cache($this->context->getService('cacheStorage'));
     $key = $hash . "count";
     dump($key);
     $count = $cache->load($key);
     if ($count === NULL) {
         $count = $this->context->createServiceTimes()->fetchPublic()->group('event_time.event_id')->count();
         $cache->save($key, $count, array(\Nette\Caching\Cache::EXPIRE => '2 hours', \Nette\Caching\Cache::TAGS => array('events', 'event'), \Nette\Caching\Cache::SLIDING => TRUE));
     }
     $this->template->eventsCount = $count;
     $this->template->events = $this->items;
     $this->template->page = $this->page;
     // omezeni na lokalitu
     $this->template->locality = false;
     if ($this->locality) {
         $this->items->where('event_time.event.subject.locality.code', $this->locality);
         $this->template->locality = true;
     }
     // omezeni na kraje
     if ($this->shire) {
         $this->items->where('(event_time.event.shire.code = "' . $this->shire . '") OR (event_time.event.shire_id = 99)');
     }
     // omezeni na kategorie
     if ($this->category || count($this->categories) > 0) {
         $this->items->where('event_time.event:event_x_category.category_id', array_keys($this->categories));
         if (count($this->categories) == 1) {
             $this->template->category = $this->context->createServiceCategories()->get(key($this->categories));
         } else {
             $this->template->categories = $this->context->createServiceCategories();
         }
     } else {
         //$this['categories']['category']['all']->setValue(1);
     }
     // nastavi casovy ramec
     if ($this->timeframe) {
         $this->items->setTimeframe($this->timeframe);
         $this->template->timeframe = $this->timeframe;
     }
     $this->template->dates = array();
     for ($i = 2; $i < 13; $i++) {
         $ts = time() + $i * 86400;
         if (strftime("%u", $ts) == 6 || strftime("%u", $ts) == 7) {
             $this->template->dates[date("Y-m-d", $ts)]['time'] = strftime("%a %e. %m.", $ts);
             $this->template->dates[date("Y-m-d", $ts)]['day'] = 'weekend';
             //$this->template->dates[date("Y-m-d", $ts)] = strftime("%A", $ts);
         } else {
             $this->template->dates[date("Y-m-d", $ts)]['time'] = strftime("%a %e. %m.", $ts);
             $this->template->dates[date("Y-m-d", $ts)]['day'] = 'weekday';
         }
     }
     // pocet polozek s omezenimi
     $key = $hash . $this->timeframe . "/page-" . $this->pagerPlaces->getPage() . "/" . serialize($this->categories);
     $this->template->pagingHash = $key;
     dump($key);
     $count = $cache->load($key);
     if ($count === NULL) {
         $count = $this->items->count();
         $cache->save($key, $count, array(\Nette\Caching\Cache::EXPIRE => '2 hours', \Nette\Caching\Cache::TAGS => array('events', 'event'), \Nette\Caching\Cache::SLIDING => TRUE));
     }
     $this->template->count = $count;
     if ($this->page * $this->limit > $count - $this->limit) {
         //zkontroluje, zda se jedna o posledni stranku vypisu
         $this->limit = 9999;
         // nastavi limi na hodne velky cislo, aby se vypsalo vse zbyvajici
         $this->template->limit = $this->limit;
     } elseif (($this->page + 1) * $this->limit > $count - $this->limit) {
         // zkontroluje, zda se jedna o predposledni stranku vypisu
         $this->template->limit = 9998;
     } else {
         $this->template->limit = $this->limit;
     }
     //nastavi razeni
     if ($this->order == "created DESC") {
         $this->items->order($this->order);
     } else {
         // ostatni razeni se resi v modelu dle timeframe
     }
     // strankovani
     $this->pagerPlaces->itemsPerPage = $this->limit;
     $this->pagerPlaces->itemCount = $count;
     if ($this->pagerPlaces->getOffset() == 9999 && $this->pagerPlaces->getPage() > 1) {
         $this->redirect('this', array('pagingPlaces-page' => 1));
     }
     if ($this->isAjax()) {
         $this->template->newEntry = $this->items->limit($this->pagerPlaces->getLimit(), $this->pagerPlaces->getOffset());
     } else {
         $this->template->events = $this->items->limit($this->pagerPlaces->getLimit(), $this->pagerPlaces->getOffset());
     }
 }
Esempio n. 2
0
 public function handleRecentEvents()
 {
     $this->tab = 'recentEvents';
     $this->events->order('event_time.event.changed DESC')->group('event_time.event_id');
     $this->refresh();
 }