/** * Function to validate a phonenumber using the mid-service phone number bundle. * @param ExecutionContextInterface $context the context * @param Organisation $org an organisation */ public function validatePhoneNumber($org, $context) { $tel = $org->getTelephone(); $phoneUtil = phoneUtil::getInstance(); $pattern = '/^[0-9+\\-\\/\\\\.\\(\\)\\s]{6,35}$/i'; $matchesPattern = preg_match($pattern, $tel); if ($matchesPattern != 1) { $context->buildViolation("person.telephone.numericWithExtra")->atPath("telephone")->addViolation(); } else { $number = $phoneUtil->parse($tel, 'BE'); if (!$phoneUtil->isValidNumber($number)) { $context->buildViolation("person.telephone.valid")->atPath("telephone")->addViolation(); } else { $org->setTelephone($phoneUtil->format($number, \libphonenumber\PhoneNumberFormat::NATIONAL)); } } }
/** * A simple test to check whether it's possible to make two Organisation objects with * the same name. This should be impossible. */ public function testNameUnique() { $name = "vogelen"; $organisation = new Organisation(); $organisation->setName($name); try { $organisation2 = new Organisation(); $organisation2->setName($name); $this->assertNull($organisation2, 'The second organisation was instantiated with the same name as the first: please rectify so that this becomes impossible'); } catch (Exception $e) { $this->assertNull($organisation2, "This should be unreachable if organisation 2 is not null"); } }
/** * Create a list of all notifications * @param Person $user a user * @param Organisation $organisation an organisation * @param Vacancy $vacancy a vacancy * @return Response */ public function listNotificationsAction($user, $organisation = null, $vacancy = null) { $digestNotifications = []; $qb = $this->getDoctrine()->getManager()->createQueryBuilder(); $qb->select(array('dE'))->from('AppBundle:DigestEntry', 'dE')->where($qb->expr()->andX($qb->expr()->eq('dE.handled', 0), $qb->expr()->eq('dE.user', $user->getId()), $qb->expr()->neq('dE.event', 1))); if ($organisation) { $qb->where('dE.Organisation = :organisation')->setParameter('organisation', $organisation->getId()); } if ($vacancy) { $qb->where('dE.vacancy = :vacancy')->setParameter('vacancy', $vacancy->getId()); } $qb->add('orderBy', 'dE.id DESC'); $digests = $qb->getQuery()->getResult(); foreach ($digests as $digest) { $textAndActionLink = $this->getTextAndActionLinkForEvent($digest); array_push($digestNotifications, $textAndActionLink); } return $this->render("person/persoon_notificaties.html.twig", ["notifications" => $digestNotifications]); }