public function doPostTransform(TransformEvent $event) { /** @var Document $document */ $document = $event->getDocument(); if ($document->has('tags')) { $explodeTags = array_map('trim', array_values(array_filter(explode(',', $document->get('tags'))))); $document->set('tags', $explodeTags); } if ($document->has('keywords')) { $explodeKeywords = array_map('trim', array_values(array_filter(explode(',', $document->get('keywords'))))); $document->set('keywords', $explodeKeywords); } return $event; }
public function addEncodedResumeProperty(TransformEvent $event) { /** @var Document $document */ $document = $event->getDocument(); $resume = $event->getObject(); if (!$resume) { return; } if (!$resume instanceof StudentResume) { return; } try { $filePath = $this->storage->resolveUri($resume, "file"); if ($resume->getFileName()) { $document->set('encodedFile', base64_encode(file_get_contents($filePath))); } else { $document->set('encodedFile', ''); } } catch (\Exception $ex) { } }
public function addCustomProperty(TransformEvent $event) { $object = $event->getObject(); $document = $event->getDocument(); $document->addGeoPoint('location', $object->getLat(), $object->getLng()); if (!$object->getProvince()) { $locale = 'it'; $countries = Locale::getDisplayCountries($locale); $country = $countries[$object->getCountry()]; $address = $object->getAddress() . ' ' . $object->getTown() . ' ' . $country; try { $result = $this->geocode->using('google_maps')->reverse($object->getLat(), $object->getLng()); $document->set('town', $result->getCity()); $document->set('zipcode', $result->getZipcode()); $document->set('province', $result->getCountyCode()); $document->set('country', $result->getCountryCode()); $document->set('address', $result->getStreetName() . ' ' . $result->getStreetNumber()); $document->set('region', $result->getRegion()); } catch (\Exception $e) { print $object->getId() . '::' . $e->getMessage() . "\n"; } } }
/** * @param TransformEvent $event * * @throws \InvalidArgumentException * @throws InvalidException */ public function addCustomProperty(TransformEvent $event) { /** @var Document $document */ $document = $event->getDocument(); $data = $event->getObject(); if (!$data instanceof DataInterface) { return; } foreach ($data->getFamily()->getAttributes() as $attribute) { if ($document->has($attribute->getCode())) { continue; } if ($attribute->isMultiple()) { $values = $data->getValuesData($attribute); if ($values instanceof ArrayCollection) { $values = $values->toArray(); } $document->set($attribute->getCode(), $this->parseAttributeValues($values)); } else { $value = $data->getValueData($attribute); $document->set($attribute->getCode(), $this->parseAttributeValue($value)); } } }
public function addCustomProperty(TransformEvent $event) { $document = $event->getDocument(); $custom = $this->anotherService->calculateCustom($event->getObject()); $document->set('custom', $custom); }