/** * Fetches the journal user * @param array $cache User cache * @param String $email User's email * @param Journal $journal Journal * @return JournalUser Imported or retrieved JournalUser */ private function getJournalUser(&$cache, $email, $journal) { if (!empty($cache[$email]['journal_user'])) { return $cache[$email]['journal_user']; } $journalUser = $this->em->getRepository('OjsJournalBundle:JournalUser')->findOneBy(['journal' => $journal, 'user' => $cache[$email]['user']]); if ($journalUser === null) { $journalUser = new JournalUser(); $journalUser->setUser($cache[$email]['user']); $journalUser->setJournal($journal); $this->em->persist($journalUser); } $cache[$email]['journal_user'] = $journalUser; return $cache[$email]['journal_user']; }
/** * @param Request $request * @param $articleId * @return RedirectResponse|Response * @throws \Exception */ public function previewAction(Request $request, $articleId) { if ($this->submissionsNotAllowed()) { return $this->respondAsNotAllowed(); } $journal = $this->get('ojs.journal_service')->getSelectedJournal(); $em = $this->getDoctrine()->getManager(); $dispatcher = $this->get('event_dispatcher'); $session = $this->get('session'); /** @var User $user */ $user = $this->getUser(); if (!$journal) { $this->throw404IfNotFound($journal); } /** @var ArticleRepository $articleRepository */ $articleRepository = $em->getRepository('OjsJournalBundle:Article'); /** @var Article $article */ $article = $articleRepository->findOneBy(array('id' => $articleId, 'submitterUser' => $user, 'status' => ArticleStatuses::STATUS_NOT_SUBMITTED)); $this->throw404IfNotFound($article); $form = $this->createForm(new ArticlePreviewType(), $article, array('action' => $this->generateUrl('ojs_journal_submission_preview', array('journalId' => $journal->getId(), 'articleId' => $article->getId())), 'method' => 'POST'))->add('submit', 'submit', array('label' => 'article.submit', 'attr' => ['class' => 'btn-block'])); $form->handleRequest($request); $validator = $this->get('validator'); $draftErrors = $validator->validate($article, null, ['groups' => 'submission']); if ($form->isValid() && count($draftErrors) == 0) { if ($session->has('submissionFiles')) { $session->remove('submissionFiles'); } $article->setStatus(ArticleStatuses::STATUS_INREVIEW); $article->setSubmissionDate(new \DateTime()); $em->persist($article); // Assign user to author journal role /** @var Role $role */ $role = $em->getRepository('OjsUserBundle:Role')->findOneBy(['role' => 'ROLE_AUTHOR']); /** @var JournalUser $journalUser */ $journalUser = $em->getRepository('OjsJournalBundle:JournalUser')->findOneBy(array('user' => $user)); if (!$journalUser) { $journalUser = new JournalUser(); $journalUser->setJournal($journal)->setUser($user); } $journalUser->addRole($role); $em->persist($journalUser); $em->flush(); $response = $this->redirectToRoute('ojs_journal_submission_me', ['journalId' => $article->getJournal()->getId()]); $event = new JournalItemEvent($article); $dispatcher->dispatch(ArticleEvents::POST_SUBMIT, $event); if (null !== $event->getResponse()) { return $event->getResponse(); } return $response; } return $this->render('OjsJournalBundle:ArticleSubmission:preview.html.twig', array('article' => $article, 'journal' => $journal, 'translations' => $article->getTranslations(), 'fileTypes' => ArticleFileParams::$FILE_TYPES, 'form' => $form->createView(), 'draftErrors' => $draftErrors)); }
/** * Creates a new User entity. * * @param Request $request * @return RedirectResponse|Response */ public function createUserAction(Request $request) { $journal = $this->get('ojs.journal_service')->getSelectedJournal(); $eventDispatcher = $this->get('event_dispatcher'); if (!$this->isGranted('CREATE', $journal, 'userRole')) { throw new AccessDeniedException("You are not authorized for this page!"); } $entity = new User(); $form = $this->createCreateForm($entity, $journal->getId()); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $factory = $this->get('security.encoder_factory'); $encoder = $factory->getEncoder($entity); $password = $encoder->encodePassword($entity->getPassword(), $entity->getSalt()); $entity->setPassword($password); $entity->setEnabled(true); $em->persist($entity); $journalUser = new JournalUser(); $journalUser->setUser($entity); $journalUser->setJournal($journal); $event = new JournalItemEvent($journalUser); $eventDispatcher->dispatch(JournalUserEvents::PRE_CREATE, $event); $em->persist($event->getItem()); $em->flush(); $event = new JournalItemEvent($event->getItem()); $eventDispatcher->dispatch(JournalUserEvents::POST_CREATE, $event); if ($event->getResponse()) { return $event->getResponse(); } $this->successFlashBag('successful.create'); return $this->redirectToRoute('ojs_journal_user_edit', ['journalId' => $journal->getId(), 'id' => $journalUser->getId()]); } return $this->render('OjsJournalBundle:JournalUser:new.html.twig', array('entity' => $entity, 'form' => $form->createView())); }
/** * Creates a new User entity. * * @param Request $request * @return RedirectResponse|Response */ public function createUserAction(Request $request) { $journal = $this->get('ojs.journal_service')->getSelectedJournal(); if (!$this->isGranted('CREATE', $journal, 'userRole')) { throw new AccessDeniedException("You are not authorized for this page!"); } $entity = new User(); $form = $this->createCreateForm($entity, $journal->getId()); $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $formData = $form->getData(); $factory = $this->get('security.encoder_factory'); $encoder = $factory->getEncoder($entity); $password = $encoder->encodePassword($entity->getPassword(), $entity->getSalt()); $entity->setPassword($password); $entity->setAvatar($request->get('user_avatar')); $em->persist($entity); $journalUser = new JournalUser(); $journalUser->setUser($entity); $journalUser->setJournal($journal); if (count($formData->getJournalRoles()) > 0) { $journalUser->setRoles($formData->getJournalRoles()); } $em->persist($journalUser); $em->flush(); $this->successFlashBag('successful.create'); return $this->redirectToRoute('ojs_journal_user_index', ['journalId' => $journal->getId()]); } return $this->render('OjsJournalBundle:JournalUser:new.html.twig', array('entity' => $entity, 'form' => $form->createView())); }