/** * @return array */ public function load() { $request = new request(self::steam_matches_url, $this->_get_data_array()); $xml = $request->send(); if (is_null($xml)) { return null; } $matches = array(); if (isset($xml->matches)) { $this->_total_results = $xml->total_results; foreach ($xml->matches as $m_matches) { foreach ($m_matches as $m) { $match = new match(); $match->set_array((array) $m); foreach ($m->players as $players) { foreach ($players as $player) { $slot = new slot(); $slot->set_array((array) $player); $match->add_slot($slot); } } $matches[$match->get('match_id')] = $match; } } } return $matches; }
/** * Load matches from db * * Possible filters: league_id, hero_id, account_id, start_at_match_id * Also matches_requested used as LIMIT * @return array */ public function load() { $matches_info = $this->_get_matches_ids_from_matches(); $matches_ids = array(); foreach ($matches_info as $match_info) { array_push($matches_ids, $match_info['match_id']); } if (count($matches_ids) == 0) { return array(); } $slots_info = $this->_load_slots_info($matches_ids); $picks_bans_formatted_info = $this->_load_picks_bans_info($matches_ids); $slots_ids = array(); foreach ($slots_info as $slot_info) { array_push($slots_ids, $slot_info['id']); } $abilities_upgrade_formatted_info = $this->_load_ability_upgrades_info($slots_ids); $additional_units_formatted_info = $this->_load_additional_units_info($slots_ids); // we load all matches info and now need to make proper match objects $matches = array(); foreach ($matches_info as $match_info) { $match = new match(); $match->set_array($match_info); $slots_count = 0; foreach ($slots_info as $slot_info) { if ($slots_count > 9) { // match can't has more than 10 slots break; } if ($slot_info['match_id'] == $match->get('match_id')) { $slot = new slot(); $slot->set_array($slot_info); if (isset($abilities_upgrade_formatted_info[$slot->get('id')])) { $slot->set_abilities_upgrade($abilities_upgrade_formatted_info[$slot->get('id')]); } if (isset($additional_units_formatted_info[$slot->get('id')])) { $slot->set_additional_unit_items($additional_units_formatted_info[$slot->get('id')]); } $match->add_slot($slot); $slots_count++; } } if (isset($picks_bans_formatted_info[$match->get('match_id')])) { $match->set_all_pick_bans($picks_bans_formatted_info[$match->get('match_id')]); } $matches[$match->get('match_id')] = $match; } return $matches; }
/** * @param match $match * @param bool $lazy if true - update all data, if false - only possible updated data */ public function update($match, $lazy = true) { $db = db::obtain(); $slots = $match->get_all_slots(); // update common match info $db->update_pdo(db::real_tablename('matches'), $match->get_data_array(), array('match_id' => $match->get('match_id'))); foreach ($slots as $slot) { // update accounts $db->update_pdo(db::real_tablename('users'), array('account_id' => $slot->get('account_id'), 'steamid' => player::convert_id($slot->get('account_id'))), array('account_id' => $slot->get('account_id'))); // update slots if (!$lazy) { $db->update_pdo(db::real_tablename('slots'), $slot->get_data_array(), array('match_id' => $slot->get('match_id'), 'player_slot' => $slot->get('player_slot'))); } } }