Newscoop\GimmeBundle\Controller\AuthorsController::updateArticleAuthorAction PHP Метод

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

To update currently assigned article author you need provide his old and new article type, it can be done with special link header value: , example: **To update artile author with number 7 and type 1 to type 2 you need to send**: [POST] /articles/{number}/{language}/authors/7 **With header link and his value:** ,
public updateArticleAuthorAction ( Request $request, $number, $language, $authorId )
$request Symfony\Component\HttpFoundation\Request
    public function updateArticleAuthorAction(Request $request, $number, $language, $authorId)
    {
        $em = $this->container->get('em');
        $links = $request->attributes->get('links', array());
        $oldAuthorType = null;
        $newAuthorType = null;
        foreach ($links as $key => $objectArray) {
            if ($objectArray['object'] instanceof \Newscoop\Entity\AuthorType && $objectArray['resourceType'] == 'old-author-type') {
                $oldAuthorType = $objectArray['object'];
            }
            if ($objectArray['object'] instanceof \Newscoop\Entity\AuthorType && $objectArray['resourceType'] == 'new-author-type') {
                $newAuthorType = $objectArray['object'];
            }
        }
        if (!$oldAuthorType || !$newAuthorType) {
            return new InvalidParametersException("\"old-author-type\" and \"new-author-type\" resources are required");
        }
        $articleAuthor = $em->getRepository('Newscoop\\Entity\\ArticleAuthor')->getArticleAuthor($number, $language, $authorId, $oldAuthorType->getId())->getOneOrNullResult();
        if (!$articleAuthor) {
            throw new NotFoundHttpException('Article Author was not found.');
        }
        $articleAuthor->setType($newAuthorType);
        $em->flush();
    }