src/Controller/TestController.php line 68

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\RecipeInfo;
  4. use App\Entity\TeamPlayers;
  5. use App\Entity\SlatePlayerList;
  6. use App\Entity\PlayerBoxStats;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. class TestController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/home", name="home")
  16.      */
  17.     public function index()
  18.     {
  19.         return $this->render('index.html.twig');
  20.     }
  21.     /**
  22.      * @Route("/all", name="all")
  23.      */
  24.     public function all()
  25.     {
  26.         return $this->render('all.html.twig');
  27.     }
  28.     /**
  29.      * @Route("/add", name="add")
  30.      */
  31.     public function add()
  32.     {
  33.         return $this->render('add.html.twig');
  34.     }
  35.     /**
  36.      * @Route("/challenges", name="challenges")
  37.      */
  38.     public function challenges()
  39.     {
  40.         return $this->render('challenges.html.twig');
  41.     }
  42.     /**
  43.      * @Route("/breakdown", name="breakdown")
  44.      */
  45.     public function breakdown(Request $request)
  46.     {
  47.         //return $this->render('breakdown.html.twig');
  48.         $id $request->query->get('id');
  49.         return $this->render('breakdown.html.twig', [
  50.             'id' => $id
  51.         ]);
  52.     }
  53.     /**
  54.      * @Route("/about", name="about")
  55.      */
  56.     public function about()
  57.     {
  58.         return $this->render('about.html.twig');
  59.     }
  60.     /**
  61.      * @Route("/contacts", name="contacts")
  62.      */
  63.     public function contacts()
  64.     {
  65.         return $this->render('contacts.html.twig');
  66.     }
  67.     /**
  68.      * @Route("/hidden", name="hidden")
  69.      */
  70.     public function odds()
  71.     {
  72.         return $this->render('odds.html.twig');
  73.     }
  74.     /**
  75.      * @Route("/ball", name="ball")
  76.      */
  77.     public function ball()
  78.     {
  79.         return $this->render('ball.html.twig');
  80.     }
  81.     /**
  82.      * @Route("/login", name="login")
  83.      */
  84.     public function login()
  85.     {
  86.         return $this->render('login.html.twig');
  87.     }
  88.     /**
  89.      * @Route("/recipe")
  90.      */
  91.     public function getRecipe(Request $request) {
  92.         /*
  93.         $entityManager = $this->getDoctrine()->getManager();
  94.         $recipeInfo = new RecipeInfo();
  95.         */
  96.         //$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findAll();
  97.         //$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->find($recipeId);
  98.         //$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($recipeId);
  99.         //$queryStr = ['chicken'];
  100.         /*
  101.         $queryStr = $request->query->get('ingredientsData');
  102.         $recipeInfo = [];
  103.         if(isset($queryStr)) {
  104.             $recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($queryStr);
  105.         }
  106.         */
  107.         $queryStr $request->query->get('ingredientsData');
  108.         $queryStr str_replace(" ""%20"$queryStr);
  109.         
  110.         $recipeInfo = [];
  111.         if(isset($queryStr)) {
  112.             //$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($queryStr);
  113.             $ch curl_init();
  114.             $query implode(","$queryStr);
  115.             //$newStr = 'recipe_5831ed782d73f56e9437e28feff625bf';
  116.             $url 'https://api.edamam.com/search?q=' $query '&app_id=91fb41c0&app_key=f4714ea59c5315a0a39801c8b26c86ff&to=25';
  117.             //$url = 'https://api.edamam.com/api/recipes/v2/' . $newStr . '?app_id=91fb41c0&app_key=f4714ea59c5315a0a39801c8b26c86ff&to=25&type=public';
  118.             curl_setopt($chCURLOPT_URL$url);
  119.             //curl_setopt($ch, CURLOPT_HEADER, TRUE); //
  120.             curl_setopt($chCURLOPT_RETURNTRANSFER1);
  121.             //curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  122.             curl_setopt($ch,CURLOPT_USERAGENT,'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)');
  123.         
  124.             //$output=curl_exec($ch);
  125.             $content curl_exec($ch);
  126.             if (curl_errno($ch)) {
  127.                 echo 'Error: ' curl_error($ch);
  128.             }
  129.             curl_close($ch);
  130.         }
  131.         $jsonItem = [];
  132.         $recipeInfo json_decode($content);
  133.         foreach($recipeInfo->hits as $items) {
  134.             
  135.             //var_dump($items);
  136.             if($items) {
  137.                 foreach($items as $recipeInfo) {
  138.                     if($recipeInfo) {
  139.                         $currRecipe = array(
  140.                             "recipe_id" => $recipeInfo->uri,
  141.                             "name" => $recipeInfo->label,
  142.                             "ingredient_name" => "ingredient",
  143.                             "ingredient_lines" => $recipeInfo->ingredientLines,
  144.                             "ingredients" => $recipeInfo->ingredients,
  145.                             "recipe_calories" => $recipeInfo->calories,
  146.                             "recipe_totalTime" => $recipeInfo->totalTime,
  147.                             "recipe_url" => $recipeInfo->url,
  148.                             "recipe_image" => $recipeInfo->image
  149.                         );
  150.             
  151.                         array_push($jsonItem$currRecipe);
  152.                     }
  153.                 }
  154.             }
  155.         }
  156.         return $this->json($jsonItem);
  157.     }
  158.     /**
  159.      * @Route("/breakdown-recipe")
  160.      */
  161.     public function getSingleRecipe(Request $request) {
  162.         /*
  163.         $entityManager = $this->getDoctrine()->getManager();
  164.         $recipeInfo = new RecipeInfo();
  165.         */
  166.         //$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findAll();
  167.         //$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->find($recipeId);
  168.         //$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($recipeId);
  169.         //$queryStr = ['chicken'];
  170.         /*
  171.         $queryStr = $request->query->get('ingredientsData');
  172.         $recipeInfo = [];
  173.         if(isset($queryStr)) {
  174.             $recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($queryStr);
  175.         }
  176.         */
  177.         $queryStr $request->query->get('id');
  178.         
  179.         $recipeInfo = [];
  180.         if(isset($queryStr)) {
  181.             //$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($queryStr);
  182.             $ch curl_init();
  183.             //$query = implode(",", $queryStr);
  184.             //$newStr = 'recipe_5831ed782d73f56e9437e28feff625bf';
  185.             $url 'https://api.edamam.com/api/recipes/v2/' $queryStr '?app_id=91fb41c0&app_key=f4714ea59c5315a0a39801c8b26c86ff&to=25&type=public';
  186.             curl_setopt($chCURLOPT_URL$url);
  187.             //curl_setopt($ch, CURLOPT_HEADER, TRUE); //
  188.             curl_setopt($chCURLOPT_RETURNTRANSFER1);
  189.             //curl_setopt($ch, CURLOPT_TIMEOUT, 3);
  190.             curl_setopt($ch,CURLOPT_USERAGENT,'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)');
  191.         
  192.             //$output=curl_exec($ch);
  193.             $content curl_exec($ch);
  194.             if (curl_errno($ch)) {
  195.                 echo 'Error: ' curl_error($ch);
  196.             }
  197.             curl_close($ch);
  198.         }
  199.         $jsonItem = [];
  200.         $recipeInfo json_decode($content);
  201.         //foreach($recipeInfo->hits as $items) {
  202.             //var_dump($recipeInfo);
  203.             //var_dump($items);
  204.                     if($recipeInfo) {
  205.                         $currRecipe = array(
  206.                             "recipe_id" => $recipeInfo->recipe->uri,
  207.                             "name" => $recipeInfo->recipe->label,
  208.                             "ingredient_name" => "ingredient",
  209.                             "ingredient_lines" => $recipeInfo->recipe->ingredientLines,
  210.                             "ingredients" => $recipeInfo->recipe->ingredients,
  211.                             "recipe_calories" => $recipeInfo->recipe->calories,
  212.                             "recipe_totalTime" => $recipeInfo->recipe->totalTime,
  213.                             "recipe_url" => $recipeInfo->recipe->url,
  214.                             "recipe_image" => $recipeInfo->recipe->image,
  215.                             "total_calories" => $recipeInfo->recipe->totalNutrients->ENERC_KCAL->quantity,
  216.                             "total_fat" => $recipeInfo->recipe->totalNutrients->FAT->quantity,
  217.                             "total_carbs" => $recipeInfo->recipe->totalNutrients->CHOCDF->quantity,
  218.                             "total_sodium" => $recipeInfo->recipe->totalNutrients->NA->quantity,
  219.                             "total_protein" => $recipeInfo->recipe->totalNutrients->PROCNT->quantity,
  220.                             "total_fiber" => $recipeInfo->recipe->totalNutrients->FIBTG->quantity,
  221.                             //"total_nutrients" => $recipeInfo->recipe->totalNutrients
  222.                         );
  223.             
  224.                         array_push($jsonItem$currRecipe);
  225.                     }
  226.         //}
  227.         return $this->json($jsonItem);
  228.     }
  229.     /**
  230.      * @Route("/hello", name="recipe")
  231.      */
  232.     public function hello() {
  233.         //return new Response("hello there");
  234.         $jsonItem = [];
  235.         $currRecipe = array(
  236.             "recipe_id" => 1,
  237.             "name" => "myRecipe",
  238.             "ingredient_name" => "ingredient",
  239.             "recipe_calories" => 0,
  240.             "recipe_totalTime" => 2,
  241.             "recipe_url" => 'url',
  242.             "recipe_image" => 'image'
  243.         );
  244.         array_push($jsonItem$currRecipe);
  245.         return $this->json($jsonItem);
  246.     }
  247.     /**
  248.      * @Route("/playerData", name="player")
  249.      */
  250.     public function playerData() {
  251.         //return new Response("hello there");
  252.         $entityManager $this->getDoctrine()->getManager();
  253.         $teamPlayers = new TeamPlayers();
  254.         
  255.         // $teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findAll();
  256.         $teamPlayers $this->getDoctrine()->getRepository(TeamPlayers::class)->findByExampleField('2019-2020');
  257.         // print_r($teamPlayers);
  258.         // $arrayCollection = array();
  259.         // foreach($teamPlayers as $item) {
  260.         //     $arrayCollection[] = array(
  261.         //         'team_city' => $item->getTeamCity(),
  262.         //         'team_name' => $item->getTeamName(),
  263.         //         'first_name' => $item->getFirstName(),
  264.         //         'last_name' => $item->getLastName(),
  265.         //         'season' => $item->getSeason(),
  266.         //         'player_image_path' => $item->getPlayerImagePath()
  267.         //     );
  268.         // }
  269.         $myPlayers = array();
  270.         foreach($teamPlayers as $item) {
  271.             $arrayCollection = array(
  272.                 'team_city' => $item->getTeamCity(),
  273.                 'team_name' => $item->getTeamName(),
  274.                 'first_name' => $item->getFirstName(),
  275.                 'last_name' => $item->getLastName(),
  276.                 'season' => $item->getSeason(),
  277.                 'player_image_path' => $item->getPlayerImagePath()
  278.             );
  279.             array_push($myPlayers,$arrayCollection);
  280.         }
  281.         $someCollection["teamPlayers"] = $myPlayers;
  282.         return new JsonResponse($someCollection);
  283.     }
  284.     /**
  285.      * @Route("/slatePlayerListData", name="slatePlayerListData")
  286.      */
  287.     public function slatePlayerListData() {
  288.         //return new Response("hello there");
  289.         $entityManager $this->getDoctrine()->getManager();
  290.         $slatePlayerList = new SlatePlayerList();
  291.         
  292.         $slatePlayerList $this->getDoctrine()->getRepository(SlatePlayerList::class)->findAll();
  293.         // $teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findByExampleField('2019-2020');
  294.         // print_r($slatePlayerList);
  295.         $arrayCollection = array();
  296.         foreach($slatePlayerList as $item) {
  297.             $arrayCollection[] = array(
  298.                 'last_name' => $item->getLastName(),
  299.                 'salary' => $item->getSalary(),
  300.                 'position' => $item->getPosition()
  301.             );
  302.         }
  303.         return new JsonResponse($arrayCollection);
  304.     }
  305.     /**
  306.      * @Route("/combinedPlayerData", name="combinedPlayerData")
  307.      */
  308.     public function combinedPlayerData(Request $request) {
  309.         //return new Response("hello there");
  310.         $entityManager $this->getDoctrine()->getManager();
  311.         $slatePlayerList = new SlatePlayerList();
  312.         $queryStr $request->query->get('date');
  313.         
  314.         $slatePlayerList $this->getDoctrine()->getRepository(SlatePlayerList::class)->findByAllField($queryStr);
  315.         // $teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findByExampleField('2019-2020');
  316.         //print_r($slatePlayerList);
  317.         // print_r('some break;');
  318.         // foreach($slatePlayerList as $item) {
  319.         //     print_r($item);
  320.         //     echo "<br><br>";
  321.         // }
  322.         $myPlayers = array();
  323.         foreach($slatePlayerList as $item) {
  324.             $arrayCollection = array(
  325.                 'first_name' => $item["firstName"],
  326.                 'last_name' => $item["lastName"],
  327.                 'fpg' => $item["fpg"],
  328.                 'played' => $item["played"],
  329.                 'salary' => $item["salary"],
  330.                 'position' => $item["position"],
  331.                 'team' => $item["team"],
  332.                 'opponent' => $item["opponent"],
  333.                 'injury_indicator' => $item["injuryIndicator"],
  334.                 'gameVS' => $item["game"],
  335.                 'player_slate_id' => $item["playerSlateId"],
  336.                 'team_city' => $item["teamCity"],
  337.                 'team_name' => $item["teamName"],
  338.                 'team_abbr' => $item["teamAbbr"],
  339.                 'season' => $item["season"],
  340.                 'player_image_path' => $item["playerImagePath"],
  341.                 'total_fp' => $item["totalFP"]
  342.             );
  343.             array_push($myPlayers,$arrayCollection);
  344.         }
  345.         $someCollection["teamPlayers"] = $myPlayers;
  346.         return new JsonResponse($someCollection);
  347.     }
  348.     /**
  349.      * @Route("/getSlateDates", name="getSlateDates")
  350.      */
  351.     public function getSlateDates(Request $request) {
  352.         //return new Response("hello there");
  353.         $entityManager $this->getDoctrine()->getManager();
  354.         $slatePlayerList = new SlatePlayerList();
  355.         //$queryStr = $request->query->get('date');
  356.         
  357.         $slatePlayerList $this->getDoctrine()->getRepository(SlatePlayerList::class)->findByDates("");
  358.         // $teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findByExampleField('2019-2020');
  359.         //print_r($slatePlayerList);
  360.         // print_r('some break;');
  361.         // foreach($slatePlayerList as $item) {
  362.         //     print_r($item);
  363.         //     echo "<br><br>";
  364.         // }
  365.         $myDates = array();
  366.         foreach($slatePlayerList as $item) {
  367.             $arrayCollection = array(
  368.                 'date_played' => $item["datePlayed"],
  369.             );
  370.             array_push($myDates,$arrayCollection);
  371.         }
  372.         $someCollection["slatesPlayed"] = $myDates;
  373.         return new JsonResponse($someCollection);
  374.         // $arrayCollection = array();
  375.         // foreach($teamPlayers as $item) {
  376.         //     $arrayCollection[] = array(
  377.         //         'date_played' => $item->getDatePlayed();
  378.         //     );
  379.         // }
  380.         // return new JsonResponse($arrayCollection);
  381.     }
  382. }