/**
  * 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;
 }
 /**
  * @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;
 }
 /**
  * @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')));
         }
     }
 }