/** * 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); }
/** * @param Contact $contact * * @return array */ public function findOrganisationForProfileEditByContact(Contact $contact) { $organisations = []; //Start with your own organisation if (!is_null($contact->getContactOrganisation())) { $organisations[$contact->getContactOrganisation()->getOrganisation()->getId()] = $contact->getContactOrganisation()->getOrganisation(); } foreach ($this->findOrganisationByEmailAddress($contact->getEmail()) as $organisation) { $organisations[$organisation->getId()] = $organisation; } asort($organisations); //Add an empty value $emptyOrganisation = new Entity\Organisation(); $emptyOrganisation->setId(0); $emptyOrganisation->setOrganisation('— None of the above'); $organisations[$emptyOrganisation->getId()] = $emptyOrganisation; return $organisations; }
/** * Create an array with the incomplete items in the profile and the relative weight. * * @param Contact $contact * * @return array; */ public function getProfileInCompleteness(Contact $contact) { $inCompleteness = []; $totalWeight = 0; $totalWeight += 10; if (is_null($contact->getFirstName())) { $inCompleteness['firstName']['message'] = _("txt-first-name-is-missing"); $inCompleteness['firstName']['weight'] = 10; } $totalWeight += 10; if (is_null($contact->getLastName())) { $inCompleteness['lastName']['message'] = _("txt-last-name-is-missing"); $inCompleteness['lastName']['weight'] = 10; } $totalWeight += 10; if (sizeof($contact->getPhone()) === 0) { $inCompleteness['phone']['message'] = _("txt-no-telephone-number-known"); $inCompleteness['phone']['weight'] = 10; } $totalWeight += 10; if (sizeof($contact->getAddress()) === 0) { $inCompleteness['address']['message'] = _("txt-no-address-known"); $inCompleteness['address']['weight'] = 10; } $totalWeight += 10; if (sizeof($contact->getPhoto()) === 0) { $inCompleteness['photo']['message'] = _("txt-no-profile-photo-given"); $inCompleteness['photo']['weight'] = 10; } $totalWeight += 10; if (is_null($contact->getSaltedPassword())) { $inCompleteness['password']['message'] = _("txt-no-password-given"); $inCompleteness['password']['weight'] = 10; } $totalWeight += 20; if (is_null($contact->getContactOrganisation()) === 0) { $inCompleteness['organisation']['message'] = _("txt-no-organisation-known"); $inCompleteness['organisation']['weight'] = 20; } /* * Determine the total weight */ $incompletenessWeight = 0; /* * Update the values in the table to create a total weight of 100% */ foreach ($inCompleteness as &$itemPerType) { $itemPerType['weight'] = $itemPerType['weight'] / $totalWeight * 100; $incompletenessWeight += $itemPerType['weight']; } return ['items' => $inCompleteness, 'incompletenessWeight' => $incompletenessWeight]; }
/** * @param Project $project * @param Contact $contact * @param int $which * * @return null|Affiliation */ public function findAffiliationByProjectAndContactAndWhich(Project $project, Contact $contact, $which = self::WHICH_ONLY_ACTIVE) { /** * If the contact has no contact organisation, return null because we will not have a affiliation */ if (is_null($contact->getContactOrganisation())) { return; } foreach ($project->getAffiliation() as $affiliation) { if ($which === self::WHICH_ONLY_ACTIVE && !is_null($affiliation->getDateEnd())) { continue; } if ($which === self::WHICH_ONLY_INACTIVE && is_null($affiliation->getDateEnd())) { continue; } if ($affiliation->getOrganisation()->getId() === $contact->getContactOrganisation()->getOrganisation()->getId()) { return $affiliation; } } return; }
/** * We use this function to update the contactOrganisation of a user. * As input we use the corresponding contact entity and the array containing the * contactOrganisation information * * $contactOrganisation['organisation'] > Name of the organisation * $contactOrganisation['country'] > CountryId * * @param Contact $contact * @param array $contactOrganisation * * @return void */ public function updateContactOrganisation(Contact $contact, array $contactOrganisation) { /** * Don't do anything when the organisationName = empty */ if (empty($contactOrganisation['organisation'])) { return; } $country = $this->getGeneralService()->findEntityById('country', (int) $contactOrganisation['country']); $currentContactOrganisation = $contact->getContactOrganisation(); if (is_null($currentContactOrganisation)) { $currentContactOrganisation = new ContactOrganisation(); $currentContactOrganisation->setContact($contact); } /** * Look for the organisation based on the name (without branch) and country + email */ $organisation = $this->getOrganisationService()->findOrganisationByNameCountryAndEmailAddress($contactOrganisation['organisation'], $country, $contact->getEmail()); $organisationFound = false; /** * We did not find an organisation, so we need to create it */ if (sizeof($organisation) === 0) { $organisation = new Organisation(); $organisation->setOrganisation($contactOrganisation['organisation']); $organisation->setCountry($country); $organisation->setType($this->organisationService->findEntityById('Type', 0)); //Unknown /** * Add the domain in the saved domains for this new company * Use the ZF2 EmailAddress validator to strip the hostname out of the EmailAddress */ $validateEmail = new EmailAddress(); $validateEmail->isValid($contact->getEmail()); $organisationWeb = new Web(); $organisationWeb->setOrganisation($organisation); $organisationWeb->setWeb($validateEmail->hostname); $organisationWeb->setMain(Web::MAIN); $this->getOrganisationService()->newEntity($organisationWeb); $currentContactOrganisation->setOrganisation($organisation); } else { $foundOrganisation = null; /** * Go over the found organisation to match the branching */ foreach ($organisation as $foundOrganisation) { /** * Stop when we have found an exact match and reset the branch if set */ if ($foundOrganisation->getOrganisation() === $contactOrganisation['organisation'] && $country->getId() === $foundOrganisation->getCountry()->getId()) { $currentContactOrganisation->setOrganisation($foundOrganisation); $currentContactOrganisation->setBranch(null); break; } if (!$organisationFound) { //Create only a branch when the name is found and the given names do not match in length if (strlen($foundOrganisation->getOrganisation()) < strlen($contactOrganisation['organisation']) - strlen($currentContactOrganisation->getBranch())) { $currentContactOrganisation->setBranch(str_replace($contactOrganisation['organisation'], '~', $foundOrganisation->getOrganisation())); } /** * We have found a match of the organisation in the string and */ $organisationFound = true; } } $currentContactOrganisation->setOrganisation($foundOrganisation); } $this->updateEntity($currentContactOrganisation); }