Пример #1
0
 /**
  * REST GET email template
  *
  * @param EmailTemplate $emailTemplate  comes from request parameter {id}
  *                                      that transformed to entity by param converter
  * @param int           $entityId       entity id of class defined by $emailTemplate->getEntityName()
  *
  * @ApiDoc(
  *     description="Get email template subject, type and content",
  *     resource=true
  * )
  * @AclAncestor("oro_email_emailtemplate_view")
  * @Get("/emailtemplates/compiled/{id}/{entityId}",
  *      requirements={"id"="\d+", "entityId"="\d*"},
  *      name="oro_api_get_emailtemplate_compiled"
  * )
  * @ParamConverter("emailTemplate", class="OroEmailBundle:EmailTemplate")
  *
  * @return Response
  */
 public function getCompiledAction(EmailTemplate $emailTemplate, $entityId = null)
 {
     $templateParams = [];
     if ($entityId && $emailTemplate->getEntityName()) {
         $entity = $this->getDoctrine()->getRepository($emailTemplate->getEntityName())->find($entityId);
         if ($entity) {
             $templateParams['entity'] = $entity;
         }
     }
     // no entity found, but entity name defined for template
     if ($emailTemplate->getEntityName() && !isset($templateParams['entity'])) {
         return $this->handleView($this->view(['message' => sprintf('entity %s with id=%d not found', $emailTemplate->getEntityName(), $entityId)], Codes::HTTP_NOT_FOUND));
     }
     list($subject, $body) = $this->get('oro_email.email_renderer')->compileMessage($emailTemplate, $templateParams);
     $data = ['subject' => $subject, 'body' => $body, 'type' => $emailTemplate->getType()];
     return $this->handleView($this->view($data, Codes::HTTP_OK));
 }