Hi Everyone
I am building a site for a rugby club in the UK.
A fixture has 2 teams, home and away, it also has many players (PlayerResult)
PlayerResult records who is playing at that fixture and how they did, i.e. player 1 score 2 goals.
A player has one team
In the admin system, I want my users to be able to add a new fixture, then in a tab Called "Home Team", which displays all the players for that team, tick which players are playing then be able to add how many tries and how many goals they scores for that fixture. Then repeat this for the away team.
I am finding it difficult to work out the correct way to do this, i need help with how to work out the CMS fields for fixtures and to make sure it populates with the correct team data for each based on HomeTeam and AwayTeam IDs. Below is some sample code, comments welcome!
class Fixture extends Page
public static $has_one = array(
'HomeTeam' => 'Team',
'AwayTeam' => 'Team'
);
static $has_many = array (
'EventImageResources' =>'EventImageResource',
'FixturePlayers' => 'FixturePlayer'
);
class TeamPlayer extends DataObject {
public static $db = array(
'PlayerName' => 'Text',
'PlayerPosition' => 'Text'
);
public static $has_one = array(
'Team' => 'Team'
);
public static $has_many = array(
'PlayerResults' => 'PlayerResult'
);
}
class PlayerResult extends DataObject {
public static $db = array(
'Tries' => 'Int',
'Goals' => 'Int'
);
public static $has_one = array(
'TeamPlayer' => 'TeamPlayer',
'Fixture' => 'Fixture'
);
function getCMSFields_forPopup() {
$fields = new FieldSet();
$oData = (DataObject::get('TeamPlayer','','',SOME LEFT JOIN NEEDS TO BE HERE,''));
if ($oData) {
$CategoriesSource = $oData->toDropDownMap('ID','PlayerName');
} else {
// no categories there yet, might put a literalfield to tell the user
}
$dropdown = new DropdownField('TeamPlayerID', 'TeamPlayer', $CategoriesSource, $this->TeamPlayerID);
$fields->push($dropdown);
$fields->push(new NumericField('Tries'));
$fields->push(new NumericField('Goals'));
return $fields;
}
}
class Team extends DataObject {
public static $db = array(
'TeamName' => 'Text'
);
public static $has_one = array(
'TeamLogo' => 'Image',
'LeagueTableResult' => 'LeagueTableResult'
);
public static $has_many = array(
'TeamPlayers' => 'TeamPlayer'
);
}
Thanks very much in advance for any help!