src/Controller/Recipes/RecipesController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Recipes;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use Pimcore\Localization\LocaleServiceInterface;
  9. use Pimcore\Model\DataObject\ClassDefinition\Service;
  10. use Pimcore\Model\DataObject\Recipe;
  11. use Pimcore\Model\DataObject\Recipecategory;
  12. use Pimcore\Model\DataObject\Review;
  13. use Pimcore\Model\DataObject\Products;
  14. use Pimcore\Model\DataObject\ChefSpecial;
  15. use Pimcore\Model\DataObject\Userloyaltyprogram;
  16. use Pimcore\Model\DataObject;
  17. use Pimcore\Model\DataObject\Slider;
  18. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  19. use Knp\Component\Pager\PaginatorInterface;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. class RecipesController extends FrontendController
  22. {
  23.     public function advancefilterBlock(Request $request)
  24.     {
  25.         $recipe_categories = new Recipecategory\Listing();
  26.         $recipe_categories->load();
  27.         $featuredproducts = new Products\Listing();
  28.         $featuredproducts->setCondition('featured IN (?)''1');
  29.         $featuredproducts->load();
  30.         $maining_ar = [];
  31.         $mainrecipeingrident = new Recipe\Listing();
  32.         $mainrecipeingrident->Load();
  33.         $maining = [];
  34.         foreach ($mainrecipeingrident as $key => $ingrident) {
  35.                 if($ingrident->getServing_options()){
  36.                     for($i=0$i<count($ingrident->getServing_options()->getItems()); $i++){
  37.                     // for($j =0; $j<count($ingrident->getServing_options()->getItems()[$i]->getIngredeints()); $j++){
  38.                             $maining[] = $ingrident->getServing_options()->getItems()[$i]->getIngredeints()[0]['ingredient']->getdata();
  39.                             $maining_ar[] = $ingrident->getServing_options()->getItems()[$i]->getIngredeints()[0]['ingredient_ar']->getdata();
  40.                         //   }
  41.                     }
  42.                 }
  43.         }
  44.         return $this->render('Recipes/advancefilter-block.html.twig' , [
  45.             'featured_products' =>$featuredproducts ,
  46.             'mainingredeints'=>$maining ,
  47.             'mainingredeints_ar'=>$maining_ar ,
  48.             'recipe_categories'=>$recipe_categories ,
  49.            
  50.           
  51.         ]);
  52.     
  53.     }
  54.     public function recipesAction(Request $request)
  55.     {
  56.         $ChefSpecialRecipe = new ChefSpecial\Listing();
  57.         $ChefSpecialRecipe->setLimit('1');
  58.         $ChefSpecialRecipe->Load();
  59.         $BrandRecipes = new Recipe\Listing();
  60.         $BrandRecipes->setCondition('o_id = 384 or o_id = 387 or o_id = 394 and brand IN (?)''1');
  61.         // $BrandRecipes->setOffset(0);
  62.         $BrandRecipes->setLimit(3);
  63.         $BrandRecipes->Load();
  64.         $BrandRecipes1 = new Recipe\Listing();
  65.         $BrandRecipes1->setCondition('o_id = 411 or o_id = 449 or o_id = 401 and brand IN (?)''1');
  66.         // $BrandRecipes1->setOffset(3);
  67.         $BrandRecipes1->setLimit(3);
  68.         $BrandRecipes1->Load();
  69.         $BrandRecipes2 = new Recipe\Listing();
  70.         $BrandRecipes2->setCondition('o_id != 401 and o_id != 411 and o_id != 449 and o_id != 384 and o_id != 387 and o_id != 394 and o_id != 374 and o_id != 406 and brand IN (?)''1');
  71.         $BrandRecipes2->setLimit(3);
  72.         // if($request->get('page')){
  73.         //     $page = $request->get('page');            
  74.         // }else{
  75.         //     $page = 2;
  76.         // }
  77.         // $start = ($page)*$limit;
  78.         // $end = $limit;
  79.         // $BrandRecipes2->setOffset($start);
  80.         // $BrandRecipes2->setLimit($end);
  81.         $BrandRecipes2->Load();
  82.         $GoodyRecipes = new Recipe\Listing();
  83.         $GoodyRecipes->setCondition('o_id = 47485 and brand IN (?)''1');
  84.         $GoodyRecipes->setLimit(1);
  85.         $GoodyRecipes->Load();
  86.        
  87.         if ($request->isXmlHttpRequest()) {
  88.         return $this->loadMoreRecipes($BrandRecipes2$request);
  89.         }
  90.         return $this->render('Recipes/recipes.html.twig' 
  91.         [
  92.             'chefspecialrecipe'=>$ChefSpecialRecipe,
  93.             'brandrecipes'=>$BrandRecipes,
  94.             'brandrecipes1'=>$BrandRecipes1,
  95.             'brandrecipes2'=>$BrandRecipes2,
  96.             'goodyrecipes'=>$GoodyRecipes
  97.         ]);
  98.     }
  99.     public function loadMoreRecipes($BrandRecipes2$request ){
  100.      
  101.         $more_BrandRecipes2 '';
  102.         foreach($BrandRecipes2 as $brandrecipes2){
  103.             if($brandrecipes2->getFeatured_image()){
  104.                 $image $brandrecipes2->getFeatured_image();
  105.             }else{
  106.                 $image '';
  107.             }
  108.             // if($product->getRegion()[0]['price']->getData()){
  109.             //     $price = $product->getRegion()[0]['price']->getData();
  110.             // }else{
  111.             //     $price = '';
  112.             // }
  113.             // if($product->getUrl()){
  114.             //     $url = $product->getUrl()[0]->getSlug();
  115.             // }else{
  116.             //     $url = '';
  117.             // }
  118.                 if($request->getLocale() =='en'){
  119.                     $weblink ='en';
  120.                 }else{
  121.                     $weblink ='ar';
  122.                 }
  123.             $more_BrandRecipes2 .= '
  124.             <div class="slide">
  125.               <div class="slide-holder">
  126.                 <figure class="slide-img">
  127.                   <img src="'.$brandrecipes2->getFeatured_image().'" alt="'.$brandrecipes2->getName().'">
  128.                 </figure>
  129.                 <div class="slide-content">
  130.                   <div class="frecipes-box">
  131.                     <h3>'.$brandrecipes2->getName().'</h3>
  132.                     <p>'.$brandrecipes2->getDescription().'</p>
  133.                     <div class="chef-names">with '.$brandrecipes2->getBrand_name().'</div>
  134.                   </div>
  135.                   <ul class="list-unstyled recipe-info">
  136.                    
  137.                     <li class="orders">No. Of Orders 8</li>
  138.                     <li class="time">'.$brandrecipes2->getTypeofmeal().'</li>
  139.                   </ul>
  140.                   <div class="btn-holder">
  141.                     <a href="/'.$request->getLocale().'/recipedetails/'.$brandrecipes2->getUrl().'" class="btn btn-custom btn-black">View Recipe</a>
  142.                   </div>
  143.                 </div>
  144.               </div>
  145.             </div>               
  146.                 ';
  147.         }
  148.         return $this->json(array('success' => $more_BrandRecipes2));
  149.         
  150.     }
  151.     public function searchforrecipeAction(Request $request)
  152.     {
  153.         $strBCond "";
  154.         $localCond "";
  155.         $Recipe = new Recipe\Listing();
  156.         if($request->get('product')){
  157.             $product =$request->get('product');
  158.             for($i=0$i<count($product); $i++){
  159.                 if($i 0){
  160.                     $localCond .= " OR ";
  161.                 }
  162.                 $localCond .= "featured_product LIKE "$Recipe->quote("%,".$product[$i].",%");
  163.                }
  164.                if($localCond != ""){
  165.                 $strBCond " ( "$localCond ." ) ";
  166.                 $localCond "";
  167.             }
  168.             }
  169.             if($request->get('tag_id')){
  170.                 $tag_id =$request->get('tag_id');
  171.                     $localCond .= "tags LIKE "$Recipe->quote("%,".$tag_id.",%");
  172.                    if($localCond != ""){
  173.                     $strBCond " ( "$localCond ." ) ";
  174.                     $localCond "";
  175.                 }
  176.                 }
  177.             if($request->get('ing')){
  178.                 $ingrident =$request->get('ing');
  179.                 for($i=0$i<count($ingrident); $i++){
  180.                     if($i 0){
  181.                         $localCond .= " OR ";
  182.                     }
  183.                     $localCond .= "ing LIKE'%".$ingrident[$i]."%'";
  184.                    }
  185.                 if($localCond != ""){
  186.                     if($strBCond != ""){
  187.                         $strBCond .= " and ";
  188.                     }
  189.                     $strBCond .= " ( "$localCond ." ) ";
  190.                     $localCond "";
  191.                 }
  192.                 }
  193.                 if($request->get('time')){
  194.                     $time $request->get('time');
  195.                         $localCond .= "time LIKE'%".$time."%'";
  196.                         if($localCond != ""){
  197.                             if($strBCond != ""){
  198.                                 $strBCond .= " and ";
  199.                             }
  200.                             $strBCond .= " ( "$localCond ." ) ";
  201.                             $localCond "";
  202.                         }
  203.                 }
  204.                 if($request->get('cuisine')){
  205.                   
  206.                     $cuisine $request->get('cuisine');
  207.                   //  dd($cuisine);
  208.                        // $localCond .= "cuisine LIKE'%".$cuisine."%'";
  209.                         $localCond .= "category LIKE "$Recipe->quote("%,".$cuisine.",%");
  210.                         
  211.                         if($localCond != ""){
  212.                             if($strBCond != ""){
  213.                                 $strBCond .= " and ";
  214.                             }
  215.                             $strBCond .= " ( "$localCond ." ) ";
  216.                             $localCond "";
  217.                         }
  218.                 }
  219.                 if($request->get('serving')){
  220.                     $serving $request->get('serving');
  221.                         $localCond .= "serves = $serving";
  222.                         if($localCond != ""){
  223.                             if($strBCond != ""){
  224.                                 $strBCond .= " and ";
  225.                             }
  226.                             $strBCond .= " ( "$localCond ." ) ";
  227.                             $localCond "";
  228.                         }
  229.                 }
  230.                 if($request->get('recipename')){
  231.                     $recipename $request->get('recipename');
  232.                         $localCond .= "name LIKE'%".$recipename."%'";
  233.                         if($localCond != ""){
  234.                             if($strBCond != ""){
  235.                                 $strBCond .= " and ";
  236.                             }
  237.                             $strBCond .= " ( "$localCond ." ) ";
  238.                             $localCond "";
  239.                         }
  240.                 }
  241.                 if($request->get('typeofmeal')){
  242.                     $typeofmeal $request->get('typeofmeal');
  243.                         $localCond .= "typeofmeal LIKE'%".$typeofmeal."%'";
  244.                         if($localCond != ""){
  245.                             if($strBCond != ""){
  246.                                 $strBCond .= " and ";
  247.                             }
  248.                             $strBCond .= " ( "$localCond ." ) ";
  249.                             $localCond "";
  250.                         }
  251.                 }
  252.                 if ($strBCond != "")
  253.         {
  254.             $Recipe->setCondition($strBCond);
  255.         }
  256.         $Recipe->load();
  257.         
  258.         return $this->render('Recipes/searchforrecipe.html.twig',
  259.         [
  260.             'result' => $Recipe
  261.         ]);
  262.     }
  263.     /**
  264.      * @Route("/{locale}/all-recipes/{url}", name="recipedetails")
  265.     */
  266.     public function recipedetailsAction(Request $request)
  267.     {
  268.         $url strip_tags($request->get('url'));
  269.         $recipedetails = new Recipe\Listing();
  270.         $recipedetails->setCondition("url = ?", [$url]);
  271.         $recipedetails->load();
  272.         if(count($recipedetails) > 0){
  273.             foreach ($recipedetails as $key => $recipedata) {
  274.                 break;
  275.             }
  276.             //for rating purpose
  277.             //reviews start
  278.             $reviewsforraitngs = new Review\Listing();
  279.             $reviewsforraitngs->setCondition("recipe_id__id IN (?)",$recipedata->getId());
  280.             $reviewsforraitngs->setOrderKey("o_id");
  281.             $reviewsforraitngs->setOrder("desc");
  282.             $reviewsforraitngs->load();
  283.             $max 0
  284.             $n count($reviewsforraitngs);
  285.             if(count($reviewsforraitngs) > 0){
  286.                 foreach ($reviewsforraitngs as $key => $reviewsforraitng){
  287.                     
  288.                     if(trim($reviewsforraitng->getName())){
  289.                         $max $max+$reviewsforraitng->getRating();
  290.                     }
  291.                 }
  292.               
  293.             }
  294.             if($max != 0){
  295.                 $rating =  round($max $n);
  296.             } else{
  297.                 $rating =0;
  298.             }
  299.             //reviews statr
  300.             $reviews = new Review\Listing();
  301.             $reviews->setCondition("recipe_id__id IN (?)"$recipedata->getId());
  302.             $reviews->setOrderKey("o_id");
  303.             $reviews->setOrder("desc");
  304.             // Pagination
  305.             $limit 2;
  306.             if($request->get('page')){
  307.                 $page $request->get('page');            
  308.             }else{
  309.                 $page 0;
  310.             }
  311.             $start = ($page)*$limit;
  312.             $end $limit;
  313.             $reviews->setOffset($start);
  314.             $reviews->setLimit($end);
  315.             $reviews->load();
  316.             if ($request->isXmlHttpRequest()) {
  317.                 return $this->loadMoreRecipeReviews($reviews);
  318.             }
  319.             // Loyality Program Logic start
  320.             $uid $this->get('session')->get('loginUID');
  321.             $rid $recipedata->getId();
  322.             $Liked = new Userloyaltyprogram\Listing();
  323.             $Liked->setCondition("op_name = ? and u_id = ? and obj_id = ?",['Like',$uid,$rid]);
  324.             $Liked->load();
  325.             $Shared = new Userloyaltyprogram\Listing();
  326.             $Shared->setCondition("op_name = ? and u_id = ? and obj_id = ?",['Share',$uid,$rid]);
  327.             $Shared->load();
  328.             //dd($recipedata->getServing_options()->getItems()[0]->getRecipe_feature_product()[0]->getId());
  329.             $Recipe_Feature_Product_Ids = [];
  330.             if($recipedata->getServing_options()){    
  331.                 for($i=0$i<count($recipedata->getServing_options()->getItems()); $i++){
  332.                 for($j =0$j<count($recipedata->getServing_options()->getItems()[$i]->getRecipe_feature_product()); $j++){
  333.                     $Recipe_Feature_Product_Ids[] = $recipedata->getServing_options()->getItems()[$i]->getRecipe_feature_product()[$j]->getId();           
  334.                     }
  335.                 }
  336.             }
  337.             //dd( $Recipe_Feature_Product_Ids);
  338.             $Liked_Recipe_feature_product = new Userloyaltyprogram\Listing();
  339.             $Liked_Recipe_feature_product->setCondition("op_name = ? and u_id = ? and obj_data__id IN (?)",['Like',$uid,$Recipe_Feature_Product_Ids]);
  340.             $Liked_Recipe_feature_product->load();
  341.             $Liked_Recipe_feature_product_Ids = [];
  342.             foreach($Liked_Recipe_feature_product as $liked_Recipe_feature_product){
  343.                 $Liked_Recipe_feature_product_Ids[]=$liked_Recipe_feature_product->getObj_id();
  344.             }
  345.             // dd($Liked_Recipe_feature_product_Ids);
  346.             // Loyality Program Logic End
  347.             // Similar Recipes Start
  348.             $recipe_category $recipedata->getCuisine();
  349.             $recipe_name $recipedata->getName();
  350.             $similar_recipes = new Recipe\Listing();
  351.             $similar_recipes->setCondition("cuisine = ? and name != ?",[$recipe_category $recipe_name]);
  352.             $similar_recipes->setLimit(3);
  353.             $similar_recipes->setOrderKey("RAND()"false);
  354.             $similar_recipes->load();
  355.             // Similar Recipes End
  356.             return $this->render('Recipes/reciepedetails.html.twig', [
  357.                 'recipedetails'=>$recipedata ,
  358.                 'review' =>$reviews ,
  359.                 'rating'=>$rating,
  360.                 'Liked'=>$Liked,
  361.                 'Shared'=>$Shared,
  362.                 'Liked_Recipe_feature_product_Ids'=>$Liked_Recipe_feature_product_Ids,
  363.                 'similar_recipes'=>$similar_recipes,
  364.              ]);
  365.            
  366.         }else{
  367.             throw new NotFoundHttpException('Invalid Recipe Url');
  368.         }      
  369.        
  370.     }
  371.     public function loadMoreRecipeReviews($reviews){
  372.         $totla_reviews 0;
  373.         if(!empty($reviews)){
  374.             $totla_reviews = (count($reviews->getData()));
  375.             
  376.         }else{
  377.             $totla_reviews '';
  378.         }
  379.         $more_review '';
  380.         foreach($reviews as $review){
  381.             $more_review .= '
  382.             <div class="col-12 col-md-6">
  383.             <div class="comment-list-box">
  384.               <div class="comment-list-box-header">
  385.                 <figure class="person-img">
  386.                   <img src="/static/assets/images/user-icon-01.png" alt="user icon 01">
  387.                 </figure>
  388.                 <h5>'.$review->getName().'</h5>
  389.                 <div class="rating">'.$review->getRating().'</div>
  390.               </div>
  391.               <p>'.$review->getComment().'</p>
  392.               <div class="date">'.$review->getMydate().'</div>
  393.             </div>
  394.           </div>               
  395.                 ';
  396.               
  397.         }
  398.         return $this->json(array('success' => $more_review 'total_reviews' => $totla_reviews));
  399.         
  400.     }
  401.     public function reviewAction(Request $request){
  402.       
  403.        if(!empty($_POST['g-recaptcha-response'])){
  404.             if($_SERVER['HTTP_HOST'] == 'gfs2.centric.ae'){
  405.                 $secret $secretdev '6LdxNsAgAAAAAOY5GPouinn81p6Vh8sih9o_s0xX';
  406.             }elseif ($_SERVER['HTTP_HOST'] == 'goodycs.com') {
  407.                 $secret $secretprod '6Le5OcAgAAAAAIxdbVPc2Y3DN6WMEWzAmE2F85WR';
  408.             }
  409.         
  410.             $url 'https://www.google.com/recaptcha/api/siteverify?secret=' urlencode($secret) .  '&response=' urlencode($_POST['g-recaptcha-response']);
  411.            // $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
  412.             $verifyResponse file_get_contents($url);
  413.             $responseData json_decode($verifyResponse);
  414.             if($responseData->success == true){
  415.                 $success 0;
  416.                 $recipe  = new Recipe\Listing();
  417.                 $recipe Recipe::getById($request->get('recipe_id'));
  418.         
  419.                 $Review = new Review();
  420.                 $Review->setKey($request->get('email')."[".strtotime(date('Y-m-d H:i:s'))."]");
  421.                 $Review->setParent(DataObject\Folder::getByPath('/reviews/'));
  422.                 $Review->setName(strip_tags($request->get('name')));
  423.                 $Review->setEmail(strip_tags($request->get('email')));
  424.                 $Review->setComment(strip_tags($request->get('comment')));
  425.                 $Review->setRating(strip_tags($request->get('addreviewrating')));
  426.                 $Review->setRecipe_id($recipe);
  427.                 $Review->setMydate(date('Y-m-d'));
  428.                 $Review->setPublished(false);
  429.                 $d $Review->save();
  430.                 if($d){
  431.                     $success 2;
  432.                 }
  433.             }else{
  434.                 $success 1;
  435.             }
  436.             
  437.         }else{
  438.             $success 1;
  439.         }
  440.    
  441.         return $this->json(array('success' =>$success));
  442.        // return $this->redirect('/'.$request->get('locale').'/all-recipes/'.$request->get('recipe_url'), 301);
  443.     }
  444.     public function ourchefAction(Request $request)
  445.     {
  446.         $chef  = new ChefSpecial\Listing();
  447.         $chef->setOrderKey("order");
  448.         $chef->setOrder("asc"); 
  449.         $chef->load();
  450.         $chef_banner_spotlight = new Slider\Listing();
  451.         $chef_banner_spotlight->setCondition("o_id = 48095");
  452.         $chef_banner_spotlight->load();
  453.         foreach($chef_banner_spotlight as $chefbannerspotlight){
  454.             break;
  455.         }
  456.         return $this->render('Recipes/our-chef.html.twig', [
  457.             'chefs'=> $chef,
  458.             'chefbannerspotlight'=> $chefbannerspotlight,
  459.         ]);
  460.       //  return [];
  461.     }
  462.     public function allrecipesAction(Request $requestPaginatorInterface $paginator,TranslatorInterface $translator)
  463.     {
  464.         // $limit = 9;
  465.         $pageSize =  LIMIT_PER_PAGE;
  466.         $page $request->get('page'1);
  467.         // $page = $request->query->getInt('page', 1); // Get the current page number, default to 1 if not present
  468.         $recipes  = new Recipe\Listing();
  469.         $recipes $paginator->paginate($recipes$page$pageSize);    
  470.         // Calculate if there are more pages
  471.         $currentPage $recipes->getCurrentPageNumber();
  472.         $totalPages ceil($recipes->getTotalItemCount() / $recipes->getItemNumberPerPage());
  473.         $showLoadMoreButton $currentPage $totalPages;
  474.         
  475.         if ($request->isXmlHttpRequest()) {
  476.             $html $this->render('Recipes/partial.html.twig', [
  477.                 'recipes' => $recipes->getItems(),
  478.             ])->getContent();
  479.            
  480.             return new JsonResponse([
  481.                 'html' => $html,
  482.                 'showLoadMoreButton' => $showLoadMoreButton
  483.             ]);
  484.         }
  485.         return $this->render('Recipes/allrecipes.html.twig', [ 'recipes'=>$recipes ]);
  486.         
  487.     }
  488.   
  489.     /**
  490.      * @Route("/{locale}/recipes/{url}", name="recipes_category")
  491.     */
  492.     public function recipeCategory(Request $request)
  493.     {
  494.         $cat_url trim($request->get('url'));
  495.         $category = new Recipecategory\Listing();
  496.         $category->setCondition('cat_url = ?', [$cat_url]);
  497.         $category->Load();
  498.      
  499.        if(count($category) > 0)
  500.        {
  501.         foreach($category as $Category){
  502.             $cat_id $Category->getId();
  503.         }
  504.        
  505.         $category_recipes = new Recipe\Listing();
  506.        // $category_recipes->setCondition('category IN (?)', [$cat_id]);
  507.         $category_recipes->setCondition("category REGEXP CONCAT('(^|,)(', REPLACE('$cat_id',',', '|'), ')(,|$)')");
  508.         $category_recipes->Load();
  509.       
  510.         return $this->render('Recipes/recipe-category.html.twig',
  511.         [
  512.             'recipe_category'=>$Category,
  513.             'category_recipes' =>$category_recipes ,
  514.             
  515.         ]);
  516.        }else{
  517.             throw new NotFoundHttpException('Invalid Recipe Category Url');
  518.        } 
  519.         
  520.     }
  521. }