コード例 #1
0
ファイル: ContactService.php プロジェクト: iteaoffice/contact
 /**
  * @param Selection $selection
  *
  * @return Contact[]
  */
 public function findContactsInSelectionAsArray(Selection $selection)
 {
     /*
      * A selection can have 2 methods, either SQL or a contacts. We need to query both
      */
     if (!is_null($selection->getSql())) {
         //We have a dynamic query, check if the contact is in the selection
         $contacts = $this->getEntityManager()->getRepository(Contact::class)->findContactsBySelectionSQL($selection->getSql(), true);
     } else {
         $contacts = $this->getEntityManager()->getRepository(Contact::class)->findContactsBySelectionContact($selection, true);
     }
     return $contacts;
 }
コード例 #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);
     }
 }
コード例 #3
0
ファイル: ContactService.php プロジェクト: debranova/contact
 /**
  * @param Selection $selection
  *
  * @return Contact[]
  */
 public function findContactsInSelection(Selection $selection)
 {
     /**
      * A selection can have 2 methods, either SQL or a contacts. We need to query both
      */
     if (!is_null($selection->getSql())) {
         //We have a dynamic query, check if the contact is in the selection
         return $this->getEntityManager()->getRepository($this->getFullEntityName('Contact'))->findContactsBySelectionSQL($selection->getSql());
     } else {
         return $this->getEntityManager()->getRepository($this->getFullEntityName('Contact'))->findContactsBySelectionContact($selection);
     }
 }
コード例 #4
0
 public function isSql()
 {
     return !is_null($this->selection->getSql());
 }