/** * Get the validation errors * * @param ConstraintViolationList $errors Validator error list * * @return FOSView */ protected function getValidationErrorsView($errors) { $msgs = array(); $it = $errors->getIterator(); foreach ($it as $val) { $msg = $val->getMessage(); $params = $val->getMessageParameters(); //using FOSUserBundle translator domain 'validators' $msgs[$val->getPropertyPath()][] = $this->get('translator')->trans($msg, $params, 'validators'); } $data = array("status" => "error", "status_code" => 400, "status_text" => "Bad Request", "current_content" => "", "message" => $msgs); $view = FOSView::create($data); $view->setStatusCode(400); return $view; }
/** * Get the validation errors. * * @param ConstraintViolationList $errors Validator error list * * @return View */ protected function getErrorsView(ConstraintViolationList $errors) { $msgs = array(); $errorIterator = $errors->getIterator(); foreach ($errorIterator as $validationError) { $msg = $validationError->getMessage(); $params = $validationError->getMessageParameters(); $msgs[$validationError->getPropertyPath()][] = $this->get('translator')->trans($msg, $params, 'validators'); } $view = View::create($msgs); $view->setStatusCode(400); return $view; }
/** * Get the validation errors * * @param ConstraintViolationList $errors Validator error list * * @return FOSView */ private function get_errors_view($errors) { $msgs = array(); $it = $errors->getIterator(); //$val = new \Symfony\Component\Validator\ConstraintViolation(); foreach ($it as $val) { $msg = $val->getMessage(); $params = $val->getMessageParameters(); //using FOSUserBundle translator domain 'validators' $msgs[$val->getPropertyPath()][] = $this->get('translator')->trans($msg, $params, 'validators'); } $view = FOSView::create($msgs); $view->setStatusCode(400); return $view; }
/** * Send Email To Patient * * @param VitalSign $vitalSign - Vital Sign * @param string $email - Optionally override email address */ public function sendEmailToPatient($vitalSign, $email = null) { $user = $this->securityContext->getToken()->getUser(); $errors = new ConstraintViolationList(); if (!$email) { $email = $vitalSign->getPatient()->getPrimaryEmail(); if (!$email) { $errors->add(new ConstraintViolation('This field is required as patient does not have email.', '', array(), '', 'email', null)); } } $emailConstraint = new EmailConstraint(); $errorList = $this->validator->validateValue($email, $emailConstraint); foreach ($errorList as $error) { $errors->add(new ConstraintViolation($error->getMessage(), '', array(), '', 'email', null)); } if (0 < count($errors)) { throw new ValidationError($errors); } $serializedVitalSign = serialize($vitalSign); $payload = array('host' => $this->practoDomain->getHost(), 'reason' => 'vital_sign', 'vital_sign' => $serializedVitalSign, 'recipient_type' => 'patient', 'email' => $email, 'user_id' => $user->getId()); $this->emailProducer->publish(json_encode($payload), explode('.', explode('/', $payload['host'])[2])[0]); }