public function addMultipleMailAction(Request $request, $id = null)
{
/** @var User $user */
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
if ($id) {
/** @var MultipleMail $multipleMail */
$multipleMail = $em->find('OjsUserBundle:MultipleMail', $id);
if (!$multipleMail) {
throw new NotFoundException();
}
if ($multipleMail->getUserId() != $user->getId()) {
throw new AccessDeniedException();
}
} else {
$multipleMail = new MultipleMail();
}
$multipleMailForm = $this->createForm(new MultipleMailType(), $multipleMail);
if ($request->isMethod('POST')) {
$multipleMailForm->handleRequest($request);
if ($multipleMailForm->isValid()) {
$multipleMail->setUser($user);
$em->persist($multipleMail);
$em->flush();
return $this->redirectToRoute('ojs_user_multiple_mail');
} else {
$this->errorFlashBag('error.oops');
}
}
return $this->render("OjsUserBundle:MultipleMail:add_multiple_mail.html.twig", ['form' => $multipleMailForm->createView()]);
}