Esempio n. 1
0
 public function editAction($mid)
 {
     $success = true;
     $errors = array();
     $em = $this->get('doctrine')->getManager();
     $repo = $em->getRepository('TuxCoffeeCornerCoreBundle:Mail');
     $mail = $repo->findOneBy(array('id_mail' => $mid));
     if (!$mail) {
         $mail = new Mail();
     }
     $mail->setIdentifier($_POST['identifier']);
     $mail->setSubject($_POST['subject']);
     $mail->setBody($_POST['body']);
     $mail->setTo($_POST['to']);
     $mail->setCc($_POST['cc']);
     $mail->setFrom($_POST['from']);
     $postErrors = $this->get('validator')->validate($mail);
     if (count($postErrors) > 0) {
         $success = false;
         foreach ($postErrors as $error) {
             $errors[] = $error->getMessage();
         }
     } else {
         $em->persist($mail);
         try {
             $em->flush();
         } catch (\Exception $e) {
             $success = false;
             $errors[] = '<b>Uuuh! Some nasty database exception caught:</b> ' . $e->getMessage() . "\n";
         }
     }
     $message = $this->render("TuxCoffeeCornerCoreBundle:adminPages/snippets:" . ($success ? "successMsg" : "errorMsg") . ".html.php", array('errors' => $errors))->getContent();
     return new Response(json_encode(array('success' => $success, 'message' => $message)), 200, array('content-type' => 'application/json'));
 }