Ejemplo n.º 1
0
 public function getSubscriptorFromType(NewsletterShipping $entity)
 {
     $emailArray = array();
     $em = $this->container->get('doctrine')->getManager();
     $query = null;
     if ($entity->getType() == NewsletterShipping::TYPE_SUBSCRIPTS) {
         $query = ' SELECT a' . ' FROM CoreBundle:NewsletterSubscription a';
     } elseif ($entity->getType() == NewsletterShipping::TYPE_USER) {
         $query = ' SELECT a' . ' FROM CoreBundle:Actor a' . " WHERE a.newsletter =  true ";
     }
     if (is_null($query)) {
         throw $this->createNotFoundException('No type found');
     }
     $q = $em->createQuery($query);
     $entities = $q->getResult();
     foreach ($entities as $value) {
         ///////////////////////////////////////////////////
         ///////////////// test case ///////////////////////
         ///////////////////////////////////////////////////
         //            $core = $this->getParameter('core');
         //            if(preg_match($core['xpath_email'], $value->getEmail())){
         $emailArray[] = $value->getEmail();
         //            }
     }
     return $emailArray;
 }
Ejemplo 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());
 }
Ejemplo n.º 3
0
 /**
  * Add shipping
  *
  * @param Shipping $shipping
  *
  * @return Actor
  */
 public function addShipping(NewsletterShipping $shipping)
 {
     $shipping->setActor($this);
     $this->shippings->add($shipping);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Creates a form to delete a MenuItem entity.
  *
  * @param Newsletter $newsletter The Newsletter entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createNShippingDeleteForm(NewsletterShipping $nshipping)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('core_newsletter_deleteshipping', array('id' => $nshipping->getId())))->setMethod('DELETE')->getForm();
 }