Ojs\ApiBundle\Controller\Journal\JournalArticleFileRestController::putFileAction PHP Method

putFileAction() public method

Update existing ArticleFile from the submitted data or create a new ArticleFile at a specific location.
public putFileAction ( Request $request, integer $id ) : Symfony\Component\Form\FormTypeInterface | FOS\RestBundle\Controller\Annotations\View
$request Symfony\Component\HttpFoundation\Request the request object
$id integer the ArticleFile id
return Symfony\Component\Form\FormTypeInterface | FOS\RestBundle\Controller\Annotations\View
    public function putFileAction(Request $request, $id)
    {
        $journal = $this->get('ojs.journal_service')->getSelectedJournal();
        if (!$this->isGranted('CREATE', $journal, 'articles')) {
            throw new AccessDeniedException();
        }
        try {
            $journalService = $this->container->get('ojs.journal_service');
            if (!($entity = $this->container->get('ojs_api.journal_article_file.handler')->get($id))) {
                $statusCode = Codes::HTTP_CREATED;
                $entity = $this->container->get('ojs_api.journal_article_file.handler')->post($request->request->all());
            } else {
                $statusCode = Codes::HTTP_NO_CONTENT;
                $entity = $this->container->get('ojs_api.journal_article_file.handler')->put($entity, $request->request->all());
            }
            $routeOptions = array('id' => $entity->getId(), 'journalId' => $journalService->getSelectedJournal()->getId(), 'articleId' => $entity->getArticle()->getId(), '_format' => $request->get('_format'));
            return $this->routeRedirectView('api_1_article_get_file', $routeOptions, $statusCode);
        } catch (InvalidFormException $exception) {
            return $exception->getForm();
        }
    }