src/Controller/Api/PlayerSportsInjuriesController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Customer;
  4. use App\Entity\PlayerSportsInjuries;
  5. use App\Services\Api\PlayerSportsInjuriesManager;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class PlayerSportsInjuriesController extends ApiController
  12. {
  13.   /** @var PlayerSportsInjuriesManager $playerSportsInjuriesManager */
  14.   protected $playerSportsInjuriesManager;
  15.   /**
  16.    * @param PlayerSportsInjuriesManager $playerSportsInjuriesManager
  17.    */
  18.   public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagPlayerSportsInjuriesManager $playerSportsInjuriesManager)
  19.   {
  20.     parent::__construct($em$parameterBag);
  21.     $this->playerSportsInjuriesManager $playerSportsInjuriesManager;
  22.   }
  23.   /**
  24.    * @param Request $request
  25.    * @return JsonResponse
  26.    *
  27.    * @Route("/player_sports_injuries/add", name="api_player_sports_injuries", methods={"POST"})
  28.    */
  29.   public function add(Request $request)
  30.   {
  31.     $request $this->transformJsonBody($request);
  32.     $data $this->getDataFromRequest($request);
  33.     $response $this->playerSportsInjuriesManager->add($data$request);
  34.     return $this->response($response);
  35.   }
  36.   /**
  37.    * @param Request $request
  38.    * @return JsonResponse
  39.    *
  40.    * @Route("/player_sports_injuries/{id}/update", name="api_player_sports_injuries_update", methods={"POST"})
  41.    */
  42.   public function update(PlayerSportsInjuries $playerInjuryRequest $request)
  43.   {
  44.     $request $this->transformJsonBody($request);
  45.     $data $this->getDataFromRequest($request);
  46.     $response $this->playerSportsInjuriesManager->update($playerInjury$data$request);
  47.     return $this->response($response);
  48.   }
  49.   /**
  50.    * @param Request $request
  51.    * @return JsonResponse
  52.    *
  53.    * @Route("/player_sports_injuries/{date}", name="api_player_sports_injuries_me", methods={"POST"})
  54.    */
  55.   public function getSharePlayerMe($dateRequest $request)
  56.   {
  57.     /** @var Customer $customer */
  58.     $customer $this->getUser();
  59.     $season $customer->getSeasonActive();
  60.     if (!empty($season)) {
  61.       $filter = [
  62.         [
  63.           "prop" => "finish",
  64.           "comp" => "=",
  65.           "val" => 0
  66.         ],
  67.         [
  68.           "prop" => "season",
  69.           "comp" => "=",
  70.           "val" => $season
  71.         ],
  72.         [
  73.           "prop" => "dateStart",
  74.           "comp" => ">=",
  75.           "val" => \DateTime::createFromFormat("d-m-Y"$date)->format('d-m-Y')
  76.         ],
  77.       ];
  78.       /** @var PlayerSportsInjuries $playersSportInjuries */
  79.       $playersSportInjuries = [];
  80.       foreach ($this->em->getRepository(PlayerSportsInjuries::class)->findByOwnCriteria($filter) as $playerSport) {
  81.         $playersSportInjuries[] = $playerSport->__toArray();
  82.       }
  83.       return $this->response($playersSportInjuries);
  84.     }
  85.   }
  86.   /**
  87.    * @param Request $request
  88.    * @return JsonResponse
  89.    *
  90.    * @Route("/player_sports/delete/{id}", name="api_share_player_delete", methods={"POST"})
  91.    */
  92.   public function delete(Int $id)
  93.   {
  94.     $response $this->playerSportsInjuriesManager->delete($id);
  95.     return $this->response($response);
  96.   }
  97.   protected function getDataFromRequest(Request $request)
  98.   {
  99.     $data = [
  100.       "playerId" => $request->get('playerId'),
  101.     ];
  102.     if ($request->get('note')) {
  103.       $data['note'] = $request->get('note');
  104.     }
  105.     if ($request->get('dateStart')) {
  106.       $data["dateStart"] = \DateTime::createFromFormat("d-m-Y"$request->get('dateStart'));
  107.     }
  108.     if ($request->get('dateEnd')) {
  109.       $data['dateEnd'] = \DateTime::createFromFormat("d-m-Y"$request->get('dateEnd'));
  110.     }
  111.     return $data;
  112.   }
  113. }