Пример #1
0
 /**
  * Adds the image to the search document.
  *
  * @param PreIndexEvent $event
  */
 public function handlePreIndex(PreIndexEvent $event)
 {
     $metadata = $event->getMetadata();
     $reflection = $metadata->getClassMetadata()->reflection;
     if (false === $reflection->isSubclassOf(FileVersionMeta::class) && $metadata->getName() !== FileVersionMeta::class) {
         return;
     }
     $document = $event->getDocument();
     $subject = $event->getSubject();
     $locale = $subject->getLocale();
     $fileVersion = $subject->getFileVersion();
     $file = $fileVersion->getFile();
     $media = $file->getMedia();
     // Do not try and get the image URL if the mime type is not in the
     // list of mime types for which thumbnails are generated.
     foreach ($this->thumbnailMimeTypes as $type) {
         if (fnmatch($type, $fileVersion->getMimeType())) {
             $document->setImageUrl($this->getImageUrl($media, $locale));
             break;
         }
     }
     $document->addField($this->factory->createField('media_id', $media->getId()));
     $document->addField($this->factory->createField('media_mime', $fileVersion->getMimeType()));
     if ($collection = $media->getCollection()) {
         $document->addField($this->factory->createField('collection_id', $collection->getId()));
     }
 }
Пример #2
0
 /**
  * Map blame and timestamp information to the search document.
  *
  * @param PreIndexEvent $event
  */
 public function handleBlameTimestamp(PreIndexEvent $event)
 {
     $subject = $event->getSubject();
     $document = $event->getDocument();
     if ($subject instanceof UserBlameInterface) {
         $this->mapCreatorAndChanger($document, $subject->getCreator(), $subject->getChanger());
     }
     if ($subject instanceof TimestampableInterface) {
         $this->mapTimestamp($document, $subject->getCreated(), $subject->getChanged());
     }
 }
Пример #3
0
 /**
  * Adds the image to the search document.
  *
  * @param PreIndexEvent $e
  */
 public function handlePreIndex(PreIndexEvent $e)
 {
     $metadata = $e->getMetadata();
     $document = $e->getDocument();
     $subject = $e->getSubject();
     $evaluator = $e->getFieldEvaluator();
     if (false === $metadata->getClassMetadata()->reflection->isSubclassOf(StructureBehavior::class)) {
         return;
     }
     if (!($imageUrlField = $metadata->getImageUrlField())) {
         return;
     }
     $data = $evaluator->getValue($subject, $imageUrlField);
     $locale = $subject->getLocale();
     if (!$data) {
         $document->setImageUrl(null);
         return;
     }
     $imageUrl = $this->getImageUrl($data, $locale);
     $document->setImageUrl($imageUrl);
 }