Exemplo n.º 1
0
 /**
  * @param HitEvent $event
  */
 public function onHit(HitEvent $event)
 {
     if ($event->getMetadata()->reflection->getName() !== 'Sulu\\Bundle\\EventBundle\\Entity\\Event') {
         return;
     }
     $locale = $this->requestAnalyzer->getCurrentLocalization()->getLocalization();
     $document = $event->getHit()->getDocument();
     $eventApiEntity = $this->eventManager->findByIdAndLocale($document->getId(), $locale);
     if (!$eventApiEntity) {
         return;
     }
     $startDate = $eventApiEntity->getStartDate();
     $endDate = $eventApiEntity->getEndDate();
     $categories = $eventApiEntity->getCategories();
     $categoryTitles = array();
     foreach ($categories as $category) {
         $categoryTitles[] = $category->getName();
     }
     $startDateField = new Field('start_date', $startDate->format('c'), Field::TYPE_STRING);
     $document->addField($startDateField);
     if ($endDate) {
         $endDateField = new Field('end_date', $endDate->format('c'), Field::TYPE_STRING);
         $document->addField($endDateField);
     }
     $categoryTitleField = new Field('category_title', implode(', ', $categoryTitles), Field::TYPE_STRING);
     $document->addField($categoryTitleField);
     $url = $this->router->generate('sulu_events.detail', array('id' => $eventApiEntity->getId(), 'slug' => $eventApiEntity->getSlug()));
     $document->setUrl($url);
 }
Exemplo n.º 2
0
 /**
  * Prefix url of document with current resourcelocator prefix.
  *
  * @param HitEvent $event
  */
 public function onHit(HitEvent $event)
 {
     if (false === $event->getMetadata()->reflection->isSubclassOf('Sulu\\Bundle\\ContentBundle\\Document\\BasePageDocument')) {
         return;
     }
     $document = $event->getHit()->getDocument();
     $url = sprintf('%s/%s', rtrim($this->requestAnalyzer->getResourceLocatorPrefix(), '/'), ltrim($document->getUrl(), '/'));
     $document->setUrl($url);
 }