Exemplo n.º 1
0
 /**
  * Sends the email to a specific lead
  *
  * @param int $id     Email ID
  * @param int $leadId Lead ID
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 public function sendLeadAction($id, $leadId)
 {
     $entity = $this->model->getEntity($id);
     if (null !== $entity) {
         if (!$this->checkEntityAccess($entity, 'view')) {
             return $this->accessDenied();
         }
         $leadModel = $this->getModel('lead');
         $lead = $leadModel->getEntity($leadId);
         if ($lead == null) {
             return $this->notFound();
         } elseif (!$this->security->hasEntityAccess('lead:leads:viewown', 'lead:leads:viewother', $lead->getOwner())) {
             return $this->accessDenied();
         }
         $post = $this->request->request->all();
         $tokens = !empty($post['tokens']) ? $post['tokens'] : array();
         $cleantokens = array_map(function ($v) {
             return InputHelper::clean($v);
         }, $tokens);
         $leadFields = array_merge(array('id' => $leadId), $leadModel->flattenFields($lead->getFields()));
         if (MailHelper::applyFrequencyRules($lead)) {
             $this->model->sendEmail($entity, $leadFields, array('source' => array('api', 0), 'tokens' => $cleantokens));
         }
         $view = $this->view(array('success' => 1), Codes::HTTP_OK);
         return $this->handleView($view);
     }
     return $this->notFound();
 }