src/DEVWEB/ColocationBundle/Controller/AdvertController.php
// controller de la vue view.html.twig
controller de la vue view.html.twig
controller de la vue view . html . twig
public function viewAction($id)
  {
    $em = $this->getDoctrine()->getManager();
    $affichage = false;
    $postule = false;
    $advert = $em->getRepository('DEVWEBColocationBundle:Advert')->find($id);
    if (null === $advert) {
      throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas.");
    }
    else{
      $securityContext = $this->container->get('security.authorization_checker');
      if ($securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
        $usr = $this->getUser()->getUsername();
        if($usr == "admin"){
          $affichage = true;
          $postule = true;
        }
        else if ($advert->getAuthor() == $usr){
          $affichage = true;
        }
        else {
          $postule = true;
        }
      }
    }
  if ($advert->getNbPlaces() == 0){
    $postule = false;
  }
  return $this->render('@DEVWEBColocation/Advert/view.html.twig', array(
    'advert'           => $advert,
    'affichage'        => $affichage,
    'postule'          => $postule,
  ));
  }
public function viewAction ( $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ affichage = false ; $ postule = false ; $ advert = $ em -> getRepository ( 'DEVWEBColocationBundle:Advert' ) -> find ( $ id ) ; if ( null === $ advert ) { throw new NotFoundHttpException ( " L'annonce d'id  " . $ id . "  n'existe pas. " ) ; } else { $ securityContext = $ this -> container -> get ( 'security.authorization_checker' ) ; if ( $ securityContext -> isGranted ( 'IS_AUTHENTICATED_REMEMBERED' ) ) { $ usr = $ this -> getUser ( ) -> getUsername ( ) ; if ( $ usr == " admin " ) { $ affichage = true ; $ postule = true ; } else if ( $ advert -> getAuthor ( ) == $ usr ) { $ affichage = true ; } else { $ postule = true ; } } } if ( $ advert -> getNbPlaces ( ) == 0 ) { $ postule = false ; } return $ this -> render ( '@DEVWEBColocation/Advert/view.html.twig' , array ( 'advert' => $ advert , 'affichage' => $ affichage , 'postule' => $ postule , ) ) ; }
controller de la vue view.html.twig
controller de la vue view . html . twig