Newscoop\GimmeBundle\Controller\EditorialCommentsApiController::processForm PHP Метод

processForm() приватный Метод

Process editorial comments form
private processForm ( Request $request, $articleNumber = null, $languageId = null, $commentId = null ) : Form
$request Symfony\Component\HttpFoundation\Request
Результат Form
    private function processForm($request, $articleNumber = null, $languageId = null, $commentId = null)
    {
        $em = $this->container->get('em');
        $editorialCommentService = $this->container->get('newscoop.editorial_comments');
        if (!$commentId) {
            $statusCode = 201;
        } else {
            $statusCode = 200;
            $comment = $em->getRepository('Newscoop\\ArticlesBundle\\Entity\\EditorialComment')->getOneByArticleAndCommentId($articleNumber, $languageId, $commentId)->getOneOrNullResult();
            if (!$comment) {
                throw new EntityNotFoundException('Result was not found.');
            }
        }
        $form = $this->createForm(new EditorialCommentType(), array());
        $form->handleRequest($request);
        if ($form->isValid()) {
            $attributes = $form->getData();
            $user = $this->container->get('user')->getCurrentUser();
            $response = new Response();
            $response->setStatusCode($statusCode);
            if ($statusCode == 201 && $articleNumber && $languageId) {
                $article = $em->getRepository('Newscoop\\Entity\\Article')->getArticle($articleNumber, $languageId)->getOneOrNullResult();
                $parent = false;
                if (array_key_exists('parent', $attributes) && $attributes['parent'] != null) {
                    $parent = $em->getRepository('Newscoop\\ArticlesBundle\\Entity\\EditorialComment')->getOneByArticleAndCommentId($articleNumber, $languageId, $attributes['parent'])->getOneOrNullResult();
                    if (!$parent) {
                        throw new EntityNotFoundException('Parent comment was not found.');
                    }
                }
                $comment = $editorialCommentService->create($attributes['comment'], $article, $user, $parent);
                $response->headers->set('X-Location', $this->generateUrl('newscoop_gimme_articles_get_editorial_comment', array('number' => $articleNumber, 'language' => $languageId, 'commentId' => $comment->getId()), true));
            } elseif ($statusCode == 200 && $comment) {
                if (array_key_exists('comment', $attributes) && $attributes['comment'] != $comment->getComment() && $attributes['comment'] != '') {
                    $editorialCommentService->edit($attributes['comment'], $comment, $user);
                }
                if (array_key_exists('resolved', $attributes) && $attributes['resolved'] != $comment->getResolved()) {
                    $editorialCommentService->resolve($comment, $user, $attributes['resolved']);
                }
            }
            return $response;
        }
        return $form;
    }