Exemplo n.º 1
0
 /**
  * Generate's new note and processes post data
  *
  * @param $leadId
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function newAction($leadId)
 {
     $lead = $this->checkLeadAccess($leadId, 'view');
     if ($lead instanceof Response) {
         return $lead;
     }
     //retrieve the entity
     $note = new LeadNote();
     $note->setLead($lead);
     $model = $this->factory->getModel('lead.note');
     $action = $this->generateUrl('mautic_leadnote_action', array('objectAction' => 'new', 'leadId' => $leadId));
     //get the user form factory
     $form = $model->createForm($note, $this->get('form.factory'), $action);
     $closeModal = false;
     $valid = false;
     ///Check for a submitted form and process it
     if ($this->request->getMethod() == 'POST') {
         if (!($cancelled = $this->isFormCancelled($form))) {
             if ($valid = $this->isFormValid($form)) {
                 $closeModal = true;
                 //form is valid so process the data
                 $model->saveEntity($note);
             }
         } else {
             $closeModal = true;
         }
     }
     $security = $this->factory->getSecurity();
     $permissions = array('edit' => $security->hasEntityAccess('lead:leads:editown', 'lead:leads:editother', $lead->getOwner()), 'delete' => $security->hasEntityAccess('lead:leads:deleteown', 'lead:leads:deleteown', $lead->getOwner()));
     if ($closeModal) {
         //just close the modal
         $passthroughVars = array('closeModal' => 1, 'mauticContent' => 'leadNote');
         if ($valid && !$cancelled) {
             $passthroughVars['upNoteCount'] = 1;
             $passthroughVars['noteHtml'] = $this->renderView('MauticLeadBundle:Note:note.html.php', array('note' => $note, 'lead' => $lead, 'permissions' => $permissions));
             $passthroughVars['noteId'] = $note->getId();
         }
         $response = new JsonResponse($passthroughVars);
         $response->headers->set('Content-Length', strlen($response->getContent()));
         return $response;
     } else {
         return $this->delegateView(array('viewParameters' => array('form' => $form->createView(), 'lead' => $lead, 'permissions' => $permissions), 'contentTemplate' => 'MauticLeadBundle:Note:form.html.php'));
     }
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }