Newscoop\GimmeBundle\Controller\ArticlesController::unlinkArticleAction PHP Method

unlinkArticleAction() public method

**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: "" **slideshows headers**: header name: "link" header value: ""
public unlinkArticleAction ( Request $request, $number, $language = null ) : Article
$request Symfony\Component\HttpFoundation\Request
return Article
    public function unlinkArticleAction(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) {
            $resourceType = $objectArray['resourceType'];
            $object = $objectArray['object'];
            if ($object instanceof \Exception) {
                throw $object;
            }
            if ($object instanceof \Newscoop\Image\LocalImage) {
                $imagesService = $this->get('image');
                $articleImage = $em->getRepository('Newscoop\\Image\\ArticleImage')->getArticleImage($article->getNumber(), $object)->getOneOrNullResult();
                if ($articleImage) {
                    $imagesService->removeArticleImage($articleImage);
                } else {
                    throw new InvalidParametersException('Image is not linked to article');
                }
                $matched = true;
                continue;
            }
            if ($object instanceof \Newscoop\Entity\Attachment) {
                $attachmentService = $this->get('attachment');
                $attachmentService->removeAttachmentFormArticle($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->removeAuthorFromArticle($article, $object, $authorType);
                    $matched = true;
                }
                continue;
            }
            if ($object instanceof \Newscoop\Entity\Snippet) {
                $snippetRepo = $em->getRepository('Newscoop\\Entity\\Snippet');
                $snippetRepo->removeSnippetFromArticle($object, $article);
                $matched = true;
                continue;
            }
            if ($object instanceof \Newscoop\NewscoopBundle\Entity\Topic) {
                $topicService = $this->get('newscoop_newscoop.topic_service');
                $topicService->removeTopicFromArticle($object, $article);
                $matched = true;
                continue;
            }
            if ($object instanceof \Newscoop\Entity\Article) {
                $relatedArticlesService = $this->get('related_articles');
                $relatedArticlesService->removeRelatedArticle($article, $object);
                $matched = true;
                continue;
            }
            if ($object instanceof \Newscoop\Package\Package) {
                $packageService = $this->get('package');
                $packageService->removeFromArticle($object, $article->getNumber());
                $matched = true;
                continue;
            }
        }
        if ($matched === false) {
            throw new InvalidParametersException('Any supported unlink object not found');
        }
        return $article;
    }