public function getSquads(Team $team) { $params = array('age' => '', 'ageComparisonType' => '', 'appearances' => '', 'appearancesComparisonType' => '', 'category' => 'summary', 'field' => 'Overall', 'includeZeroValues' => 'true', 'isCurrent' => 'true', 'isMinApp' => 'false', 'matchId' => '', 'nationality' => '', 'numberOfPlayersToPick' => '', 'page' => '', 'playerId' => '', 'positionOptions' => '', 'sotAscending' => '', 'sortBy' => 'Rating', 'stageId' => '', 'statsAccumulationType' => 0, 'subcategory' => 'all', 'teamIds' => $team->getWsId(), 'timeOfTheGameEnd' => '', 'timeOfTheGameStart' => '', 'tournamentOptions' => ''); try { $data = $this->whoscored->loadStatistics('player-stats', $params); } catch (\Exception $e) { throw $e; } if (empty($data->playerTableStats)) { throw new \Exception('No player data found'); } foreach ($data->playerTableStats as $playerData) { $player = null; if (array_key_exists($playerData->playerId, $this->players)) { $player = $this->players[$playerData->playerId]; } else { $player = $this->em->getRepository('AppBundle:Player')->findOneByWsId($playerData->playerId); } if ($player == null) { $player = new Player(); $player->setFirstName($playerData->firstName); $player->setLastName($playerData->lastName); $player->setKnownName($playerData->name); $player->setAge($playerData->age); $player->setWsId($playerData->playerId); if ($playerData->isActive == false) { $teamId = $this->whoscored->getActiveTeam($playerData->playerId); try { $ret = $this->getTeam($teamId); $player->setTeam($ret); } catch (\Exception $e) { } } else { $player->setTeam($team); } $this->em->persist($player); } $this->players[$playerData->playerId] = $player; } $this->em->flush(); }