Newscoop\GimmeBundle\Controller\ArticlesController::linkArticleAction PHP Метод

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

**article authors headers**: header name: "link" header value: "," **attachments headers**: header name: "link" header value: "" **images headers**: header name: "link" header value: "" **topics headers**: header name: "link" header value: "" **related articles headers**: header name: "link" header value: "" or with specific language header value: "" you can also specify position on list header value: ",<1; rel="article-position">"
public linkArticleAction ( Request $request, $number, $language = null ) : Article
$request Symfony\Component\HttpFoundation\Request
Результат Article
    public function linkArticleAction(Request $request, $number, $language = null)
    {
        $em = $this->container->get('em');
        $publication = $this->get('newscoop.publication_service')->getPublication();
        $article = $em->getRepository('Newscoop\\Entity\\Article')->getArticle($number, $request->get('language', $publication->getLanguage()->getCode()))->getOneOrNullResult();
        if (!$article) {
            throw new NotFoundHttpException('Article was not found');
        }
        $matched = false;
        foreach ($request->attributes->get('links', array()) as $key => $objectArray) {
            if (!is_array($objectArray)) {
                return true;
            }
            $resourceType = $objectArray['resourceType'];
            $object = $objectArray['object'];
            if ($object instanceof \Exception) {
                throw $object;
            }
            if ($object instanceof \Newscoop\Image\LocalImage) {
                $imagesService = $this->get('image');
                $imagesService->addArticleImage($article->getNumber(), $object);
                $matched = true;
                continue;
            }
            if ($object instanceof \Newscoop\Entity\Attachment) {
                $attachmentService = $this->get('attachment');
                $attachmentService->addAttachmentToArticle($article, $object);
                $matched = true;
                continue;
            }
            if ($object instanceof \Newscoop\Entity\Author) {
                $authorService = $this->get('author');
                $authorType = false;
                foreach ($request->attributes->get('links') as $key => $tempObjectArray) {
                    if ($tempObjectArray['object'] instanceof \Newscoop\Entity\AuthorType) {
                        $authorType = $tempObjectArray['object'];
                    }
                }
                if ($authorType) {
                    $authorService->addAuthorToArticle($article, $object, $authorType);
                    $matched = true;
                }
                continue;
            }
            if ($object instanceof \Newscoop\Entity\Snippet) {
                $snippetRepo = $em->getRepository('Newscoop\\Entity\\Snippet');
                $snippetRepo->addSnippetToArticle($object, $article);
                $matched = true;
                continue;
            }
            if ($object instanceof \Newscoop\NewscoopBundle\Entity\Topic) {
                $topicService = $this->get('newscoop_newscoop.topic_service');
                $topicService->addTopicToArticle($object, $article);
                $matched = true;
                continue;
            }
            if ($object instanceof \Newscoop\Entity\Article) {
                $relatedArticlesService = $this->get('related_articles');
                $position = false;
                if (count($notConvertedLinks = $this->getNotConvertedLinks($request)) > 0) {
                    foreach ($notConvertedLinks as $link) {
                        if (isset($link['resourceType']) && $link['resourceType'] == 'article-position') {
                            $position = $link['resource'];
                        }
                    }
                }
                $relatedArticlesService->addArticle($article, $object, $position);
                $matched = true;
                continue;
            }
        }
        if ($matched === false) {
            throw new InvalidParametersException('Any supported link object not found');
        }
        return $article;
    }