Пример #1
0
    /**
     * Parses phpDoc comment.
     * @param  string
     * @return array
     */
    private static function parseComment($comment)
    {
        static $tokens = array('true' => TRUE, 'false' => FALSE, 'null' => NULL, '' => TRUE);
        $res = array();
        $comment = preg_replace('#^\\s*\\*\\s?#ms', '', trim($comment, '/*'));
        $parts = preg_split('#^\\s*(?=@' . self::RE_IDENTIFIER . ')#m', $comment, 2);
        $description = trim($parts[0]);
        if ($description !== '') {
            $res['description'] = array($description);
        }
        $matches = XApp_Utils_Strings::matchAll(isset($parts[1]) ? $parts[1] : '', '~
				(?<=\\s|^)@(' . self::RE_IDENTIFIER . ')[ \\t]*      ##  annotation
				(
					\\((?>' . self::RE_STRING . '|[^\'")@]+)+\\)|  ##  (value)
					[^(@\\r\\n][^@\\r\\n]*|)                     ##  value
			~xi');
        foreach ($matches as $match) {
            list(, $name, $value) = $match;
            if (substr($value, 0, 1) === '(') {
                $items = array();
                $key = '';
                $val = TRUE;
                $value[0] = ',';
                while ($m = Strings::match($value, '#\\s*,\\s*(?>(' . self::RE_IDENTIFIER . ')\\s*=\\s*)?(' . self::RE_STRING . '|[^\'"),\\s][^\'"),]*)#A')) {
                    $value = substr($value, strlen($m[0]));
                    list(, $key, $val) = $m;
                    $val = rtrim($val);
                    if ($val[0] === "'" || $val[0] === '"') {
                        $val = substr($val, 1, -1);
                    } elseif (is_numeric($val)) {
                        $val = 1 * $val;
                    } else {
                        $lval = strtolower($val);
                        $val = array_key_exists($lval, $tokens) ? $tokens[$lval] : $val;
                    }
                    if ($key === '') {
                        $items[] = $val;
                    } else {
                        $items[$key] = $val;
                    }
                }
                $value = count($items) < 2 && $key === '' ? $val : $items;
            } else {
                $value = trim($value);
                if (is_numeric($value)) {
                    $value = 1 * $value;
                } else {
                    $lval = strtolower($value);
                    $value = array_key_exists($lval, $tokens) ? $tokens[$lval] : $value;
                }
            }
            $class = $name . 'Annotation';
            if (class_exists($class)) {
                $res[$name][] = new $class(is_array($value) ? $value : array('value' => $value));
            } else {
                $res[$name][] = is_array($value) ? Nette\ArrayHash::from($value) : $value;
            }
        }
        return $res;
    }
Пример #2
0
 /**
  * (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();
 }