public function load()
 {
     $this->clear();
     // Alfredo Rodriguez (Maryland)
     $player = new Player();
     $player->setFirstName('Alfredo');
     $player->setLastName('Rodriguez');
     $player->setHeight(72);
     $player->setWeight(180);
     $player->setBats('R');
     $player->setThrows('R');
     $player->setHometown('Oak Hill, Va.');
     $player->setCstvId(395839);
     $player->setNcaaId(993788);
     $player->save();
     print_r(sprintf("Created Player: %s (%s)\n", $player->getName(), $player->getId()));
 }
 protected function saveTeamSeasonForPlayers($players, $team)
 {
     $list = array();
     $this->CI->load->model('playerRepository', '_player');
     foreach ($players as $ncaaId => $stats) {
         $player = $this->CI->_player->findOneByNcaaId($ncaaId);
         $name = explode(',', $stats[0]);
         if (!$player) {
             $player = new Player();
             $player->setNcaaId($ncaaId);
             $player->setFirstName(trim($name[1]));
             $player->setLastName(trim($name[0]));
             $player->save();
         }
         if (!$player->getFirstName()) {
             $player->setFirstName(trim($name[1]));
         }
         if (!$player->getLastName()) {
             $player->setLastName(trim($name[0]));
         }
         $year = explode('-', $stats[2]);
         $year = date('Y', strtotime("january 1, " . $year[1]));
         if ($this->output) {
             print_r("Checking for Player Season with Year: " . $year . "\n");
         }
         $season = $player->getSeason($year);
         if (!$season) {
             if ($this->output) {
                 print_r("No Season for Player, Creating New Season\n");
             }
             $season = new Season();
         }
         $season->setYear($year);
         $season->setClass($stats[1]);
         $season->setPosition($stats[3]);
         $season->setTeam($team);
         $season->setGames($stats[4]);
         $season->setAtBats($stats[5]);
         $season->setRuns($stats[6]);
         $season->setHits($stats[7]);
         $season->setDoubles($stats[9]);
         $season->setTriples($stats[10]);
         $season->setHomeRuns($stats[11]);
         $season->setTotalBases($stats[12]);
         $season->setRunsBattedIn($stats[14]);
         $season->setStolenBases($stats[15]);
         $season->setStolenBaseAttempts($stats[16]);
         $season->setWalks($stats[17]);
         $season->setStrikeouts($stats[18]);
         $season->setHitByPitch($stats[19]);
         $season->setSacrificeHits($stats[20]);
         $season->setSacrificeFlies($stats[21]);
         $season->setAppearances($stats[22]);
         $season->setGamesStarted($stats[23]);
         $season->setCompleteGames($stats[24]);
         $season->setWins($stats[25]);
         $season->setLosses($stats[26]);
         $season->setSaves($stats[27]);
         $season->setShutouts($stats[28]);
         $season->setInningsPitched($stats[29]);
         $season->setHitsAllowed($stats[30]);
         $season->setRunsAllowed($stats[31]);
         $season->setEarnedRuns($stats[32]);
         $season->setWalksAllowed($stats[33]);
         $season->setStrikeoutsPitched($stats[34]);
         $player->addSeason($season);
         //print_r($player);
         //print_r('<br /><br />');
         $player->save();
         if ($this->output) {
             print_r("Player with Season:\n");
         }
         if ($this->output) {
             print_r($player);
         }
         $list[] = $player;
     }
     if ($this->output) {
         print_r("List of Players:\n");
     }
     if ($this->output) {
         print_r($list);
     }
     return $list;
 }
 public function importPitchers($real = false, $year = 0)
 {
     if ($real) {
         $file = "./web/utilities/bw-pitching.csv";
     } else {
         $file = "./web/utilities/bw-pitching-test.csv";
     }
     $row = 0;
     if (($handle = fopen($file, "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
             if ($row) {
                 if ($data[0] >= $year) {
                     $player = utf8_encode($data[2]);
                     $slug = $this->CI->slugify->simple($player);
                     $player = $this->CI->_player->findOneBySlug($slug);
                     $team = utf8_encode($data[1]);
                     $slug = $this->CI->slugify->simple($team);
                     $team = $this->CI->_team->findOneBySlug($slug);
                     $year = $data[0];
                     if ($team) {
                         if ($player) {
                             $season = $this->CI->_season->findOneBySourceAndPlayerAndYear('Boydsworld', $player, $year);
                             $official = $this->CI->_season->findOneBySourceAndPlayerAndYear('Smallball', $player, $year);
                         }
                         if (!$season) {
                             $season = new Season();
                         }
                         $num = count($data);
                         for ($c = 0; $c < $num; $c++) {
                             $method = 'set' . ucwords($this->pitcher[$c]);
                             if (method_exists($season, $method)) {
                                 $season->{$method}($data[$c]);
                                 if ($official) {
                                     $official->{$method}($data[$c]);
                                 }
                             }
                         }
                         //print_r($season);
                         $season->setPlayer(utf8_encode($season->getPlayer()));
                         $season->setLevel('College');
                         $season->setLeague('NCAA');
                         $season->setDivision('D1');
                         /* Save Player */
                         if (!$player) {
                             $player = new Player();
                             $name = $season->getPlayer();
                             $name = explode(' ', $name);
                             if (isset($name[count($name) - 1])) {
                                 $player->setLastName(utf8_encode($name[count($name) - 1]));
                             }
                             $name = array_splice($name, 0, count($name) - 1);
                             $name = implode(' ', $name);
                             if (isset($name)) {
                                 $player->setFirstName(utf8_encode($name));
                             }
                             print_r("Adding Player: " . $team->getName() . ", " . $player->getName() . ", " . $season->getYear() . "\n");
                             $player->save();
                         } else {
                             print_r("Existing Player: " . $team->getName() . ", " . $player->getName() . ", " . $season->getYear() . "\n");
                         }
                         $season->setPlayer($player);
                         $season->setTeam($team);
                         $season->setSource('Boydsworld');
                         $season->save();
                         if (!$official) {
                             $official = clone $season;
                             $official->setSource('Smallball');
                         }
                         $official->setPlayer($player);
                         $official->setTeam($team);
                         $official->save();
                         $teamOfficial = $this->CI->_season->findOneOfficialByTeamAndYear($team, $season->getYear());
                         if ($teamOfficial) {
                             $teamOfficial->addPlayer($player);
                             $teamOfficial->save();
                         }
                     }
                     // end team
                 }
                 // end year
             }
             //row
             $row++;
         }
         fclose($handle);
     }
 }
 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->downloader->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->downloader->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();
 }