<?php

namespace AppBundle\Controller\Admin;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Entity\Recommendation;
use Symfony\Component\HttpFoundation\JsonResponse;

class RecommendationController extends Controller
{

    /**
     * @Route("/admin/config/recommandations/list", name="admin_config_recommendations")
     */
    public function listeRecommendationAdminAction()
    {
        $em = $this->getDoctrine()->getManager();
        $recos = $em->getRepository('AppBundle:Recommendation')->findAll();
        return $this->render('admin/recommendation_list.html.twig', array(
            'recos' => $recos,
        ));
    }

    /**
     * @Route("/admin/config/recommandation/{id}/toggle", name="admin_recommendation_toggle")
     */
    public function adminToggleRecommendationAction(Recommendation $recommendation)
    {
        $em = $this->getDoctrine()->getManager();
        $value = ($recommendation->getIsVisible() ? false : true);
        $recommendation->setIsVisible($value);
        $em->persist($recommendation);
        $em->flush();
        $result = array("msg" => "toggle ok");
        return new JsonResponse($result);
        $result = array("msg" => "toggle error");
        return new JsonResponse($result);
    }

}
