Hello,
I'm trying to create a form where user can come enter 5 names for team a, 5 names for team b, select the date, select which team won, choose who the MVP was on each team and then submit it. I have this form created as following:
class ScoreManager_Controller extends Page_Controller {
private static $allowed_actions = array('GameResultForm');
public function GameResultForm() {
$gameDate = new DateField('GameDate');
$gameDate->setConfig('showcalendar', true);
$gameDate->setConfig('dateformat', 'dd/MM/YYYY');
$fields = new FieldList (
$gameDate,
new OptionsetField(
$name = "WinningTeam",
$title = "Who won?",
$source = array(
"1" => "Team 1",
"2" => "Team 2"
),
$value = "1"
),
new OptionsetField(
$name = "TeamOneMVP",
$title = "Who is the MVP for Team 1?",
$source = array(
"1" => "Player A",
"2" => "Player B",
"3" => "Player C",
"4" => "Player D",
"5" => "Player E"
),
$value = "1"
),
new TextField('PlayerA'),
new TextField('PlayerB'),
new TextField('PlayerC'),
new TextField('PlayerD'),
new TextField('PlayerE'),
new OptionsetField(
$name = "TeamTwoMVP",
$title = "Who is the MVP for Team 2?",
$source = array(
"1" => "Player F",
"2" => "Player G",
"3" => "Player H",
"4" => "Player I",
"5" => "Player J"
),
$value = "1"
),
new TextField('PlayerF'),
new TextField('PlayerG'),
new TextField('PlayerH'),
new TextField('PlayerI'),
new TextField('PlayerJ')
);
$actions = new FieldList(
new FormAction('doBrowserPoll', 'Add Group')
);
return new Form($this, 'GameResultForm', $fields, $actions);
}
}
This displays on the page as I need it and works great. My problem comes next. I come from ASP.NET development and there usually I will go and manually create the tables I need and then just create methods that connect to DB, write data to it, or retrieve data from it. With silverstripe I'm not 100% sure how to do this because I don't fully understand how /dev/build works.
Basically I want to create a Player table which will hold all the information about the player. So when I submit that form, it will call a function which will loop through each player and then if the player exists, it will calculate their new ratings and add a count +1 if they are MVP. I also then want to create a second table which will keep track of all games played and who was on them. How do I go about doing this with silverstripe?
If I go to phpmyadmin and create the tables myself, what happens when I run /dev/build, will that destroy my tables, will it alter them in any way? Are there scenarios in the future where I would lose the tables and the data there?
Is it possible to create 2 tables like this with silverstripe framework? Can I write a php file which will create the tables if they don't exist and /dev/build not affect them?