src/Dpavic/JobsBundle/Controller/JobController.php
/**
     * Finds and displays a Job entity.
     *
     * @Route("/{company}/{location}/{id}/{position}", requirements={"id" = "\d+"}, name="job_show")
     * @Method("GET")
     * @Template()
     */
Finds and displays a Job entity.
Finds and displays a Job entity .
public function showAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        $entity = $em->getRepository('DpavicJobsBundle:Job')->getActiveJob($id);
        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Job entity.');
        }
        $session = $this->getRequest()->getSession();
        $jobs = $session->get('job_history', array());
        $job = array(
            'id' => $entity->getId(),
            'position' => $entity->getPosition(),
            'company' => $entity->getCompany(),
            'companySlug' => $entity->getCompanySlug(),
            'locationSlug' => $entity->getLocationSlug(),
            'positionSlug' => $entity->getPositionSlug()
        );
        if (!in_array($job, $jobs)) {
            array_unshift($jobs, $job);
            $session->set('job_history', array_slice($jobs, 0, 3));
        }
        $deleteForm = $this->createDeleteForm($id);
        return array(
            'entity' => $entity,
            'delete_form' => $deleteForm->createView(),
        );
    }
public function showAction ( $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ entity = $ em -> getRepository ( 'DpavicJobsBundle:Job' ) -> getActiveJob ( $ id ) ; if ( ! $ entity ) { throw $ this -> createNotFoundException ( 'Unable to find Job entity.' ) ; } $ session = $ this -> getRequest ( ) -> getSession ( ) ; $ jobs = $ session -> get ( 'job_history' , array ( ) ) ; $ job = array ( 'id' => $ entity -> getId ( ) , 'position' => $ entity -> getPosition ( ) , 'company' => $ entity -> getCompany ( ) , 'companySlug' => $ entity -> getCompanySlug ( ) , 'locationSlug' => $ entity -> getLocationSlug ( ) , 'positionSlug' => $ entity -> getPositionSlug ( ) ) ; if ( ! in_array ( $ job , $ jobs ) ) { array_unshift ( $ jobs , $ job ) ; $ session -> set ( 'job_history' , array_slice ( $ jobs , 0 , 3 ) ) ; } $ deleteForm = $ this -> createDeleteForm ( $ id ) ; return array ( 'entity' => $ entity , 'delete_form' => $ deleteForm -> createView ( ) , ) ; }
Finds and displays a Job entity.
Finds and displays a Job entity .
//fetch all jobs already stored in the job history //store the job as an array so we can put it in the session and avoid entity serialize errors //add curent job at the beginning of the array //store the new job history back into the session