/** * Admin can create new journal. * admin can resume from where he/she left. * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function indexAction() { $user = $this->getUser(); $em = $this->getDoctrine()->getManager(); $journalCreatePermission = $this->isGranted('CREATE', new Journal()); /** @var Journal $selectedJournal */ $selectedJournal = $this->get("ojs.journal_service")->getSelectedJournal(); $selectedJournalEditPermission = $this->isGranted('EDIT', $selectedJournal); if (!$journalCreatePermission && !$selectedJournalEditPermission) { throw new AccessDeniedException(); } if (!$selectedJournal && !$journalCreatePermission) { throw new NotFoundHttpException(); } $journalSetup = new JournalSetupProgress(); if ($journalCreatePermission) { /** @var JournalSetupProgress $journalSetup */ $journalSetup = $em->getRepository('OjsJournalBundle:JournalSetupProgress')->findOneBy(array('user' => $user)); if (!$journalSetup) { $newJournal = new Journal(); $newJournal->setTitle(''); $newJournal->setTitleAbbr(''); $newJournal->setSetupFinished(false); $em->persist($newJournal); $journalSetup = new JournalSetupProgress(); $journalSetup->setUser($user); $journalSetup->setCurrentStep(1); $journalSetup->setJournal($newJournal); $em->persist($journalSetup); $em->flush(); } } elseif (!$selectedJournal->isSetupFinished()) { /** @var JournalSetupProgress $userSetup */ $journalSetup = $em->getRepository('OjsJournalBundle:JournalSetupProgress')->findOneBy(array('journal' => $selectedJournal)); } elseif ($selectedJournal->isSetupFinished()) { $selectedJournal->setSetupFinished(false); $journalSetup->setUser($user); $journalSetup->setJournal($selectedJournal); $journalSetup->setCurrentStep(1); $em->persist($journalSetup); $em->flush(); } return $this->redirect($this->generateUrl('ojs_journal_setup_resume', ['setupId' => $journalSetup->getId()]) . '#' . $journalSetup->getCurrentStep()); }