/** * @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; }
/** * 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; }
/** * 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; }
/** * @param Match $match * @param bool $lazy if false - update all data, if true - only possible updated data */ public function update(Match $match, $lazy = true) { $db = Db::obtain(); $slots = $match->getAllSlots(); // update common match info $db->updatePDO(Db::realTablename('matches'), $match->getDataArray(), array('match_id' => $match->get('match_id'))); foreach ($slots as $slot) { // update accounts $db->updatePDO(Db::realTablename('users'), array('account_id' => $slot->get('account_id'), 'steamid' => Player::convertId($slot->get('account_id'))), array('account_id' => $slot->get('account_id'))); // update slots if (!$lazy) { $db->updatePDO(Db::realTablename('slots'), $slot->getDataArray(), array('match_id' => $slot->get('match_id'), 'player_slot' => $slot->get('player_slot'))); } } }