コード例 #1
0
 /**
  * Load match info by match_id
  */
 public function load()
 {
     $request = new request(self::STEAM_MATCH_URL, array('match_id' => $this->getMatchId()));
     $matchInfo = $request->send();
     if (null === $matchInfo) {
         return null;
     }
     $match = new Match();
     $players = array();
     foreach ($matchInfo->players->player as $key => $player) {
         $players[] = $player;
     }
     $data = (array) $matchInfo;
     unset($data['players']);
     $data['start_time'] = date('Y-m-d H:i:s', $data['start_time']);
     $data['radiant_win'] = $data['radiant_win'] === 'true' ? '1' : '0';
     $match->setArray($data);
     // slots info
     foreach ($players as $player) {
         $data = (array) $player;
         $data['match_id'] = $this->getMatchId();
         $slot = new Slot();
         $slot->setArray($data);
         // additional_units
         if (array_key_exists('additional_units', $data)) {
             $slot->setAdditionalUnitItems((array) $data['additional_units']->unit);
         }
         // abilities
         if (array_key_exists('ability_upgrades', $data)) {
             $d = (array) $data['ability_upgrades'];
             $abilitiesUpgrade = $d['ability'];
             if (!is_array($abilitiesUpgrade)) {
                 $abilitiesUpgrade = array($abilitiesUpgrade);
             }
             foreach ($abilitiesUpgrade as $k => $v) {
                 $abilitiesUpgrade[$k] = (array) $abilitiesUpgrade[$k];
             }
             $slot->setAbilitiesUpgrade($abilitiesUpgrade);
         }
         $match->addSlot($slot);
     }
     if (isset($matchInfo->picks_bans)) {
         $picksBans = (array) $matchInfo->picks_bans;
         foreach ($picksBans['pick_ban'] as $k => $v) {
             $picksBans['pick_ban'][$k] = (array) $v;
             $picksBans['pick_ban'][$k]['is_pick'] = filter_var($picksBans['pick_ban'][$k]['is_pick'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
         }
         $match->setAllPickBans($picksBans['pick_ban']);
     }
     return $match;
 }
コード例 #2
0
 /**
  * Load matches from db
  *
  * Possible filters: league_id, hero_id, account_id, start_at_match_id
  * Also matches_requested used as LIMIT
  * @return Match[]
  */
 public function load()
 {
     $matchesInfo = $this->_getMatchesIdsFromMatches();
     $matchesIds = array();
     foreach ($matchesInfo as $matchInfo) {
         array_push($matchesIds, $matchInfo['match_id']);
     }
     if (count($matchesIds) === 0) {
         return array();
     }
     $slotsInfo = $this->_loadSlotsInfo($matchesIds);
     $picksBansFormattedInfo = $this->_loadPicksBansInfo($matchesIds);
     $slotsIds = array();
     foreach ($slotsInfo as $slotInfo) {
         array_push($slotsIds, $slotInfo['id']);
     }
     $abilitiesUpgradeFormattedInfo = $this->_loadAbilityUpgradesInfo($slotsIds);
     $additionalUnitsFormattedInfo = $this->_loadAdditionalUnitsInfo($slotsIds);
     // we load all matches info and now need to make proper match objects
     $matches = array();
     foreach ($matchesInfo as $matchInfo) {
         $match = new Match();
         $match->setArray($matchInfo);
         $slots_count = 0;
         foreach ($slotsInfo as $slotInfo) {
             if ($slots_count > 9) {
                 // match can't has more than 10 slots
                 break;
             }
             if ((int) $slotInfo['match_id'] === (int) $match->get('match_id')) {
                 $slot = new slot();
                 $slot->setArray($slotInfo);
                 if (array_key_exists($slot->get('id'), $abilitiesUpgradeFormattedInfo)) {
                     $slot->setAbilitiesUpgrade($abilitiesUpgradeFormattedInfo[$slot->get('id')]);
                 }
                 if (array_key_exists($slot->get('id'), $additionalUnitsFormattedInfo)) {
                     $slot->setAdditionalUnitItems($additionalUnitsFormattedInfo[$slot->get('id')]);
                 }
                 $match->addSlot($slot);
                 $slots_count++;
             }
         }
         if (array_key_exists($match->get('match_id'), $picksBansFormattedInfo)) {
             $match->setAllPickBans($picksBansFormattedInfo[$match->get('match_id')]);
         }
         $matches[$match->get('match_id')] = $match;
     }
     return $matches;
 }
コード例 #3
0
 /**
  * @param int $matchId
  * @return match
  */
 public function load($matchId = null)
 {
     if (null !== $matchId) {
         $this->setMatchId($matchId);
     }
     $db = Db::obtain();
     $queryForMatch = 'SELECT * FROM ' . Db::realTablename('matches') . ' WHERE match_id=?';
     $queryForSlots = 'SELECT * FROM ' . Db::realTablename('slots') . ' WHERE match_id=?';
     $matchInfo = $db->queryFirstPDO($queryForMatch, array($this->getMatchId()));
     $match = new Match();
     if (!$matchInfo) {
         return $match;
     }
     $match->setArray($matchInfo);
     $slots = $db->fetchArrayPDO($queryForSlots, array($this->getMatchId()));
     $slotIds = '';
     foreach ($slots as $slot) {
         $slotIds .= $slot['id'] . ',';
     }
     $queryForAbilityUpgrades = 'SELECT * FROM ' . Db::realTablename('ability_upgrades') . ' WHERE slot_id IN (' . rtrim($slotIds, ',') . ')';
     $abilityUpgrade = $db->fetchArrayPDO($queryForAbilityUpgrades);
     $abilityUpgradeFormatted = array();
     foreach ($abilityUpgrade as $a) {
         if (!array_key_exists($a['slot_id'], $abilityUpgradeFormatted)) {
             $abilityUpgradeFormatted[$a['slot_id']] = array();
         }
         array_push($abilityUpgradeFormatted[$a['slot_id']], $a);
     }
     $queryForAdditionalUnits = 'SELECT * FROM ' . Db::realTablename('additional_units') . ' WHERE slot_id IN  (' . rtrim($slotIds, ',') . ')';
     $additionalUnits = $db->fetchArrayPDO($queryForAdditionalUnits);
     $additionalUnitsFormatted = array();
     foreach ($additionalUnits as $additionalUnit) {
         if (!array_key_exists($additionalUnit['slot_id'], $additionalUnitsFormatted)) {
             $additionalUnitsFormatted[$additionalUnit['slot_id']] = array();
         }
         array_push($additionalUnitsFormatted[$additionalUnit['slot_id']], $additionalUnit);
     }
     foreach ($slots as $s) {
         $slot = new Slot();
         $slot->setArray($s);
         if (array_key_exists($slot->get('id'), $abilityUpgradeFormatted)) {
             $slot->setAbilitiesUpgrade($abilityUpgradeFormatted[$slot->get('id')]);
         }
         if (array_key_exists($slot->get('id'), $additionalUnitsFormatted)) {
             $slot->setAdditionalUnitItems($additionalUnitsFormatted[$slot->get('id')]);
         }
         $match->addSlot($slot);
     }
     if ($match->get('game_mode') === match::CAPTAINS_MODE) {
         $queryForPicksBans = 'SELECT `is_pick`, `hero_id`, `team`, `order` FROM ' . Db::realTablename('picks_bans') . ' WHERE match_id = ? ORDER BY `order`';
         $picks_bans = $db->fetchArrayPDO($queryForPicksBans, array($match->get('match_id')));
         $match->setAllPickBans($picks_bans);
     }
     return $match;
 }