Exemplo n.º 1
0
 /**
  * @param Contact $contact
  * @param null    $height
  * @param bool    $responsive
  * @param null    $classes
  *
  * @return string
  */
 public function __invoke(Contact $contact, $height = null, $responsive = true, $classes = null)
 {
     if (is_null($contact->getPhoto())) {
         return sprintf('<img src="assets/' . DEBRANOVA_HOST . '/style/image/anonymous.jpg" class="%s" %s>', !($responsive && is_null($height)) ?: implode(' ', ['img-responsive']), is_null($height) ?: 'height="' . $height . '"');
     }
     /**
      * @var Photo $photo
      */
     $photo = $contact->getPhoto()->first();
     if (null !== $classes && !is_array($classes)) {
         $classes = [$classes];
     } elseif (null === $classes) {
         $classes = [];
     }
     if ($responsive) {
         $classes[] = 'img-responsive';
     }
     $this->setClasses($classes);
     /*
      * Return an empty photo when there is no, or only a empty object
      */
     if (!$photo || is_null($photo->getId())) {
         return sprintf('<img src="assets/' . DEBRANOVA_HOST . '/style/image/anonymous.jpg" class="%s" %s>', !($responsive && is_null($height)) ?: implode(' ', ['img-responsive']), is_null($height) ?: 'height="' . $height . '"');
     }
     $this->setRouter('assets/contact-photo');
     $this->addRouterParam('hash', $photo->getHash());
     $this->addRouterParam('ext', $photo->getContentType()->getExtension());
     $this->addRouterParam('id', $photo->getId());
     $this->setHeight($height);
     return $this->createImageUrl();
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 /**
  * 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];
 }