/** * Try to guess the cuisine by restaurant name * otherwise return random cuisine * * @param Restaurant $restaurant * @param array $cuisines * * @return Cuisine */ public function guessCuisine(Restaurant $restaurant, array $cuisines) { $name = strtolower($restaurant->getName()); /** @var Cuisine $cuisine */ foreach ($cuisines as $cuisine) { if (strpos($name, strtolower($cuisine->getName())) !== false) { return $cuisine; } } return $cuisines[array_rand($cuisines)]; }
/** * @param Restaurant $restaurant * * @return Restaurant|null */ public function getRestaurantByRestaurant(Restaurant $restaurant) { $results = $this->getEntityManager()->createQueryBuilder()->select('r')->from(Restaurant::SHORTCUT_CLASS_NAME, 'r')->where('r.name = :name')->andWhere('r.lat = :lat')->andWhere('r.lng = :lng')->setParameter('name', $restaurant->getName())->setParameter('lat', $restaurant->getLat())->setParameter('lng', $restaurant->getLng())->getQuery()->getResult(); if (count($results) > 0) { return $results[0]; } return null; }