Newscoop\Services\AuthorService::addAuthorToArticle PHP Метод

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

Add author with type to article
public addAuthorToArticle ( Article $article, Author $author, AuthorType $authorType ) : ArticleAuthor
$article Newscoop\Entity\Article
$author Newscoop\Entity\Author
$authorType Newscoop\Entity\AuthorType
Результат Newscoop\Entity\ArticleAuthor
    public function addAuthorToArticle(Article $article, Author $author, AuthorType $authorType)
    {
        $articleAuthor = $this->em->getRepository('Newscoop\\Entity\\ArticleAuthor')->getArticleAuthor($article->getNumber(), $article->getLanguageCode(), $author->getId(), $authorType->getId())->getOneOrNullResult();
        if (!is_null($articleAuthor)) {
            throw new ResourcesConflictException("Author with this type is already attached to article", 409);
        }
        $articleAuthors = $this->em->getRepository('Newscoop\\Entity\\ArticleAuthor')->getArticleAuthors($article->getNumber(), $article->getLanguageCode())->getArrayResult();
        $articleAuthor = new ArticleAuthor();
        $articleAuthor->setArticle($article);
        $articleAuthor->setAuthor($author);
        $articleAuthor->setType($authorType);
        $articleAuthor->setOrder(count($articleAuthors) + 1);
        $this->em->persist($articleAuthor);
        $this->em->flush();
        return $articleAuthor;
    }