/** * @param Contact $contact * @param Selection $selection * * @return bool */ public function findContactInSelection(Contact $contact, Selection $selection) { if (!is_null($selection->getSql())) { try { //We have a dynamic query, check if the contact is in the selection return $this->getEntityManager()->getRepository(Contact::class)->isContactInSelectionSQL($contact, $selection->getSql()); } catch (\Exception $e) { print sprintf("Selection %s is giving troubles ()", $selection->getId(), $e->getMessage()); } } /* * The selection contains contacts, do an extra query to find the contact */ if (sizeof($selection->getSelectionContact()) > 0) { $findContact = $this->getEntityManager()->getRepository($this->getFullEntityName('SelectionContact'))->findOneBy(['contact' => $contact, 'selection' => $selection]); /* * Return true when we found a contact */ if (!is_null($findContact)) { return true; } } }
/** * @param Selection $selection * * @return bool * @throws \InvalidArgumentException */ public function findContactInSelection(Selection $selection) { if (is_null($this->getContact())) { throw new \InvalidArgumentException("The contact cannot be null"); } 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'))->isContactInSelectionSQL($this->getContact(), $selection->getSql()); } /** * The selection contains contacts, do an extra query to find the contact */ if (sizeof($selection->getSelectionContact()) > 0) { $contact = $this->getEntityManager()->getRepository($this->getFullEntityName('SelectionContact'))->findOneBy(['contact' => $this->getContact(), 'selection' => $selection]); /** * Return true when we found a contact */ if (!is_null($contact)) { return true; } } }