<?php
namespace App\Controller;
use App\Entity\RecipeInfo;
use App\Entity\TeamPlayers;
use App\Entity\SlatePlayerList;
use App\Entity\PlayerBoxStats;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
class TestController extends AbstractController
{
/**
* @Route("/home", name="home")
*/
public function index()
{
return $this->render('index.html.twig');
}
/**
* @Route("/all", name="all")
*/
public function all()
{
return $this->render('all.html.twig');
}
/**
* @Route("/add", name="add")
*/
public function add()
{
return $this->render('add.html.twig');
}
/**
* @Route("/challenges", name="challenges")
*/
public function challenges()
{
return $this->render('challenges.html.twig');
}
/**
* @Route("/breakdown", name="breakdown")
*/
public function breakdown(Request $request)
{
//return $this->render('breakdown.html.twig');
$id = $request->query->get('id');
return $this->render('breakdown.html.twig', [
'id' => $id
]);
}
/**
* @Route("/about", name="about")
*/
public function about()
{
return $this->render('about.html.twig');
}
/**
* @Route("/contacts", name="contacts")
*/
public function contacts()
{
return $this->render('contacts.html.twig');
}
/**
* @Route("/hidden", name="hidden")
*/
public function odds()
{
return $this->render('odds.html.twig');
}
/**
* @Route("/ball", name="ball")
*/
public function ball()
{
return $this->render('ball.html.twig');
}
/**
* @Route("/login", name="login")
*/
public function login()
{
return $this->render('login.html.twig');
}
/**
* @Route("/recipe")
*/
public function getRecipe(Request $request) {
/*
$entityManager = $this->getDoctrine()->getManager();
$recipeInfo = new RecipeInfo();
*/
//$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findAll();
//$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->find($recipeId);
//$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($recipeId);
//$queryStr = ['chicken'];
/*
$queryStr = $request->query->get('ingredientsData');
$recipeInfo = [];
if(isset($queryStr)) {
$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($queryStr);
}
*/
$queryStr = $request->query->get('ingredientsData');
$queryStr = str_replace(" ", "%20", $queryStr);
$recipeInfo = [];
if(isset($queryStr)) {
//$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($queryStr);
$ch = curl_init();
$query = implode(",", $queryStr);
//$newStr = 'recipe_5831ed782d73f56e9437e28feff625bf';
$url = 'https://api.edamam.com/search?q=' . $query . '&app_id=91fb41c0&app_key=f4714ea59c5315a0a39801c8b26c86ff&to=25';
//$url = 'https://api.edamam.com/api/recipes/v2/' . $newStr . '?app_id=91fb41c0&app_key=f4714ea59c5315a0a39801c8b26c86ff&to=25&type=public';
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, TRUE); //
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch,CURLOPT_USERAGENT,'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)');
//$output=curl_exec($ch);
$content = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
curl_close($ch);
}
$jsonItem = [];
$recipeInfo = json_decode($content);
foreach($recipeInfo->hits as $items) {
//var_dump($items);
if($items) {
foreach($items as $recipeInfo) {
if($recipeInfo) {
$currRecipe = array(
"recipe_id" => $recipeInfo->uri,
"name" => $recipeInfo->label,
"ingredient_name" => "ingredient",
"ingredient_lines" => $recipeInfo->ingredientLines,
"ingredients" => $recipeInfo->ingredients,
"recipe_calories" => $recipeInfo->calories,
"recipe_totalTime" => $recipeInfo->totalTime,
"recipe_url" => $recipeInfo->url,
"recipe_image" => $recipeInfo->image
);
array_push($jsonItem, $currRecipe);
}
}
}
}
return $this->json($jsonItem);
}
/**
* @Route("/breakdown-recipe")
*/
public function getSingleRecipe(Request $request) {
/*
$entityManager = $this->getDoctrine()->getManager();
$recipeInfo = new RecipeInfo();
*/
//$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findAll();
//$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->find($recipeId);
//$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($recipeId);
//$queryStr = ['chicken'];
/*
$queryStr = $request->query->get('ingredientsData');
$recipeInfo = [];
if(isset($queryStr)) {
$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($queryStr);
}
*/
$queryStr = $request->query->get('id');
$recipeInfo = [];
if(isset($queryStr)) {
//$recipeInfo = $this->getDoctrine()->getRepository(RecipeInfo::class)->findByExampleField($queryStr);
$ch = curl_init();
//$query = implode(",", $queryStr);
//$newStr = 'recipe_5831ed782d73f56e9437e28feff625bf';
$url = 'https://api.edamam.com/api/recipes/v2/' . $queryStr . '?app_id=91fb41c0&app_key=f4714ea59c5315a0a39801c8b26c86ff&to=25&type=public';
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HEADER, TRUE); //
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch,CURLOPT_USERAGENT,'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)');
//$output=curl_exec($ch);
$content = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
curl_close($ch);
}
$jsonItem = [];
$recipeInfo = json_decode($content);
//foreach($recipeInfo->hits as $items) {
//var_dump($recipeInfo);
//var_dump($items);
if($recipeInfo) {
$currRecipe = array(
"recipe_id" => $recipeInfo->recipe->uri,
"name" => $recipeInfo->recipe->label,
"ingredient_name" => "ingredient",
"ingredient_lines" => $recipeInfo->recipe->ingredientLines,
"ingredients" => $recipeInfo->recipe->ingredients,
"recipe_calories" => $recipeInfo->recipe->calories,
"recipe_totalTime" => $recipeInfo->recipe->totalTime,
"recipe_url" => $recipeInfo->recipe->url,
"recipe_image" => $recipeInfo->recipe->image,
"total_calories" => $recipeInfo->recipe->totalNutrients->ENERC_KCAL->quantity,
"total_fat" => $recipeInfo->recipe->totalNutrients->FAT->quantity,
"total_carbs" => $recipeInfo->recipe->totalNutrients->CHOCDF->quantity,
"total_sodium" => $recipeInfo->recipe->totalNutrients->NA->quantity,
"total_protein" => $recipeInfo->recipe->totalNutrients->PROCNT->quantity,
"total_fiber" => $recipeInfo->recipe->totalNutrients->FIBTG->quantity,
//"total_nutrients" => $recipeInfo->recipe->totalNutrients
);
array_push($jsonItem, $currRecipe);
}
//}
return $this->json($jsonItem);
}
/**
* @Route("/hello", name="recipe")
*/
public function hello() {
//return new Response("hello there");
$jsonItem = [];
$currRecipe = array(
"recipe_id" => 1,
"name" => "myRecipe",
"ingredient_name" => "ingredient",
"recipe_calories" => 0,
"recipe_totalTime" => 2,
"recipe_url" => 'url',
"recipe_image" => 'image'
);
array_push($jsonItem, $currRecipe);
return $this->json($jsonItem);
}
/**
* @Route("/playerData", name="player")
*/
public function playerData() {
//return new Response("hello there");
$entityManager = $this->getDoctrine()->getManager();
$teamPlayers = new TeamPlayers();
// $teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findAll();
$teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findByExampleField('2019-2020');
// print_r($teamPlayers);
// $arrayCollection = array();
// foreach($teamPlayers as $item) {
// $arrayCollection[] = array(
// 'team_city' => $item->getTeamCity(),
// 'team_name' => $item->getTeamName(),
// 'first_name' => $item->getFirstName(),
// 'last_name' => $item->getLastName(),
// 'season' => $item->getSeason(),
// 'player_image_path' => $item->getPlayerImagePath()
// );
// }
$myPlayers = array();
foreach($teamPlayers as $item) {
$arrayCollection = array(
'team_city' => $item->getTeamCity(),
'team_name' => $item->getTeamName(),
'first_name' => $item->getFirstName(),
'last_name' => $item->getLastName(),
'season' => $item->getSeason(),
'player_image_path' => $item->getPlayerImagePath()
);
array_push($myPlayers,$arrayCollection);
}
$someCollection["teamPlayers"] = $myPlayers;
return new JsonResponse($someCollection);
}
/**
* @Route("/slatePlayerListData", name="slatePlayerListData")
*/
public function slatePlayerListData() {
//return new Response("hello there");
$entityManager = $this->getDoctrine()->getManager();
$slatePlayerList = new SlatePlayerList();
$slatePlayerList = $this->getDoctrine()->getRepository(SlatePlayerList::class)->findAll();
// $teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findByExampleField('2019-2020');
// print_r($slatePlayerList);
$arrayCollection = array();
foreach($slatePlayerList as $item) {
$arrayCollection[] = array(
'last_name' => $item->getLastName(),
'salary' => $item->getSalary(),
'position' => $item->getPosition()
);
}
return new JsonResponse($arrayCollection);
}
/**
* @Route("/combinedPlayerData", name="combinedPlayerData")
*/
public function combinedPlayerData(Request $request) {
//return new Response("hello there");
$entityManager = $this->getDoctrine()->getManager();
$slatePlayerList = new SlatePlayerList();
$queryStr = $request->query->get('date');
$slatePlayerList = $this->getDoctrine()->getRepository(SlatePlayerList::class)->findByAllField($queryStr);
// $teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findByExampleField('2019-2020');
//print_r($slatePlayerList);
// print_r('some break;');
// foreach($slatePlayerList as $item) {
// print_r($item);
// echo "<br><br>";
// }
$myPlayers = array();
foreach($slatePlayerList as $item) {
$arrayCollection = array(
'first_name' => $item["firstName"],
'last_name' => $item["lastName"],
'fpg' => $item["fpg"],
'played' => $item["played"],
'salary' => $item["salary"],
'position' => $item["position"],
'team' => $item["team"],
'opponent' => $item["opponent"],
'injury_indicator' => $item["injuryIndicator"],
'gameVS' => $item["game"],
'player_slate_id' => $item["playerSlateId"],
'team_city' => $item["teamCity"],
'team_name' => $item["teamName"],
'team_abbr' => $item["teamAbbr"],
'season' => $item["season"],
'player_image_path' => $item["playerImagePath"],
'total_fp' => $item["totalFP"]
);
array_push($myPlayers,$arrayCollection);
}
$someCollection["teamPlayers"] = $myPlayers;
return new JsonResponse($someCollection);
}
/**
* @Route("/getSlateDates", name="getSlateDates")
*/
public function getSlateDates(Request $request) {
//return new Response("hello there");
$entityManager = $this->getDoctrine()->getManager();
$slatePlayerList = new SlatePlayerList();
//$queryStr = $request->query->get('date');
$slatePlayerList = $this->getDoctrine()->getRepository(SlatePlayerList::class)->findByDates("");
// $teamPlayers = $this->getDoctrine()->getRepository(TeamPlayers::class)->findByExampleField('2019-2020');
//print_r($slatePlayerList);
// print_r('some break;');
// foreach($slatePlayerList as $item) {
// print_r($item);
// echo "<br><br>";
// }
$myDates = array();
foreach($slatePlayerList as $item) {
$arrayCollection = array(
'date_played' => $item["datePlayed"],
);
array_push($myDates,$arrayCollection);
}
$someCollection["slatesPlayed"] = $myDates;
return new JsonResponse($someCollection);
// $arrayCollection = array();
// foreach($teamPlayers as $item) {
// $arrayCollection[] = array(
// 'date_played' => $item->getDatePlayed();
// );
// }
// return new JsonResponse($arrayCollection);
}
}