Ojs\JournalBundle\Controller\IssueController::addArticleAction PHP Метод

addArticleAction() публичный Метод

add article to this issue
public addArticleAction ( Request $request, integer $id, integer $articleId ) : RedirectResponse
$request Symfony\Component\HttpFoundation\Request
$id integer
$articleId integer
Результат Symfony\Component\HttpFoundation\RedirectResponse
    public function addArticleAction(Request $request, $id, $articleId)
    {
        $journal = $this->get('ojs.journal_service')->getSelectedJournal();
        if (!$this->isGranted('EDIT', $journal, 'issues')) {
            throw new AccessDeniedException("You are not authorized for edit this journal's issue!");
        }
        $em = $this->getDoctrine()->getManager();
        /** @var Issue $issue */
        $issue = $em->getRepository('OjsJournalBundle:Issue')->find($id);
        $this->throw404IfNotFound($issue);
        $selectedSection = $request->get('section', null);
        /** @var Article $article */
        $article = $em->getRepository('OjsJournalBundle:Article')->find($articleId);
        $this->throw404IfNotFound($article);
        $section = null;
        if ($selectedSection) {
            /** @var Section $section */
            $section = $em->getRepository('OjsJournalBundle:Section')->find($selectedSection);
            $this->throw404IfNotFound($section);
        }
        $article->setIssue($issue);
        $article->setStatus(ArticleStatuses::STATUS_PUBLISHED);
        if ($section) {
            $sections = $issue->getSections();
            if (!$sections->contains($section)) {
                $issue->addSection($section);
                $em->persist($issue);
            }
            $article->setSection($section);
        }
        $em->persist($article);
        $em->flush();
        $this->successFlashBag('successfully.article.added.to.issue');
        return $this->redirect($request->headers->get('referer'));
    }