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);
 }
 /**
  * testItLogsToOutputIfAnExceptionIsThrownDuringIndexing
  */
 public function testItLogsToOutputIfAnExceptionIsThrownDuringIndexing()
 {
     $this->container->expects($this->at(0))->method('get')->with($this->equalTo('sulu_event.event_manager'))->will($this->returnValue($this->eventManager));
     $this->container->expects($this->at(1))->method('get')->with($this->equalTo('massive_search.search_manager'))->will($this->returnValue($this->searchManager));
     $eventMock = $this->getMock(Event::class);
     $eventMock->expects($this->any())->method('getTitle')->will($this->returnValue('FooBarEvent'));
     $eventMocks = array($eventMock);
     $this->eventManager->expects($this->once())->method('findAll')->will($this->returnValue($eventMocks));
     $this->searchManager->expects($this->exactly(1))->method('index')->with($eventMock)->willThrowException(new \Exception('Something went wrong!'));
     $this->output->expects($this->at(1))->method('writeln')->with($this->stringContains('(path: FooBarEvent: Something went wrong!'));
     $reindexCommand = new ReindexCommand();
     $reindexCommand->setContainer($this->container);
     $reindexCommand->execute($this->input, $this->output);
 }
 /**
  *
  * @param Request $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function detailAction(Request $request)
 {
     $event = $this->eventManager->findByIdAndLocale($request->get('id'), 'de', true);
     if (!$event) {
         throw new NotFoundHttpException(404);
     }
     $filter['lat'] = $event->getLatitude();
     $filter['long'] = $event->getLongitude();
     $filter['area'] = 100;
     $requestData = $this->requestAnalyzerResolver->resolve($this->requestAnalyzer);
     $resolverData = $this->parameterResolver->resolve(array(), $this->requestAnalyzer, null, false);
     $response = $this->templating->renderResponse('SuluEventBundle:templates:detail.html.twig', array_merge(array('event' => $event, 'urls' => isset($resolverData['urls']) ? $resolverData['urls'] : array()), $requestData));
     $response->setMaxAge($this->cacheMaxAge);
     $response->setSharedMaxAge($this->cacheSharedMaxAge);
     return $response;
 }