Example #1
0
 /**
  * @param $import
  */
 private function importContacts($import)
 {
     foreach ($this->contacts as $key => $contact) {
         if (in_array($key, $import)) {
             if (is_null($contact->getId())) {
                 $contact = $this->getContactService()->newEntity($contact);
             }
             $contactOptIn = new ArrayCollection($this->optIn);
             /** Add the optIn */
             foreach ($contact->getOptIn() as $optIn) {
                 $contactOptIn->removeElement($optIn);
             }
             $contact->addOptIn($contactOptIn);
             if (!$this->getContactService()->contactInSelection($contact, $this->getSelection())) {
                 $selectionContact = new SelectionContact();
                 $selectionContact->setSelection($this->getSelection());
                 $selectionContact->setContact($contact);
                 $this->getSelectionService()->newEntity($selectionContact);
             }
             $this->importedContacts[] = $contact;
         }
     }
 }
Example #2
0
 /**
  * @param array $data
  *
  * array (size=5)
  * 'type' => string '2' (length=1)
  * 'added' => string '20388' (length=5)
  * 'removed' => string '' (length=0)
  * 'sql' => string '' (length=0)
  *
  *
  */
 public function updateSelectionContacts(Selection $selection, array $data)
 {
     /**
      * First update the selection based on the type
      */
     if ((int) $data['type'] === Selection::TYPE_FIXED) {
         //remove the query
         if (!is_null($sql = $selection->getSql())) {
             $this->removeEntity($sql);
         }
         //Update the contacts
         if (!empty($data['added'])) {
             foreach (explode(',', $data['added']) as $contactId) {
                 $contact = $this->getContactService()->findEntityById('contact', $contactId);
                 if (!$contact->isEmpty() && !$this->getContactService()->contactInSelection($contact, $selection)) {
                     $selectionContact = new SelectionContact();
                     $selectionContact->setContact($contact);
                     $selectionContact->setSelection($selection);
                     $this->newEntity($selectionContact);
                 }
             }
         }
         //Update the contacts
         if (!empty($data['removed'])) {
             foreach (explode(',', $data['removed']) as $contactId) {
                 foreach ($selection->getSelectionContact() as $selectionContact) {
                     if ($selectionContact->getContact()->getId() === (int) $contactId) {
                         $this->removeEntity($selectionContact);
                     }
                 }
             }
         }
     } else {
         $selectionSql = $selection->getSql();
         if (is_null($selectionSql)) {
             $selectionSql = new SelectionSql();
             $selectionSql->setSelection($selection);
         }
         $selectionSql->setQuery($data['sql']);
         $this->updateEntity($selectionSql);
     }
 }