Newscoop\NewscoopBundle\Controller\CommentsController::setRecommendedAction PHP Метод

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

public setRecommendedAction ( Request $request, $comments, $recommended )
$request Symfony\Component\HttpFoundation\Request
    public function setRecommendedAction(Request $request, $comments, $recommended)
    {
        $em = $this->container->get('em');
        if (!is_array($comments)) {
            $comments = array($comments);
        }
        foreach ($comments as $commentId) {
            if (!$recommended) {
                continue;
            }
            $comment = $em->getRepository('Newscoop\\Entity\\Comment')->find($commentId);
            $thread = $em->getRepository('Newscoop\\Entity\\Article')->findOneBy(array('number' => $comment->getThread()));
            $this->container->get('dispatcher')->dispatch('comment.recommended', new GenericEvent($this, array('id' => $comment->getId(), 'subject' => $comment->getSubject(), 'article' => $thread->getName(), 'commenter' => $comment->getCommenterName())));
        }
        try {
            $em->getRepository('Newscoop\\Entity\\Comment')->setRecommended($comments, $recommended);
            $em->flush();
        } catch (\Exception $e) {
            return new JsonResponse(array('status' => $e->getMessage()));
        }
        return new JsonResponse(array('status' => true));
    }