public function like(Application $app, $id)
 {
     $restaurant = $app['repository.restaurant']->find($id);
     $user = $app['repository.user']->findByName($app['security.token_storage']->getToken()->getUser()->getUsername());
     try {
         $app['likechecker']->check($user, $restaurant);
     } catch (\Exception $e) {
         $app['session']->getFlashBag()->add('error_like', $e->getMessage());
         return $app->redirect($app['url_generator']->generate('restaurant_show', array('id' => $id)));
     }
     $like = new Like();
     $like->setRestaurant($id);
     $like->setUser($user->getId());
     $app['repository.likes']->save($like);
     $likes = $app['repository.likes']->findByRestaurant($id);
     $restaurant->setLikes(count($likes));
     $app['repository.restaurant']->save($restaurant);
     return $app->redirect($app['url_generator']->generate('restaurant_show', array('id' => $id)));
 }
 /**
  * Instantiates an user entity and sets its properties using db data.
  *
  * @param array likeData
  *   The array of db data.
  *
  * @return Like
  */
 protected function buildLike($likeData)
 {
     $like = new Like();
     $like->setId($likeData['id']);
     $like->setUser($likeData['user_id']);
     $like->setRestaurant($likeData['restaurant_id']);
     return $like;
 }