public function insert($data) { $coords = Geolocation::getCoordsFromText($data['map_coords']); $data['lat'] = $coords[0]; $data['lon'] = $coords[1]; $to_code = isset($data['locality_nickname']) ? $data['name'] . " " . $data['locality_nickname'] . " " . $data['locality_id'] : $data['name'] . " " . $data['locality_id']; $data['code'] = $data['code'] != '' ? $data['code'] : \Nette\Utils\Strings::webalize($to_code); $data['stroller'] = isset($data['stroller']) && $data['stroller'] == 1 ? 1 : 0; $data['visible'] = isset($data['visible']) && $data['visible'] == 1 ? 1 : 0; $data['ad_onhomepage'] = isset($data['ad_onhomepage']) && $data['ad_onhomepage'] == 1 ? 1 : 0; $data['ad'] = isset($data['ad']) && $data['ad'] == 1 ? 1 : 0; $data['show_in_catalogue'] = isset($data['show_in_catalogue']) && $data['show_in_catalogue'] == 1 ? 1 : 0; $data['show_in_calendar'] = isset($data['show_in_calendar']) && $data['show_in_calendar'] == 1 ? 1 : 0; $data['changed'] = new \Nette\DateTime(); $data['created'] = new \Nette\DateTime(); //$data['ad_shire'] = isset($data['ad_shire']) && $data['ad_shire'] == 0 ? null : $data['ad_shire']; //$data['ad_category'] = isset($data['ad_category']) && $data['ad_category'] == 0 ? null : $data['ad_category']; unset($data['categories']); parent::insert($data); }
public function createComponentDetailTabs() { if (!is_null($this->template->item->subject)) { $subject = $this->template->item->subject; $control = new TabsControl($this->context); $control->subject = $subject; $control->excludeEvent = $this->template->item->id; $control->excludePlace = $subject->id; $coords = \soundake\utils\Geolocation::getCoordsFromText($this->template->item->subject_gps); $control->lat = $coords[0]; $control->lon = $coords[1]; $control->addTab('events', true); $control->addTab('nearPlaces'); $control->addTab('nearEvents'); return $control; } return new BaseControl($this->context); }
public function update($data, $checkData = FALSE) { if ($checkData) { $data['code'] = Nette\Utils\Strings::webalize($data['subject_name'] . " " . $data['name']); } $coords = Geolocation::getCoordsFromText($data['subject_gps']); $data['lat'] = $coords[0]; $data['lon'] = $coords[1]; $data['last_edit_id'] = isset($this->context->user->id) ? $this->context->user->id : NULL; parent::update($data); }
/** * (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(); }
/** * @param $lat Real * @param $lon Real * @param int $distance Distance in meters * @param null $excludeEvent Event ID * @param null $excludePlace Venue ID * @return $this * @throws DibiException */ public function nearEvent($lat, $lon, $distance = 1000000, $excludeEvent = false, $excludePlace = false) { $key = 'events' . $lat . $lon . $distance; $cache = new Nette\Caching\Cache($this->context->cacheStorage); $ids = $cache->load($key); if ($ids === NULL) { /* Vytáhnu si všechny koordináty */ $res = dibi::select('id, subject_gps')->from('event')->where('deleted = 0')->where('visible = 1')->and('subject_gps !=""'); if ($excludeEvent) { $res->where('id != %i', $excludeEvent); } if ($excludePlace && $excludePlace != 1) { $res->where('subject_id != %i', $excludePlace); } /* Zjistím vzdálenost jednotlivých ID od středu */ $locs = array(); foreach ($res->fetchAll() as $r => $n) { $coords = Geolocation::getCoordsFromText($n['subject_gps']); $dist = Geolocation::getDistance($coords[0], $coords[1], $lat, $lon); if ($dist <= $distance && $dist >= 0) { $locs[] = array('id' => $n['id'], 'dist' => $dist); } } /* Nestliže nic nenajdu, tak vyhodím chybu. */ if (count($locs) == 0) { throw new DibiException('There is no events', 1); } foreach ($locs as $key => $row) { $ids[$key] = $row['id']; $distances[$key] = $row['dist']; } foreach ($locs as $key => $row) { $aa[$row['id']] = $row['dist']; } array_multisort($distances, SORT_ASC, $ids, SORT_ASC, $locs); //dump($lat, $lon, $locs); $cache->save($key, $ids, array(Nette\Caching\Cache::TAGS => array("events", "event", "distance"), Nette\Caching\Cache::EXPIRATION => '4 hours')); } $this->where('event_time.event_id', $ids); $this->order('FIND_IN_SET(event_time.event_id,"' . implode(",", $ids) . '")'); return $this; }