Ejemplo n.º 1
0
 /**
  * Update or insert a contact document
  *
  * @param Contact $contact
  *
  * <field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
  * <field name="contact_id" type="int" indexed="true" stored="true" omitNorms="true"/>
  * <field name="fullname" type="text_general" indexed="true" stored="true" omitNorms="true"/>
  * <field name="lastname" type="string" indexed="true" stored="true" omitNorms="true"/>
  * <field name="position" type="text_en_splitting" indexed="true" stored="true" omitNorms="true"/>
  * <field name="type" type="string" indexed="true" stored="true" omitNorms="true"/>
  * <field name="photo_url" type="string" indexed="true" stored="true" omitNorms="true"/>
  * <field name="organisation" type="string" indexed="true" stored="true" omitNorms="true"/>
  * <field name="organisation_type" type="string" indexed="true" stored="true" omitNorms="true"/>
  * <field name="country" type="string" indexed="true" stored="true" omitNorms="true"/>
  * <field name="profile" type="text_en_splitting" indexed="true" stored="true" omitNorms="true"/>
  * <field name="cv" type="text_en_splitting" indexed="true" stored="true" omitNorms="true"/>
  *
  * @return \Solarium\Core\Query\Result\ResultInterface
  * @throws \Solarium\Exception\HttpException
  */
 public function updateDocument($contact)
 {
     // Get an update query instance
     $update = $this->getSolrClient()->createUpdate();
     $contactDocument = $update->createDocument();
     $contactDocument->id = $contact->getResourceId();
     $contactDocument->contact_id = $contact->getId();
     $contactDocument->type = 'contact';
     $contactDocument->fullname = $contact->getDisplayName();
     $contactDocument->lastname = $contact->getLastName();
     $contactDocument->position = $contact->getPosition();
     if (!is_null($contact->getProfile())) {
         $contactDocument->profile = str_replace(PHP_EOL, '', strip_tags($contact->getProfile()->getDescription()));
         if ($contact->getProfile()->getHidePhoto() === Profile::NOT_HIDE_PHOTO && $contact->getPhoto()->count() > 0) {
             $photo = $contact->getPhoto()->first();
             $contactDocument->photo_url = $this->getServiceLocator()->get('ViewHelperManager')->get('url')->__invoke('assets/contact-photo', ['hash' => $photo->getHash(), 'ext' => $photo->getContentType()->getExtension(), 'id' => $photo->getId()]);
         }
     }
     if (!is_null($contact->getContactOrganisation())) {
         $contactDocument->organisation = $contact->getContactOrganisation()->getOrganisation()->getOrganisation();
         $contactDocument->organisation_type = $contact->getContactOrganisation()->getOrganisation()->getType();
         $contactDocument->country = $contact->getContactOrganisation()->getOrganisation()->getCountry()->getCountry();
     }
     if (!is_null($contact->getCv())) {
         $contactDocument->cv = str_replace(PHP_EOL, '', strip_tags(stream_get_contents($contact->getCv()->getCv())));
     }
     $update->addDocument($contactDocument);
     $update->addCommit();
     return $this->executeUpdateDocument($update);
 }