/** * @param int $match_id * @return match */ public function load($match_id = null) { if (!is_null($match_id)) { $this->set_match_id($match_id); } $db = db::obtain(); $query_for_match = 'SELECT * FROM ' . db::real_tablename('matches') . ' WHERE match_id=?'; $query_for_slots = 'SELECT * FROM ' . db::real_tablename('slots') . ' WHERE match_id=?'; $match_info = $db->query_first_pdo($query_for_match, array($this->get_match_id())); $match = new match(); if (!$match_info) { return $match; } $match->set_array($match_info); $slots = $db->fetch_array_pdo($query_for_slots, array($this->get_match_id())); $slot_ids = ''; foreach ($slots as $slot) { $slot_ids .= $slot['id'] . ','; } $query_for_ability_upgrades = 'SELECT * FROM ' . db::real_tablename('ability_upgrades') . ' WHERE slot_id IN (' . rtrim($slot_ids, ',') . ')'; $ability_upgrade = $db->fetch_array_pdo($query_for_ability_upgrades); $ability_upgrade_formatted = array(); foreach ($ability_upgrade as $a) { if (!isset($ability_upgrade_formatted[$a['slot_id']])) { $ability_upgrade_formatted[$a['slot_id']] = array(); } array_push($ability_upgrade_formatted[$a['slot_id']], $a); } $query_for_additional_units = 'SELECT * FROM ' . db::real_tablename('additional_units') . ' WHERE slot_id IN (' . rtrim($slot_ids, ',') . ')'; $additional_units = $db->fetch_array_pdo($query_for_additional_units); $additional_units_formatted = array(); foreach ($additional_units as $additional_unit) { if (!isset($additional_units_formatted[$additional_unit['slot_id']])) { $additional_units_formatted[$additional_unit['slot_id']] = array(); } array_push($additional_units_formatted[$additional_unit['slot_id']], $additional_unit); } foreach ($slots as $s) { $slot = new slot(); $slot->set_array($s); if (isset($ability_upgrade_formatted[$slot->get('id')])) { $slot->set_abilities_upgrade($ability_upgrade_formatted[$slot->get('id')]); } if (isset($additional_units_formatted[$slot->get('id')])) { $slot->set_additional_unit_items($additional_units_formatted[$slot->get('id')]); } $match->add_slot($slot); } if ($match->get('game_mode') == match::CAPTAINS_MODE) { $query_for_picks_bans = 'SELECT `is_pick`, `hero_id`, `team`, `order` FROM ' . db::real_tablename('picks_bans') . ' WHERE match_id = ? ORDER BY `order`'; $picks_bans = $db->fetch_array_pdo($query_for_picks_bans, array($match->get('match_id'))); $match->set_all_pick_bans($picks_bans); } 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; }
/** * 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; }
/** * Add new slot for slots-array * @param slot $slot * @return match */ public function add_slot(slot $slot) { $this->_slots[$slot->get('player_slot')] = $slot; return $this; }