<?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller,
	Symfony\Component\HttpFoundation\Request,
    Symfony\Component\HttpFoundation\Response;

class PageController extends Controller
{
    public function eventAction($slug)
    {
        $response = new Response;
		$obj= $this->getDoctrine()->getManager()->getRepository('AppBundle:Event')->findOneBy(array('slug'=>$slug));
		if (!$obj) {
			throw $this->createNotFoundException('Oups ! This page does not exist');
		}

		return $this->render(
                'AppBundle:Page:event.html.twig',
                array('content' =>$obj),
                $response
          );
    }
	
	public function jobAction($slug)
    {
        $response = new Response;
		$obj= $this->getDoctrine()->getManager()->getRepository('AppBundle:Job')->findOneBy(array('slug'=>$slug));
		if (!$obj) {
			throw $this->createNotFoundException('Oups ! This page does not exist');
		}
		return $this->render(
                'AppBundle:Page:job.html.twig',
                array('content' =>$obj),
                $response
          );
    } 
	public function applicantAction($slug)
    {
        $response = new Response;
		$obj= $this->getDoctrine()->getManager()->getRepository('AppBundle:Applicant')->findOneBy(array('slug'=>$slug));
		if (!$obj) {
			throw $this->createNotFoundException('Oups ! This page does not exist');
		}
		return $this->render(
                'AppBundle:Page:applicant.html.twig',
                array('content' =>$obj),
                $response
          );
    }
	
	public function interviewAction($slug)
    {
        $response = new Response;
		$obj= $this->getDoctrine()->getManager()->getRepository('AppBundle:Interview')->findOneBy(array('slug'=>$slug));
		if (!$obj) {
			throw $this->createNotFoundException('Oups ! This page does not exist');
		}
		return $this->render(
                'AppBundle:Page:interview.html.twig',
                array('content' =>$obj),
                $response
          );
    }
	public function interviewModalAction(Request $request)
    {
        $response = new Response;
        $response->setMaxAge(0);
        $response->setSharedMaxAge(0);
        $response->headers->addCacheControlDirective('must-revalidate', true);
        $params = $request->query;
        if( $params->has('id') ) {
            return $this->render(
                'AppBundle:Ajax:interview.html.twig',
                array('content' => $this->getDoctrine()->getManager()->getRepository('AppBundle:Interview')->find($params->get('id'))),
                $response
            );
        }
        return $response;
    }
}
