Newscoop\Services\RelatedArticlesService::addArticle PHP Method

addArticle() public method

Add new related article to related articles container
public addArticle ( Article $article, Article $articleToAdd, integer $position = false ) : boolean
$article Newscoop\Entity\Article
$articleToAdd Newscoop\Entity\Article
$position integer
return boolean
    public function addArticle($article, $articleToAdd, $position = false)
    {
        $relatedArticles = $this->findRelatedArticlesBox($article);
        $relatedArticle = $this->em->getRepository('Newscoop\\Entity\\RelatedArticle')->getRelatedArticle($relatedArticles, $articleToAdd->getNumber())->getOneOrNullResult();
        if ($relatedArticle) {
            $this->positionRelateArticle($relatedArticles, $relatedArticle, $position);
            return true;
        }
        $relatedArticle = new RelatedArticle($relatedArticles->getId(), $articleToAdd->getNumber());
        $this->em->persist($relatedArticle);
        $this->em->flush();
        $this->positionRelateArticle($relatedArticles, $relatedArticle, $position);
        return true;
    }