Exemplo n.º 1
0
 /**
  * Add shipping
  *
  * @param Shipping $shipping
  *
  * @return Actor
  */
 public function addShipping(NewsletterShipping $shipping)
 {
     $shipping->setActor($this);
     $this->shippings->add($shipping);
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Creates a new Newsletter entity.
  *
  * @param Request $request The request
  *
  * @return array|RedirectResponse
  *
  * @Route("/admin/actor/{id}/email")
  * @Template("CoreBundle:Actor:email.html.twig")
  */
 public function emailAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var Newsletter $entity */
     $entity = $em->getRepository('CoreBundle:Actor')->find($id);
     $form = $this->createForm(new ActorEmailType(array('email' => $entity->getEmail())));
     if ($request->getMethod() == 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             //Get params
             $data = $form->getData();
             $email = $data['email'];
             if ($entity->getEmail() == $email) {
                 $news = new Newsletter();
                 $news->setTitle($data['subject']);
                 $news->setBody($data['body']);
                 $news->setActive(true);
                 $em->persist($news);
                 $shipping = new NewsletterShipping();
                 $shipping->setNewsletter($news);
                 $shipping->setActor($entity);
                 $shipping->setTotalSent(1);
                 $shipping->setType(NewsletterShipping::TYPE_PERSONAL);
                 $em->persist($shipping);
                 $em->flush();
                 $this->get('core.mailer')->sendActorEmail($email, $data['subject'], $data['body']);
                 //if come from popup
                 if ($request->isXMLHttpRequest()) {
                     return new JsonResponse(array('id' => $shipping->getId()));
                 }
                 $this->get('session')->getFlashBag()->add('success', 'user.email.created');
                 return $this->redirect($this->generateUrl('core_actor_show', array('id' => $entity->getId())));
             }
         }
     }
     return array('entity' => $entity, 'form' => $form->createView());
 }