public function doUserLike(User $user, Restaurant $restaurant)
 {
     $likes = $this->app['repository.likes']->findByUser($user->getId());
     foreach ($likes as $like) {
         if ($like->getRestaurant() == $restaurant->getId()) {
             return true;
         }
     }
     return false;
 }
 public function create(Application $app, Request $request)
 {
     if ($request->getMethod() == 'POST') {
         $restaurant = new Restaurant();
         $restaurant->setNom($request->get('nom'));
         $restaurant->setAdresse($request->get('adresse'));
         $restaurant->setCp($request->get('cp'));
         $restaurant->setVille($request->get('ville'));
         $restaurant->setFermeture($request->get('fermeture'));
         $restaurant->setOuverture($request->get('ouverture'));
         $restaurant->setLikes(0);
         $app['repository.restaurant']->save($restaurant);
         return $app->redirect($app['url_generator']->generate('restaurant_index'));
     }
     return $app['twig']->render('restaurant/create.html.twig');
 }
 /**
  * Instantiates an user entity and sets its properties using db data.
  *
  * @param array restaurantData
  *   The array of db data.
  *
  * @return Restaurant
  */
 protected function buildRestaurant($restaurantData)
 {
     $restaurant = new Restaurant();
     $restaurant->setId($restaurantData['id']);
     $restaurant->setNom($restaurantData['nom']);
     $restaurant->setAdresse($restaurantData['adresse']);
     $restaurant->setCp($restaurantData['cp']);
     $restaurant->setVille($restaurantData['ville']);
     $restaurant->setOuverture($restaurantData['ouverture']);
     $restaurant->setFermeture($restaurantData['fermeture']);
     $restaurant->setLikes($restaurantData['likes']);
     return $restaurant;
 }