src/Controller/RecipeController.php line 458
<?phpnamespace App\Controller;use Pimcore\Controller\FrontendController;use Symfony\Bridge\Twig\Attribute\Template;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\HttpFoundation\Request;use Symfony\Contracts\Translation\TranslatorInterface;use Pimcore\Localization\LocaleServiceInterface;use Pimcore\Model\DataObject\Recipe;use Pimcore\Model\DataObject\Review;use Pimcore\Model\DataObject\RecipeIngredients;use Pimcore\Model\DataObject\Product;use Pimcore\Model\DataObject\RecipeTag;use Pimcore\Model\DataObject\UploadRecipe;use Pimcore\Model\DataObject;use Pimcore\Model\DataObject\Commentscount;use Pimcore\Bundle\PersonalizationBundle\Targeting\VisitorInfoStorageInterface;use Pimcore\Model\Tool\Targeting;use Pimcore\Model\Tool\Targeting\TargetGroup;use Pimcore\Model\DataObject\UserRecipeActivity;use GeoIp2\Database\Reader;/****@IgnoreAnnotation("Template")* @author PcCom*/class RecipeController extends FrontendController {/*** @Template** @param Request $request** @return array*//*** @var LocaleService*/private $visitorInfoStorage;public function __construct(VisitorInfoStorageInterface $visitorInfoStorage) {$this->visitorInfoStorage = $visitorInfoStorage;}public function recipesAction() {$Recipe = new Recipe\Listing();$Recipe->setOrder("desc");$Recipe->setLimit('4');$Recipe->load();$Tags = new RecipeTag\Listing();$Tags->load();$FeaturedRecipe = new Recipe\Listing();$FeaturedRecipe->setCondition("featured IN (?)", '1');$FeaturedRecipe->load();$Products = new Product\Listing();$Products->setLimit('3');$Products->load();$product = [];foreach ($Products as $key => $Product) {$product[] = $Product;}$recipe_reviews = new Review\Listing();$recipe_reviews->setLimit('5');$recipe_reviews->load();// Region wise ip Handler starttry {$ipaddress = '';if (isset($_SERVER['HTTP_CLIENT_IP'])) {$ipaddress = $_SERVER['HTTP_CLIENT_IP'];} else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];} else if (isset($_SERVER['HTTP_X_FORWARDED'])) {$ipaddress = $_SERVER['HTTP_X_FORWARDED'];} else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) {$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];} else if (isset($_SERVER['HTTP_FORWARDED'])) {$ipaddress = $_SERVER['HTTP_FORWARDED'];} else if (isset($_SERVER['REMOTE_ADDR'])) {$ipaddress = $_SERVER['REMOTE_ADDR'];} else {$ipaddress = 'UNKNOWN';}if ($ipaddress != 'UNKNOWN') {$ip_info = new Reader(__DIR__ . '/GeoLite2-Country.mmdb');$record = $ip_info->country($ipaddress);if ($record) {$ip = $record->country->isoCode;}}} catch (\Exception $e) {$ip = '';}$code = $ip; // issign country-iso code to code varibleif ($code == 'AE') {$groupids[] = '29';} elseif ($code == 'SA') {$groupids[] = '27';} elseif ($code == 'OM' || $code == 'QA' || $code == 'KW' || $code == 'BH') {$groupids[] = '28';} else {//$code = 'AE';$groupids[] = '29';}$groupids[] = '22';// Region wise ip Handler endreturn $this->render('Recipe/recipes.html.twig', ['products' => $product,'tags' => $Tags,'featuredrecipe' => $FeaturedRecipe,'recipes' => $Recipe,'recipe_reviews' => $recipe_reviews,'groupids' => $groupids,'country' => $code,]);}public function allrecipesAction() {$Recipe = new Recipe\Listing();$Recipe->setOrderKey("id");$Recipe->setOrder("desc");$Recipe->load();$Tags = new RecipeTag\Listing();$Tags->load();$recipe_reviews = new Review\Listing();$recipe_reviews->load();// $NewRecipes = new UploadRecipe\Listing();// $NewRecipes->setCondition("status In (?)","ApprovePublished");// $NewRecipes->load();return $this->render('Recipe/allrecipes.html.twig', ['tags' => $Tags,'recipes' => $Recipe,'recipe_reviews' => $recipe_reviews,//'newRecipes'=>$NewRecipes,]);}public function recipedetailsAction(Request $request) {// Region wise ip Handler starttry {$ipaddress = '';if (isset($_SERVER['HTTP_CLIENT_IP'])) {$ipaddress = $_SERVER['HTTP_CLIENT_IP'];} else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];} else if (isset($_SERVER['HTTP_X_FORWARDED'])) {$ipaddress = $_SERVER['HTTP_X_FORWARDED'];} else if (isset($_SERVER['HTTP_FORWARDED_FOR'])) {$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];} else if (isset($_SERVER['HTTP_FORWARDED'])) {$ipaddress = $_SERVER['HTTP_FORWARDED'];} else if (isset($_SERVER['REMOTE_ADDR'])) {$ipaddress = $_SERVER['REMOTE_ADDR'];} else {$ipaddress = 'UNKNOWN';}if ($ipaddress != 'UNKNOWN') {$ip_info = new Reader(__DIR__ . '/GeoLite2-Country.mmdb');$record = $ip_info->country($ipaddress);if ($record) {$ip = $record->country->isoCode;}}} catch (\Exception $e) {$ip = '';}$code = $ip; // issign country-iso code to code varibleif ($code == 'AE') {$groupids[] = '29';} elseif ($code == 'SA') {$groupids[] = '27';} elseif ($code == 'OM' || $code == 'QA' || $code == 'KW' || $code == 'BH') {$groupids[] = '28';} else {//$code = 'AE';$groupids[] = '29';}// Region wise ip Handler end$url = $request->get('url');$recipedetails = new Recipe\Listing();$recipedetails->setCondition("url = ?", [$url]);$recipedetails->load();foreach ($recipedetails as $key => $recipedata) {$recipe = $recipedata;break;}$recipeid = $recipedata->getId();$reviews = new Review\Listing();$reviews->setCondition("recipe_id__id IN (?)", $recipedata->getId());$reviews->setOrderKey("id");$reviews->setOrder("desc");$reviews->load();$reviewcount = [];if ($reviews) {foreach ($reviews as $key => $review) {$reviewcount[] = $review->getName();}$reviewcounts = count($reviewcount);} else {$reviewcounts = "0";}$commentscount = new Commentscount\Listing();$commentscount->setlimit(1);$commentscount->load();$myRecipe = new Recipe\Listing();//$myRecipe->setCondition("typeofmeal LIKE ?" , ['%Dessert%']);$myRecipe->load();$featuredrecipe = new Recipe\Listing();$featuredrecipe->setCondition("url != ? and featured IN (?)", [$url, '1']);$featuredrecipe->setlimit(4);$featuredrecipe->load();//Loyalty user activity/* if($this->get('session')){$userid = $this->get('session')->get('loginUID');}*/// $recipeid = $recipe->getId();/* $Liked = new UserRecipeActivity\Listing();$Liked->setCondition("recipeoption = ? and user_id__id = ? and recipe_id__id = ?", ['Like', $userid, $recipeid]);$Liked->load();if (count($Liked) == 1) {$Likedcount = 1;} else {$Likedcount = 0;}$Shared = new UserRecipeActivity\Listing();$Shared->setCondition("recipeoption = ? and user_id__id = ? and recipe_id__id = ?", ['Share', $userid, $recipeid]);$Shared->load();if (count($Shared) == 1) {$Sharedcount = 1;} else {$Sharedcount = 0;}$Saved = new UserRecipeActivity\Listing();$Saved->setCondition("recipeoption = ? and user_id__id = ? and recipe_id__id = ?", ['Save', $userid, $recipeid]);$Saved->load();if (count($Saved) == 1) {$Savedcount = 1;} else {$Savedcount = 0;}*///Loyalty user activity endsreturn $this->render('Recipe/recipesdetail.html.twig', ['recipedetails' => $recipedata,'ratingcount' => $reviewcounts,'reviewcount' => $reviewcounts,'count' => $commentscount,'reviews' => $reviews,'myrecipes' => $myRecipe,'featuredrecipe' => $featuredrecipe,'featuredreviews' => [],'country' => $code,//'country'=>'AE', // temporary basses'groupids' => $groupids,'Likedcount' => 0,'Sharedcount' =>0,'Savedcount' => 0,]);}public function searchbytagAction(Request $request) {$url = htmlspecialchars($request->get('id'));$Recipe = new Recipe\Listing();// if($url == 'featured'){// $Recipe->setCondition("featured IN (?)", '1');// $id = $request->get('id2');// }$Recipe->load();$Recipes = [];$tagURL = "";foreach ($Recipe as $key => $recipe) {for ($i = 0; $i < count($recipe->getTags()); $i++) {if ($recipe->getTags()[$i]) {if ($recipe->getTags()[$i]->getUrl() == $url) {$Recipes[] = $recipe;if ($tagURL == "") {if ($request->getLocale() == 'ar') {$tagURL = $recipe->getTags()[$i]->getUrl("en");} else {$tagURL = $recipe->getTags()[$i]->getUrl("ar");}}}}}}$Tags = new RecipeTag\Listing();$Tags->load();$recipe_reviews = new Review\Listing();$recipe_reviews->load();return $this->render('Recipe/recipesearchbytag.html.twig', ['tags' => $Tags,'recipes' => $Recipes,'tagURL' => $tagURL,'recipe_reviews' => $recipe_reviews,]);}public function searchAction(Request $request) {$q = strip_tags($request->get('q'));$Recipe = new Recipe\Listing();$Recipe->setCondition("name LIKE ? or url LIKE ? ", ["%" . $q . "%", "%" . $q . "%"]);$Recipe->load();$FeaturedProduct = new Product\Listing();$FeaturedProduct->setCondition("featured IN (?)", '1');$FeaturedProduct->load();$Tags = new RecipeTag\Listing();$Tags->load();$RecipeIng = new RecipeIngredients\Listing();$RecipeIng->load();return $this->render('Recipe/recipe_searchby_name.html.twig', ['tags' => $Tags,'recipes' => $Recipe,'name' => "Search query: $q",'recipeingredients' => $RecipeIng,'featuredproduct ' => $FeaturedProduct]);}/*** @Route("/{locale}/reviews", name="recipe_review")*/public function reviewAction(Request $request) {$success = 0;$session = $request->getSession();if (empty($_POST['g-recaptcha-response'])) {$success = 1;return $this->json(array('success' => $success));// $session->getFlashBag()->add('recaptcha-error', 'Please check the the captcha form.');// $this->addFlash('warning', 'Please check the the captcha form.');// return $this->redirect($request->headers->get('referer').'#message-alertt');}$secret = $secretdev = '6LePrpohAAAAANEprm30tyI4ltm2Tcgw8kO_BbEV';$url = 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($secret) . '&response=' . urlencode($_POST['g-recaptcha-response']);// $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);$verifyResponse = file_get_contents($url);$responseData = json_decode($verifyResponse);if ($responseData->success == false) {$success = 1;return $this->json(array('success' => $success));// $session->getFlashBag()->add('recaptcha-error', 'Please check the the captcha form.');// $this->addFlash('warning', 'Please check the the captcha form.');// return $this->redirect($request->headers->get('referer').'#message-alertt');}if ($request->get('recipe_id')) {$recipe = Recipe::getById($request->get('recipe_id'));try {$params = ['name' => $request->get('name'),'email' => $request->get('email'),'comment' => $request->get('comment'),'rating' => $request->get('rating'),];$Review = new Review();$Review->setKey(strtotime(date('Y-m-d H:i:s')) . htmlspecialchars($request->get('email')));$Review->setParent(DataObject\Folder::getByPath('/Review/'));$Review->setName(strip_tags($request->get('name')));$Review->setEmail(strip_tags($request->get('email')));$Review->setComment(strip_tags($request->get('comment')));$Review->setRating($request->get('addreviewrating'));$Review->setRecipe_id($recipe);$Review->setPublished(false);$d = $Review->save();if ($d) {$success = 2;return $this->json(array('success' => $success));// $session->getFlashBag()->add('success', 'Thank you for your feedback.');// return $this->redirect($request->headers->get('referer').'#message-alertt');}} catch (\Exception $e) {print_r($e->getMessage());}}// $locale = $request->getLocale();// if($locale == 'ar'){// return $this->redirect('/ar/كل-الوصفات/'.$request->get('recipe_url'), 301);// }else{// return $this->redirect('/en/all-recipes/'.$request->get('recipe_url'), 301);// }return $this->json(array('success' => $success));}public function getadvancefiltermodal() {$RecipeIng = new RecipeIngredients\Listing();// $RecipeIng->setCondition("featureingrident IN (?)", '1');$RecipeIng->load();$FeaturedProduct = new Product\Listing();$FeaturedProduct->setCondition("featured IN (?)", '1');$FeaturedProduct->load();return $this->render('Recipe/advancefilterModal_includes.html.twig', ['recipeingredients' => $RecipeIng,'featuredproduct' => $FeaturedProduct,]);}/*** @Route("/{locale}/filterrecipes", name="filterrecipes")*/public function searchfilterAction(Request $request) {// dd("hello");if (count($request->query->all()) < 1) {$referer = $request->headers->get('referer');return $this->redirect($referer);}$strBCond = "";$localCond = "";// $check = false;$Recipe = new Recipe\Listing();if ($request->get('product')) {$product = $request->get('product');for ($i = 0; $i < count($product); $i++) {if ($i > 0) {$localCond .= " OR ";}//$localCond .= "product LIKE'%" . $product[$i] . "%'";$localCond .= "featured_product LIKE " . $Recipe->quote("%," . $product[$i] . ",%");}// $conn .= " OR ";if ($localCond != "") {$strBCond = " ( " . $localCond . " ) ";$localCond = "";}}if ($request->get('Ing')) {$ingrident = $request->get('Ing');for ($i = 0; $i < count($ingrident); $i++) {if ($i > 0) {$localCond .= " OR ";}$localCond .= "ing LIKE " . $Recipe->quote("%" . $ingrident[$i] . "%");}if ($localCond != "") {if ($strBCond != "") {$strBCond .= " and ";}$strBCond .= " ( " . $localCond . " ) ";$localCond = "";}}if ($request->get('time60')) {$localCond .= "time <= 60";} else if ($request->get('time30')) {if ($localCond != "") {$localCond .= " OR ";}$localCond .= "time <= 30";} else if ($request->get('time15')) {if ($localCond != "") {$localCond .= " OR ";}$localCond .= "time <= 15";}if ($localCond != "") {if ($strBCond != "") {$strBCond .= " and ";}$strBCond .= " ( " . $localCond . " ) ";$localCond = "";}//Time End//Serving Start$servingParams = [];if ($request->get('serving01')) {array_push($servingParams, 1);// $localCond .= "serving = 1 OR serving2 = 1";}if ($request->get('serving02')) {array_push($servingParams, 2);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 2 OR serving2 = 2";}if ($request->get('serving03')) {array_push($servingParams, 3);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 3 OR serving2 = 3";}if ($request->get('serving04')) {array_push($servingParams, 4);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 4 OR serving2 = 4";}if ($request->get('serving05')) {array_push($servingParams, 5);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 5 OR serving2 = 5";}if ($request->get('serving06')) {array_push($servingParams, 6);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 6 OR serving2 = 6";}if ($request->get('serving07')) {array_push($servingParams, 7);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 7 OR serving2 = 7";}if ($request->get('serving08')) {array_push($servingParams, 8);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 8 OR serving2 = 8";}if ($request->get('serving09')) {array_push($servingParams, 9);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 9 OR serving2 = 9";}if ($request->get('serving10')) {array_push($servingParams, 10);// if($localCond != ""){// $localCond .= " OR ";// }// $localCond .= "serving = 10 OR serving2 = 10";}// if($localCond != ""){// if($strBCond != ""){// $strBCond .= " and ";// }// $strBCond .= " ( ". $localCond ." ) ";// $localCond = "";// }//End Serving//Start Cusineif ($request->get('cusine')) {$cusine[] = $request->get('cusine');for ($i = 0; $i < count($cusine); $i++) {if ($i > 0) {$localCond .= " OR ";}$localCond .= "cusine LIKE " . $Recipe->quote("%" . $cusine[$i] . "%");$para[] = $cusine[$i];}if ($localCond != "") {if ($strBCond != "") {$strBCond .= " and ";}$strBCond .= " ( " . $localCond . " ) ";$localCond = "";}}$Recipes = [];if ($strBCond != "") {$Recipe->setCondition($strBCond);}$Recipe->load();$Tags = new RecipeTag\Listing();$Tags->load();$recipe_reviews = new Review\Listing();$recipe_reviews->load();return $this->render('Recipe/advancefilter.html.twig', ['tags' => $Tags,'recipes' => $Recipe,'name' => "Advance Search",'recipe_reviews' => $recipe_reviews,]);}}