Ojs\ApiBundle\Controller\Journal\JournalIssueRestController::getAddArticleAction PHP Method

getAddArticleAction() public method

Add article to issue
public getAddArticleAction ( Request $request, integer $issueId, integer $articleId, integer $sectionId ) : Symfony\Component\Form\FormTypeInterface | FOS\RestBundle\Controller\Annotations\View
$request Symfony\Component\HttpFoundation\Request the request object
$issueId integer the Issue id
$articleId integer the Article id
$sectionId integer the Section id
return Symfony\Component\Form\FormTypeInterface | FOS\RestBundle\Controller\Annotations\View
    public function getAddArticleAction(Request $request, $issueId, $articleId, $sectionId)
    {
        $journal = $this->get('ojs.journal_service')->getSelectedJournal();
        if (!$this->isGranted('CREATE', $journal, 'issues')) {
            throw new AccessDeniedException();
        }
        $em = $this->getDoctrine()->getManager();
        /** @var Issue $issue */
        $issue = $this->getOr404($issueId);
        /** @var Article $article */
        $article = $em->getRepository('OjsJournalBundle:Article')->find($articleId);
        $this->throw404IfNotFound($article, 'article not found');
        $section = $em->getRepository('OjsJournalBundle:Section')->find($sectionId);
        $this->throw404IfNotFound($section, 'please specify section');
        $article->setIssue($issue);
        $article->setStatus(ArticleStatuses::STATUS_PUBLISHED);
        $sections = $issue->getSections();
        if (!$sections->contains($section)) {
            $issue->addSection($section);
            $em->persist($issue);
        }
        $article->setSection($section);
        $em->persist($article);
        $em->flush();
        return $this->view(['success' => true, 'message' => 'successfully arranged article to issue']);
    }