/** * @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; }
/** * @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); } }
/** * @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); } }
public function isSql() { return !is_null($this->selection->getSql()); }