Knp\Bundle\KnpBundlesBundle\Controller\BundleController::favoriteAction PHP Method

favoriteAction() public method

public favoriteAction ( $ownerName, $name )
    public function favoriteAction($ownerName, $name)
    {
        /* @var $bundle Bundle */
        $bundle = $this->getRepository('Bundle')->findOneBy(array('ownerName' => $ownerName, 'name' => $name));
        if (!$bundle) {
            return new Response(sprintf('The bundle "%s/%s" does not exist', $ownerName, $name), 404);
        }
        $developer = $this->getUser();
        if (!$developer instanceof Developer) {
            return new Response('You must log in as a Developer to favorite a bundle.', 400);
        }
        $status = $this->get('knp_bundles.bundle.manager')->toggleBundleFavorite($bundle, $developer);
        return new JsonResponse(array('status' => 'OK', 'result' => array('favorited' => $status, 'label' => $status ? $this->get('translator')->trans('bundles.show.favorited') : $this->get('translator')->trans('bundles.show.favorite'))));
    }