Exemplo 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);
 }
Exemplo n.º 2
0
 /**
  * @param  Entity\Contact  $contact
  * @param  Entity\Facebook $facebook
  * @return bool
  */
 public function isContactInFacebook(Entity\Contact $contact, Entity\Facebook $facebook)
 {
     $resultSetMap = new ResultSetMapping();
     $resultSetMap->addEntityResult('Contact\\Entity\\Contact', 'c');
     /**
      * Don't map the contact_id because that will overwrite the existing contact object leaving an emtpy one
      */
     $resultSetMap->addFieldResult('c', 'email', 'email');
     $queryInString = sprintf("SELECT %s FROM %s WHERE %s", $facebook->getContactKey(), $facebook->getFromClause(), $facebook->getWhereClause());
     $query = $this->getEntityManager()->createNativeQuery(sprintf("SELECT email FROM contact WHERE contact_id = %s AND contact_id IN (%s) AND date_end IS NULL", $contact->getId(), $queryInString), $resultSetMap);
     return sizeof($query->getResult()) > 0;
 }
Exemplo n.º 3
0
 /**
  * Return Contact entities based on a selection SQL using a native SQL query
  *
  * @param Entity\Contact $contact
  * @param SelectionSql   $sql
  *
  * @return bool
  */
 public function isContactInSelectionSQL(Entity\Contact $contact, SelectionSQL $sql)
 {
     $resultSetMap = new ResultSetMapping();
     $resultSetMap->addEntityResult('Contact\\Entity\\Contact', 'c');
     $resultSetMap->addFieldResult('c', 'contact_id', 'id');
     $query = $this->getEntityManager()->createNativeQuery("SELECT\n             contact_id\n             FROM contact\n             WHERE contact_id\n             IN (" . $sql->getQuery() . ") AND contact_id = " . $contact->getId(), $resultSetMap);
     return sizeof($query->getResult()) > 0;
 }
Exemplo n.º 4
0
 /**
  * Needed for the hydration of form elements.
  *
  * @return array
  */
 public function getArrayCopy()
 {
     return ['id' => $this->id, 'rationale' => $this->rationale, 'contact' => $this->contact->getId()];
 }
Exemplo n.º 5
0
 /**
  * Send the email.
  */
 public function send()
 {
     switch ($this->email->isPersonal()) {
         case true:
             foreach ($this->email->getTo() as $recipient => $contact) {
                 /*
                  * Create a new message for everyone
                  */
                 $this->message = new Message();
                 $this->message->setEncoding('UTF-8');
                 $this->generateMessage();
                 //add the CC and BCC to the email
                 $this->setShadowRecipients();
                 /*
                  * We have a recipient which can be an instance of the contact. Produce a contactService object
                  * and fill the templateVars with extra options
                  */
                 if ($contact instanceof Contact) {
                     $this->updateTemplateVarsWithContact($contact);
                 } else {
                     $contact = new Contact();
                     $contact->setEmail($recipient);
                 }
                 /*
                  * Overrule the to when we are in development
                  */
                 if (!defined("DEBRANOVA_ENVIRONMENT") || 'development' === DEBRANOVA_ENVIRONMENT) {
                     $this->message->addTo('*****@*****.**', $contact->getDisplayName());
                 } else {
                     $this->message->addTo($contact->getEmail(), !is_null($contact->getId()) ? $contact->getDisplayName() : null);
                 }
                 /**
                  * We have the contact and can now produce the content of the message
                  */
                 $this->parseSubject();
                 /**
                  * If we have a deeplink, parse it
                  */
                 $this->parseDeeplink();
                 /**
                  * If we have an unsubscribe, parse it
                  */
                 $this->parseUnsubscribe();
                 /**
                  * We have the contact and can now produce the content of the message
                  */
                 $this->parseBody();
                 /**
                  * Send the email
                  */
                 $this->transport->send($this->message);
             }
             break;
         case false:
             /*
              * Create a new message for everyone
              */
             $this->message = new Message();
             $this->message->setEncoding('UTF-8');
             $this->generateMessage();
             //add the CC and BCC to the email
             $this->setShadowRecipients();
             foreach ($this->email->getTo() as $recipient => $contact) {
                 /*
                  * We have a recipient which can be an instance of the contact. Produce a contactService object
                  * and fill the templateVars with extra options
                  */
                 if (!$contact instanceof Contact) {
                     $contact = new Contact();
                     $contact->setEmail($recipient);
                 }
                 /*
                  * Overrule the to when we are in development
                  */
                 if (!defined("DEBRANOVA_ENVIRONMENT") || 'development' === DEBRANOVA_ENVIRONMENT) {
                     $this->message->addTo('*****@*****.**', $contact->getDisplayName());
                 } else {
                     $this->message->addTo($contact->getEmail(), !is_null($contact->getId()) ? $contact->getDisplayName() : null);
                 }
             }
             /*
              * We have the contact and can now produce the content of the message
              */
             $this->parseSubject();
             /**
              * If we have a deeplink, parse it
              */
             $this->parseDeeplink();
             /**
              * If we have an unsubscribe, parse it
              */
             $this->parseUnsubscribe();
             /*
              * We have the contact and can now produce the content of the message
              */
             $this->parseBody();
             /*
              * Send the email
              */
             $this->transport->send($this->message);
             break;
     }
 }
Exemplo n.º 6
0
 /**
  * Returns of contact is:
  * - Associate
  * - Affiliate
  * - Project leader
  * - Work package leader.
  *
  * @param Contact $contact
  * @param Project $project
  *
  * @return bool
  */
 public function isContactInProject(Contact $contact, Project $project)
 {
     $this->getProjectService()->setProject($project);
     $projectContacts = $this->findContactsInProject($this->getProjectService());
     return array_key_exists($contact->getId(), $projectContacts);
 }
Exemplo n.º 7
0
 /**
  * @return bool
  */
 public function isEmpty()
 {
     return is_null($this->contact) || is_null($this->contact->getId());
 }