/**
* 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')->findOneByUser($user);
if (!$journalSetup) {
$newJournal = new Journal();
$newJournal->setTitle('');
$newJournal->setTitleAbbr('');
$newJournal->setSetupStatus(false);
$em->persist($newJournal);
$journalSetup = new JournalSetupProgress();
$journalSetup->setUser($user);
$journalSetup->setCurrentStep(1);
$journalSetup->setJournal($newJournal);
$em->persist($journalSetup);
$em->flush();
}
} elseif (!$selectedJournal->getSetupStatus()) {
/** @var JournalSetupProgress $userSetup */
$journalSetup = $em->getRepository('OjsJournalBundle:JournalSetupProgress')->findOneByJournal($selectedJournal);
} elseif ($selectedJournal->getSetupStatus()) {
$selectedJournal->setSetupStatus(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());
}