/** * @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; } } }
/** * Return Contact entities based on a selection SQL using a native SQL query * * @param Selection $selection * * @return Entity\Contact[] */ public function findContactsBySelectionContact(Selection $selection) { $qb = $this->_em->createQueryBuilder(); $qb->select('c'); $qb->from("Contact\\Entity\\Contact", 'c'); $qb->join('c.selectionContact', 'sc'); $qb->distinct('c.id'); $qb->andWhere($qb->expr()->isNull('c.dateEnd')); $qb->andWhere('sc.selection = ?1'); $qb->setParameter(1, $selection->getId()); $qb->orderBy('c.lastName'); return $qb->getQuery()->getResult(); }
/** * Return Contact entities based on a selection SQL using a native SQL query. * * @param Selection $selection * @param bool $toArray * * @return Entity\Contact[] */ public function findContactsBySelectionContact(Selection $selection, $toArray = false) { $qb = $this->_em->createQueryBuilder(); $qb->select('c', 'co', 'o', 'cy'); $qb->from("Contact\\Entity\\Contact", 'c'); $qb->join('c.selectionContact', 'sc'); $qb->leftJoin('c.contactOrganisation', 'co'); $qb->join('co.organisation', 'o'); $qb->join('o.country', 'cy'); $qb->distinct('c.id'); $qb->andWhere($qb->expr()->isNull('c.dateEnd')); $qb->andWhere('sc.selection = ?1'); $qb->setParameter(1, $selection->getId()); $qb->orderBy('c.lastName'); if ($toArray) { return $this->reIndexContactArray($qb->getQuery()->getResult(AbstractQuery::HYDRATE_SCALAR)); } else { return $qb->getQuery()->getResult(); } }