/**
  * {@inheritDoc}
  */
 public function getEmailList()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getEmailList', array());
     return parent::getEmailList();
 }
 public function editemailcontentAction(Request $request)
 {
     /****** Admin session checking**********/
     $response = $this->checkAdmin($request->getSession());
     if ($response) {
         return $response;
     }
     $em = $this->getDoctrine()->getManager();
     $lan = $this->container->get('request')->get('lan');
     $id = $this->container->get('request')->get('id');
     $checkquery = $em->createQuery("SELECT p FROM MytripAdminBundle:Language  p WHERE p.lanCode='" . $lan . "'");
     $checklanguage = $checkquery->getArrayResult();
     if (empty($checklanguage)) {
         return $this->redirect($this->generateUrl('mytrip_admin_editemailcontent', array('id' => $id, 'lan' => 'en')));
     }
     if ($request->getMethod() == "POST") {
         if ($lan == "en") {
             $repository = $em->getRepository('MytripAdminBundle:EmailList');
             $emaillist = $repository->findOneByEmailListId($id);
             $emaillist->setTitle($request->request->get('title'));
             $emaillist->setFromname($request->request->get('fromname'));
             $emaillist->setFromemail($request->request->get('fromemail'));
             $emaillist->setTomail($request->request->get('tomail'));
             $emaillist->setCcmail($request->request->get('ccmail'));
         }
         $em = $this->getDoctrine()->getManager();
         $check = $em->createQuery("SELECT p FROM MytripAdminBundle:EmailContent p WHERE p.emailList=" . $id . " AND p.lan='" . $lan . "'");
         $check_content = $check->getArrayResult();
         if (!empty($check_content)) {
             $repository_content = $em->getRepository('MytripAdminBundle:EmailContent');
             $check_contents = $repository_content->findOneByEmailContentId($check_content['0']['emailContentId']);
             $check_contents->setSubject($request->request->get('subject'));
             $check_contents->setEmailcontent($request->request->get('emailcontent'));
         } else {
             $check_contents = new EmailContent();
             $check_contents->setEmailList($this->getDoctrine()->getRepository('MytripAdminBundle:EmailList')->find($id));
             $check_contents->setSubject($request->request->get('subject'));
             $check_contents->setEmailcontent($request->request->get('emailcontent'));
             $check_contents->setLan($lan);
             $em->persist($check_contents);
         }
         $em->flush();
         $this->get('session')->getFlashBag()->add('error', '<div class="success msg">Email Content successfully updated</div>');
         return $this->redirect($this->generateUrl('mytrip_admin_editemailcontent', array('id' => $id, 'lan' => $lan)));
     }
     /******Fetch language********/
     $query = $em->createQuery("SELECT p FROM MytripAdminBundle:Language  p ");
     $language = $query->getArrayResult();
     /*******Fetch Email content details*****/
     $email_query = $em->createQuery("SELECT p FROM MytripAdminBundle:EmailList  p WHERE p.emailListId=" . $id);
     $emaillist = $email_query->getArrayResult();
     if (empty($emaillist)) {
         return $this->redirect($this->generateUrl('mytrip_admin_emailcontent'));
     }
     /*******Fetch Email content content details*****/
     $email_content_query = $em->createQuery("SELECT p FROM MytripAdminBundle:EmailContent p WHERE p.emailList=" . $id . " AND p.lan='" . $lan . "'");
     $email_content = $email_content_query->getArrayResult();
     if (empty($email_content)) {
         $email_content_query = $em->createQuery("SELECT p FROM MytripAdminBundle:EmailContent p WHERE p.emailList=" . $id . " AND p.lan='en'");
         $email_content = $email_content_query->getArrayResult();
     }
     return $this->render('MytripAdminBundle:Default:editemailcontent.html.php', array('language' => $language, 'emaillist' => $emaillist, 'email_content' => $email_content));
 }