Пример #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
 /**
  * @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;
 }
Пример #3
0
 /**
  * @return array
  */
 public function load()
 {
     $request = new Request(self::STEAM_MATCHES_URL, $this->_getDataArray());
     $xml = $request->send();
     if (null === $xml) {
         return null;
     }
     $matches = array();
     if (isset($xml->matches)) {
         $this->_total_results = $xml->total_results;
         $this->_results_remaining = $xml->results_remaining;
         foreach ($xml->matches as $m_matches) {
             foreach ($m_matches as $m) {
                 $match = new Match();
                 $match->setArray((array) $m);
                 foreach ($m->players as $players) {
                     foreach ($players as $player) {
                         $slot = new Slot();
                         $slot->setArray((array) $player);
                         $match->addSlot($slot);
                     }
                 }
                 $matches[$match->get('match_id')] = $match;
             }
         }
     }
     return $matches;
 }