Hi there,
I have created a data object called players, created a model admin interface for it and now want to create a page that shows the results from the data that has been captured. I realize that i will need a ResultsPage class and assume that i will have to create a function in the controller that queries the Player class and then loops over the data from each player. I want to do calculations on thse database columns. So for example, for each player i want to calculate the number of (tries * 5) + (number of conversions *2) and get a total called PlayerScore, which i need to be able to show in my ResultsPage.ss template...how do i do that?
I have the following:
//// Player Class ///
class Player extends DataObject {
static $db = array(
'PlayerName'=>'Varchar(50)',
'DateJoined'=> 'Year',
'Tries'=>'Int',
'Conversions'=>'Int',
);
//// Results Page//
class ResultsPage extends Page {
}
class ResultsPage_Controller extends Page_Controller {
function playerstats() {
$player = Player::get();
foreach($player as $x) {
$tries = $x[tries]*5;
$conversions = $x[conversions]*2;
$PlayerScore = $tries + $conversions;
return $PlayerScore;
}
}
}
Thanks