public function render() { $this->template->setFile(__DIR__ . "/Flags.latte"); if ($this->type == 'subject') { $this->template->item = $this->context->createServicePlaces()->wherePrimary($this->id)->fetch(); $this['form']['subject_id']->setValue($this->id); } elseif ($this->type == 'event') { $this->template->item = $this->context->createServiceEvents()->wherePrimary($this->id)->fetch(); $this['form']['event_id']->setValue($this->id); } $this->template->hide = $this->hide; $this->template->render(); }
public function __construct(\Nette\DI\Container $context) { $this->context = $context; $this->subjects = $this->context->createServicePlaces()->fetchVisible()->limit(7)->order('RAND()'); }
/** * (non-phpDoc) * * @see Nette\Application\Control#render() */ public function render($args = NULL) { parent::render($args); $httpRequest = $this->context->getService('httpRequest'); $this->template->hash = $httpRequest->getUrl()->path; if ($this->presenter->name == 'Calendar') { $this->template->type = 'event'; } else { $this->template->type = 'place'; } if ($this->tab == '') { $this->handleEvents(); } $cache = new Cache($this->context->getService('cacheStorage'), 'tabs'); // akce na miste $key = "subject_id/" . $this->subject->id; if (in_array('events', $this->tabs) && $this->subject->id != 1) { $events = $this->context->createServiceTimes()->where('event_time.event.subject_id', $this->subject->id)->fetchVisibleEvent()->fetchCurrent()->group('event_time.event_id')->limit(5); if ($this->excludeEvent) { $events->where('event_time.event_id != ' . $this->excludeEvent); } } else { $events = new \Nette\ArrayHash(); //workaround pro prazdny eventy a nasledujici IF } $eventsCount = $cache->load($key); if ($eventsCount === NULL) { $eventsCount = $events->count(); $cache->save($key, $eventsCount, array(Cache::EXPIRE => "8 hours", Cache::SLIDING => true, Cache::TAGS => array('events', 'event'))); } $this->template->events = $events; $this->template->eventsCount = $eventsCount; if ($this->tab == 'events' && $eventsCount == 0) { if ($this->template->type == 'event') { $this->tab = "nearEvents"; } else { $this->tab = "nearPlaces"; } } if ($this->lat == "") { $this->lat = $this->subject->lat; } if ($this->lon == "") { $this->lon = $this->subject->lon; } // akce v okoli try { /* @var $nearEvents \EventsTimes */ $nearEvents = in_array('nearEvents', $this->tabs) ? $this->context->createServiceTimes()->nearEvent($this->lat, $this->lon, $this->distance, $this->excludeEvent, $this->excludePlace)->fetchCurrent()->fetchVisibleEvent()->limit(5)->group('event_time.event_id') : NULL; if ($this->tab == 'nearEvents' && $nearEvents->count() == 0) { if ($this->template->type == 'event') { $this->tab = "nearPlaces"; } else { $this->tab = "events"; } } $distances = array(); foreach ($nearEvents as $key => $time) { $gps = Geolocation::getCoordsFromText($time->event_time->event->subject_gps); $distances[$time->id] = Geolocation::getDistance($this->lat, $this->lon, $gps[0], $gps[1]); } $this->template->nearEvents = $nearEvents; $this->template->nearEventsDistances = $distances; } catch (DibiException $e) { if ($e->getCode() == 1) { // no near events $this->tab = "nearPlaces"; } else { $this->flashMessage($e->getMessage(), 'warning'); } } // mista v okoli try { $places = in_array('nearPlaces', $this->tabs) ? $this->context->createServicePlaces()->near($this->lat, $this->lon, $this->distance)->fetchVisible()->fetchUnDeleted()->limit(5)->fetchVisible() : NULL; if ($this->subject) { $places->where('subject.id != ', $this->subject->id); } if ($this->excludePlace) { $places->where('subject.id != ' . $this->excludePlace); } $distances = array(); foreach ($places as $key => $place) { $distances[$place->id] = Geolocation::getDistance($this->lat, $this->lon, $place->lat, $place->lon); } $this->template->nearPlaces = $places; $this->template->nearPlacesDistances = $distances; if ($this->tab == 'nearPlaces' && $this->template->nearPlaces->count() == 0) { if ($this->template->type == 'event') { $this->tab = "events"; } else { $this->tab = "nearEvents"; } } $this->template->subject = $this->subject; } catch (DibiException $e) { if ($e->getCode() == 1) { $this->tab = "events"; } else { $this->flashMessage($e->getMessage(), 'warning'); } } $this->template->distance = $this->distance / 1000; $this->template->active = $this->tab; $this->template->tabs = $this->tabs; $texy = new Texy(); $this->template->registerHelper('texy', callback($texy, 'process')); $helpers = $this->context->myTemplateHelpers; $this->template->registerHelperLoader(array($helpers, 'loader')); $this->template->setFile(__DIR__ . "/Tabs.latte"); $this->template->render(); }
public function __construct(\Nette\DI\Container $context) { $this->context = $context; $this->events = $this->context->createServiceTimes()->fetchPublic()->limit(6); $this->subjects = $this->context->createServicePlaces()->fetchVisible()->limit(6); }