<?php

namespace Whatsup\ContentBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Response;
use Whatsup\AdminBundle\Entity\Signalement;
use DateTime;

class DefaultController extends Controller
{
    /**
     * @Route("/credits", name="credits")
     * @Template()
     */
    public function creditsAction()
    {
        return array();
    }

    /**
     * @Route("/", name="home")
     * @Template()
     */
    public function indexAction()
    {
    	return array();
    }

    /**
     * @Route("/slider", name="slider")
     * @Template()
     */
    public function sliderAction($colorText = '', $colorBorder = '', $colorFL = '', $colorElems = '', $catId)
    {
    	$em = $this->getDoctrine()->getManager();
    	$slides = $em->getRepository('ContentBundle:Article')->findBy(array('category' => $catId), array('id' => 'desc'), 3);
    	return array(
    		'slides' => $slides,
            'colorText' => $colorText,
            'colorBorder' => $colorBorder,
            'colorFL' => $colorFL,
            'colorElems' => $colorElems
    	);
    }

    /**
     * @Route("/home-slider", name="homeslider")
     * @Template()
     */
    public function homeSliderAction()
    {
        $em = $this->getDoctrine()->getManager();
        $subcat = $em->getRepository('ContentBundle:SubCategory')->findOneById(5);
        $slides = $em->getRepository('ContentBundle:Article')->getAdminArticles($subcat);
        return array(
            'slides' => $slides,
        );
    }

    /**
     * @Route("/subslider", name="subslider")
     * @Template()
     */
    public function sliderSouCatAction($colorText = '', $colorBorder = '', $colorFL = '', $colorElems = '', $catId)
    {
        $em = $this->getDoctrine()->getManager();
        $slides = $em->getRepository('ContentBundle:Article')->findBy(array('subCategory' => $catId), array('id' => 'desc'), 3);
        return array(
            'slides' => $slides,
            'colorText' => $colorText,
            'colorBorder' => $colorBorder,
            'colorFL' => $colorFL,
            'colorElems' => $colorElems
        );
    }

    /**
     * @Route("/signalement/{id}/{text}", name="signalement", options={"expose"=true})
     * @Template()
     */
    public function signalementAction($id, $text)
    {
        $em = $this->getDoctrine()->getManager();
        $signalement = new Signalement();
        $signalement->setArticleId($id);
        $signalement->setComment($text);
        $signalement->setCreatedAt(new DateTime());
        $em->persist($signalement);
        $em->flush();

        return new Response('signalement');
    }

    /**
     * @Route("/article-of-the-month", name="month_article")
     * @Template()
     */
    public function monthArticleAction()
    {
        $em = $this->getDoctrine()->getManager();
        $articleOfTheMonth = $em->getRepository('ContentBundle:Article')->findArticleBestScore();
        return array('articleOfTheMonth' => $articleOfTheMonth);
    }

    /**
     * @Route("/search/{value}", name="search", options={"expose"=true}) 
     * @Template()
     */
    public function searchAction($value)
    {
        $em = $this->getDoctrine()->getManager();
        $search = $em->getRepository('ContentBundle:Article')->getSearchResult($value);
        return array('searchResults' => $search, 'searchParams' => $value);
    }

    /**
     * @Route("/cgu", name="cgu")
     * @Template()
     */
    public function cguAction()
    {
        return array();
    }

    /**
     * @Route("/legalnotice", name="legal") 
     * @Template()
     */
    public function legalnoticeAction()
    {
        return array();
    }
}
