/**
  * @param Review $review
  */
 public function deduceMissingFields(Review $review)
 {
     $restaurant = $review->getRestaurant();
     $user = $review->getUser();
     if (null === $user || null === $restaurant) {
         return;
     }
     if (null === $review->getGeoname()) {
         $review->setGeoname($restaurant->getGeoname());
     }
     if (null === $review->getCuisine()) {
         $review->setCuisine($restaurant->getCuisine());
     }
     if (null === $review->getCost()) {
         $review->setCost($restaurant->getAverageCost());
     }
     if (null === $review->getPosition()) {
         $max = $this->reviewRepository->getMaxPosition($user, $review);
         $review->setPosition($max + 1);
     }
 }
 /**
  * @param Review $review
  *
  * @throws \Doctrine\DBAL\DBALException
  */
 public function decrementReviewsWithHigherPosition(Review $review)
 {
     $cuisine = $review->getCuisine();
     $geoname = $review->getGeoname();
     $user = $review->getUser();
     $sql = 'UPDATE reviews
             SET position = position - 1
             WHERE user_id = ?
               AND geoname_id = ?
               AND cuisine_id = ?
               AND position > ?';
     $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
     $stmt->bindValue(1, $user->getId());
     $stmt->bindValue(2, $geoname->getId());
     $stmt->bindValue(3, $cuisine->getId());
     $stmt->bindValue(4, $review->getPosition());
     $stmt->execute();
 }