/** * @param Entity\OptIn $optIn * @param bool $toArray * * @return Entity\Contact[] */ public function findContactsByOptIn(Entity\OptIn $optIn, $toArray = false) { $qb = $this->_em->createQueryBuilder(); $qb->select('c'); $qb->from("Contact\\Entity\\Contact", 'c'); $qb->join("c.optIn", 'optIn'); $qb->where($qb->expr()->in('optIn.id', $optIn->getId())); $qb->orderBy('c.lastName'); if ($toArray) { return $qb->getQuery()->getArrayResult(); } else { return $qb->getQuery()->getResult(); } }
/** * New function needed to make the hydrator happy * * @param Collections\Collection $optInCollection */ public function removeOptIn(Collections\Collection $optInCollection) { foreach ($optInCollection as $optIn) { $this->optIn->removeElement($optIn); } }
public function testCanAddMultipleOptInToUser() { $contact = $this->entityManager->find("Contact\\Entity\\Contact", 1); $optIn = new \Contact\Entity\OptIn(); $optIn->setOptIn(3); $optIn->setDescription('This is the description'); $optIn2 = new \Contact\Entity\OptIn(); $optIn2->setOptIn(4); $optIn2->setDescription('This is the description'); $contact->setOptIn(array($optIn, $optIn2)); $this->entityManager->persist($contact); $this->entityManager->flush(); $this->assertEquals(2, sizeof($contact->getOptIn())); }