/** * Populates the collection of business objects from raw data * * @return bool * @param MySqlRawData $o_result */ protected function BuildItems(MySqlRawData $o_result) { /* @var $o_season Season */ $this->Clear(); # use CollectionBuilder to handle duplicates $o_season_builder = new CollectionBuilder(); $o_team_builder = new CollectionBuilder(); $o_rule_builder = new CollectionBuilder(); $o_points_builder = new CollectionBuilder(); $o_type_builder = new CollectionBuilder(); $o_season = null; while ($o_row = $o_result->fetch()) { # check whether this is a new season if (!$o_season_builder->IsDone($o_row->season_id)) { # store any exisiting season and reset if ($o_season != null) { $this->Add($o_season); $o_team_builder->Reset(); $o_rule_builder->Reset(); $o_points_builder->Reset(); $o_type_builder->Reset(); } # create the new season $o_season = new Season($this->GetSettings()); $this->BuildSeason($o_season, $o_row); } # Teams the first cause of multiple rows if (isset($o_row->team_id)) { if (!$o_team_builder->IsDone($o_row->team_id)) { if (isset($o_team)) { unset($o_team); } $o_team = new Team($this->GetSettings()); $o_team->SetId($o_row->team_id); $o_team->SetName($o_row->team_name); $ground = new Ground($this->GetSettings()); $ground->SetId($o_row->team_ground_id); $o_team->SetGround($ground); if (isset($o_row->team_short_url)) { $o_team->SetShortUrl($o_row->team_short_url); } $o_season->AddTeam($o_team); if (isset($o_row->withdrawn_league) and (bool) $o_row->withdrawn_league) { $o_season->TeamsWithdrawnFromLeague()->Add($o_team); } } # Points adjustments - should come with team and in order of team if (isset($o_row->point_id) and !$o_points_builder->IsDone($o_row->point_id)) { $o_point = new PointsAdjustment($o_row->point_id, $o_row->points, $o_team, $o_row->reason, $o_row->points_date); $o_season->PointsAdjustments()->Add($o_point); } } # Season rules if (isset($o_row->season_rule_id) and !$o_rule_builder->IsDone($o_row->season_rule_id)) { $o_mr = new MatchResult($o_row->match_result_id); $o_mr->SetHomePoints($o_row->home_points); $o_mr->SetAwayPoints($o_row->away_points); $o_season->PossibleResults()->Add($o_mr); unset($o_mr); } # Match types if (isset($o_row->season_match_type) and !$o_type_builder->IsDone($o_row->season_match_type)) { $o_season->MatchTypes()->Add((int) $o_row->season_match_type); } } # store final season if ($o_season != null) { $this->Add($o_season); } return true; }