Пример #1
0
 public function provider()
 {
     $genderTest = new GenderTest();
     $titleTest = new TitleTest();
     $contact = new Contact();
     $contact->setFirstName('Jan');
     $contact->setMiddleName('van der');
     $contact->setLastName('Vliet');
     $contact->setEmail('info+' . Rand::getString(4) . '@example.com');
     $contact->setGender($genderTest->provider()[0][0]);
     $contact->setTitle($titleTest->provider()[0][0]);
     return [[$contact]];
 }
Пример #2
0
 /**
  * Body function, creating the contactObjects.
  */
 private function prepareContent()
 {
     foreach ($this->content as $key => $content) {
         //See first if the contact can be found
         $contact = $this->getContactService()->findContactByEmail($content[$this->headerKeys['email']]);
         if (!is_null($contact)) {
             $contact->key = $key;
             $this->contacts[] = $contact;
             continue;
         }
         /**
          * 'organisation_id' => int 0
          * 'organisation' => int 1
          * 'firstname' => int 2
          * 'middlename' => int 3
          * 'lastname' => int 4
          * 'position' => int 5
          * 'email' => int 6
          * 'phone' => int 7
          * 'country' => int 8
          * 'gender' => int 8
          * 'title' => int 8
          */
         //Contact is not found
         $contact = new Contact();
         $contact->key = $key;
         $contact->setFirstName($content[$this->headerKeys['firstname']]);
         $contact->setMiddleName($content[$this->headerKeys['middlename']]);
         $contact->setLastName($content[$this->headerKeys['lastname']]);
         $contact->setEmail($content[$this->headerKeys['email']]);
         $gender = null;
         $title = null;
         if (isset($this->headerKeys['gender']) && !empty($content[$this->headerKeys['gender']])) {
             $gender = $contact->setGender($this->getGeneralService()->findGenderByGender($content[$this->headerKeys['gender']]));
         }
         if (!is_null($gender)) {
             $contact->setGender($gender);
         } else {
             $contact->setGender($this->getGeneralService()->findEntityById('gender', Gender::GENDER_UNKNOWN));
         }
         if (isset($this->headerKeys['title']) && !empty($content[$this->headerKeys['title']])) {
             $title = $contact->setTitle($this->getGeneralService()->findTitleByTitle($content[$this->headerKeys['title']]));
         }
         if (!is_null($title)) {
             $contact->setTitle($title);
         } else {
             $contact->setTitle($this->getGeneralService()->findEntityById('title', Title::TITLE_UNKNOWN));
         }
         $contact->setPosition($content[$this->headerKeys['position']]);
         //If found, set the phone number
         if (isset($this->headerKeys['phone']) && !empty($content[$this->headerKeys['phone']])) {
             $phone = new Phone();
             $phoneType = $this->getContactService()->findEntityById('phoneType', PhoneType::PHONE_TYPE_DIRECT);
             $phone->setType($phoneType);
             $phone->setPhone($content[$this->headerKeys['phone']]);
             $phone->setContact($contact);
             $phones = new ArrayCollection();
             $phones->add($phone);
             $contact->setPhone($phones);
         }
         //Try to find the country
         $country = $this->getGeneralService()->findCountryByName($content[$this->headerKeys['country']]);
         //Try to find the organisation
         $organisationName = $content[$this->headerKeys['organisation']];
         $organisation = null;
         if (isset($this->headerKeys['organisation_id']) && !empty($content[$this->headerKeys['organisation_id']])) {
             $organisation = $this->getOrganisationService()->setOrganisationId($content[$this->headerKeys['organisation_id']])->getOrganisation();
         }
         if (is_null($organisation) && !is_null($country)) {
             $organisation = $this->getOrganisationService()->findOrganisationByNameCountry($organisationName, $country);
         }
         //If the organisation does not exist, create it
         if (is_null($organisation) && !is_null($country)) {
             $organisation = new Organisation();
             $organisation->setOrganisation($organisationName);
             $organisation->setCountry($country);
             //Add the type
             $organisationType = $this->getOrganisationService()->findEntityById('type', Type::TYPE_UNKNOWN);
             $organisation->setType($organisationType);
             //Add the domain
             $validate = new EmailAddress();
             $validate->isValid($content[$this->headerKeys['email']]);
             $organisationWebElements = new ArrayCollection();
             $organisationWeb = new Web();
             $organisationWeb->setWeb($validate->hostname);
             $organisationWeb->setMain(Web::MAIN);
             $organisationWeb->setOrganisation($organisation);
             $organisationWebElements->add($organisationWeb);
             if (isset($this->headerKeys['website']) && !is_null($content[$this->headerKeys['website']])) {
                 //Strip the http:// and https://
                 $website = str_replace('http://', '', $content[$this->headerKeys['website']]);
                 $website = str_replace('https://', '', $website);
                 $organisationWebsite = new Web();
                 $organisationWebsite->setMain(Web::MAIN);
                 $organisationWebsite->setWeb($website);
                 $organisationWebsite->setOrganisation($organisation);
                 $organisationWebElements->add($organisationWebsite);
             }
             $organisation->setWeb($organisationWebElements);
         }
         /**
          * If an organisation is found, add it to the contact
          */
         if (!is_null($organisation)) {
             $contactOrganisation = new ContactOrganisation();
             $contactOrganisation->setOrganisation($organisation);
             $contactOrganisation->setContact($contact);
             $contact->setContactOrganisation($contactOrganisation);
         }
         /** Add the contact to the contacts array */
         $this->contacts[] = $contact;
     }
 }
Пример #3
0
 /**
  * Create an account and send an email address.
  *
  * @param string $emailAddress
  * @param string $firstName
  * @param string $middleName
  * @param string $lastName
  *
  * @return Contact
  */
 public function register($emailAddress, $firstName, $middleName, $lastName)
 {
     //Create the account
     $contact = new Contact();
     $contact->setEmail($emailAddress);
     $contact->setFirstName($firstName);
     if (strlen($middleName) > 0) {
         $contact->setMiddleName($middleName);
     }
     $contact->setLastName($lastName);
     //Fix the gender
     $contact->setGender($this->getGeneralService()->findEntityById('gender', Gender::GENDER_UNKNOWN));
     $contact->setTitle($this->getGeneralService()->findEntityById('title', Title::TITLE_UNKNOWN));
     /*
      * Include all the optIns
      */
     $contact->setOptIn($this->getEntityManager()->getRepository('Contact\\Entity\\OptIn')->findBy(['autoSubscribe' => OptIn::AUTO_SUBSCRIBE]));
     /**
      * @var $contact Contact
      */
     $contact = $this->newEntity($contact);
     //Create a target
     $target = $this->getDeeplinkService()->createTargetFromRoute('community/contact/profile/view');
     //Create a deep link for the user which redirects to the profile-page
     $deeplink = $this->getDeeplinkService()->createDeeplink($target, $contact);
     $email = $this->getEmailService()->create();
     $this->getEmailService()->setTemplate("/auth/register:mail");
     $email->setDisplayName($contact->getDisplayName());
     $email->addTo($emailAddress);
     $email->setUrl($this->getDeeplinkService()->parseDeeplinkUrl($deeplink));
     $this->getEmailService()->send();
     return $contact;
 }