/** * 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); }
/** * Special function which translates the output of the facebook to a known value * * @param $titleGetter * @param Contact $contact * @return string */ private function facebookTitleParser($titleGetter, Contact $contact) { if (strlen($titleGetter) === 0) { return ''; } //Format the $getter switch (intval($titleGetter)) { case Facebook::DISPLAY_ORGANISATION: if (is_null($contact->getContactOrganisation())) { return 'Unknown'; } return (string) $contact->getContactOrganisation()->getOrganisation(); case Facebook::DISPLAY_COUNTRY: if (is_null($contact->getContactOrganisation())) { return 'Unknown'; } return (string) $contact->getContactOrganisation()->getOrganisation()->getCountry(); case Facebook::DISPLAY_PROJECTS: $projects = []; foreach ($contact->getProject() as $project) { $projects[] = $project->getProject(); } return implode(', ', $projects); case Facebook::DISPLAY_POSITION: return $contact->getPosition(); case Facebook::DISPLAY_NONE: default: return ''; } }