Hi there, I have 2 x objects. Player & Team and a page type called PlayerStatsPage where I want to show the scorers stats of each player. Included in the stats I want the team name. I cant seem to get the team name to render in my template. Please help
class Player extends DataObject {
static $db = array(
'PlayerName'=>'Varchar',
'DateJoined'=> 'Date',
'Tries'=>'Int',
'Conversions'=>'Int',
'DropGoals'=>'Int',
'Penalties'=>'Int'
);
private static $has_one = array(
'TeamJoin' => 'Team',
);
// Build database coliumns
static $db = array(
'TeamName'=>'Varchar',
'DateJoined'=>'Date'
);
// Set up relationships
private static $has_many = array(
'PlayerJoin' => 'Player',
);
class PlayerStatsPage_Controller extends Page_Controller {
private static $allowed_actions = array (
);
public function init(){
parent::init();
}
// Function that creates player stats
function playerstats() {
$players = Player::get()
->innerJoin("Team", "\"Player\".\"TeamJoinID\" = \"Team\".\"ID\"")
->filter(array(
'DateJoined:StartsWith' => $this->Year
))
;
$playerlist = new ArrayList();
foreach($players as $item) {
//Declare variables and do calculations on them
$playername = $item->PlayerName;
$team = $item->TeamJoin[TeamName];
$tries = $item->Tries;
$conversions = $item->Conversions;
$penalties = $item->Penalties;
$dropgoals = $item->DropGoals;
//Build new array with calculated data
$playerlist->push(
new ArrayData(array(
'Player' => $playername,
'Team' => $team,
'Tries' => $tries,
'Conversions' => $conversions,
'Penalties' => $penalties ,
'DropGoal' =>$dropgoals ,
'Total' => ($tries*5)+($conversions*2)+($penalties*3)+($dropgoals*3)
))
);
}
return $playerlist;
}
As you can see, i want to pull the team name data into the custom array, but when i try and render the data on my .ss template, nothing shows. Am i doing the join incorrectly or should i be doing something else.
Thanks