Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Championship points system with results table


Reply


5 Posts   506 Views

Avatar
lozhowlett

Community Member, 146 Posts

20 October 2011 at 5:00am

Hi everyone

I am building a site for a race car series and wanted some general advice.

Here is the kinda structure I am planning....

Season
-   Has one Photo, Year, Description

Event
-   Title, Date & Time, description
-   isNextRace
o   Means it loads on the homepage
-   Has one season
-   Has one track
-   Has many teams
-   Has many images
o   Each image can have many teams or many drivers

Tracks
-   Name, Address, Telephone, Website, Track image, YouTube on board lap

Teams
-   Name, description, race number
-   Has one class selection (petrol / diesel)
-   Has one profile picture
-   Has many photos
-   Has many drivers

Drivers
-   Name, description
-   Has one profile picture
-   Has many photos
-   Has one team

Result
-   Has one event
-   Has one teams
-   Each team gets points awarded for each race
-   Has one PDF results download

Now most of this I am fine with, what I would really like some advice on is the results selection.

A result will will be given to a team for each event, i.e first place scores 10 points, and so on. I need to put together an easy way to input these and then update a "championship" table with the latest results. I really dont know where to start, so would be great if anyone would like to get involved and give me some help?

It might be worth doing this as a generic as possible module so its useful to others?

Thanks in advance.

Avatar
Willr

Forum Moderator, 5513 Posts

20 October 2011 at 8:32pm

So a championship goes across multiple events? If so would start with getting a list of teams, totaling up all the points from each result for that team then once you have all the points for the team sort the list of team by number of points. Several ways of doing this, but writing it as a SQL Query would be the fastest.

What information did you want to include on the championship table?

Avatar
lozhowlett

Community Member, 146 Posts

20 October 2011 at 11:21pm

Yes a championship goes across multiple events. Each event will have multiple teams entered, each team will be in 1 of 2 classes. So i need to make sure the SQL picks up which class they are in too.

Are there any tutorials kicking about on how to select data directly from the DB, I know SQL, just need to know how to get it into usable data in the template...

In the champ table I want to include

- Position, Team name, Total Points

Does that sound doable? Cheers

Avatar
lozhowlett

Community Member, 146 Posts

21 October 2011 at 3:00am

To manage this, i would like to use a table in the events screen. As we know this information:

- What event it is
- What teams have entered

So therefore we should be able to have a tab with:

- a list of entered teams
- a text box to enter the points scored

Is that possible?

Avatar
lozhowlett

Community Member, 146 Posts

21 October 2011 at 3:07am

This is what I have so far....

<?php
class Team extends Page {

   public static $db = array(
'Name' => 'Text',
'CarNumber' => 'Text',
"Class" => "Enum('Petrol, Diesel', 'Diesel')",
'ContactTelephone' => 'Text',
'ContactEmail' => 'Text',
'CarLocation' => 'Text'
   );

   static $has_many = array (
'ImageResources' =>'ImageResource',
'Drivers' => 'Driver'
   );

//public static $many_many = array(
// 'Events' => 'Event'
//);

public static $belongs_many_many = array(
'Events' => 'Event',
'Results' => 'Result'
);

public static $has_one = array(
'ProfilePicture' => 'Image'
   );

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new TextField('Name'));
$fields->addFieldToTab("Root.Content.Main", new TextField('CarNumber'));
$fields->addFieldToTab("Root.Content.Main", new TextField('ContactTelephone'));
$fields->addFieldToTab("Root.Content.Main", new TextField('ContactEmail'));
$fields->addFieldToTab("Root.Content.Main", new TextField('CarLocation'));
$fields->addFieldToTab("Root.Content.Main", new ImageField('ProfilePicture'));
$fields->addFieldToTab("Root.Content.Main", new DropdownField('Class', 'Class', singleton('Team')->dbObject('Class')->enumValues()));
$managerimages = new ImageDataObjectManager(
$this, // Controller
'Images', // Source name
'ImageResource', // Source class
'Attachment', // File name on DataObject
array(
'Title' => 'Title'
), // Headings
'getCMSFields_forPopup' // Detail fields
// Filter clause
// Sort clause
// Join clause
);
$fields->addFieldToTab("Root.Content.Image Gallery",$managerimages);

return $fields;
}

}
class Team_Controller extends Page_Controller {
   public static $allowed_actions = array (
   );

   public function init() {
parent::init();
   }
}


<?php
class Event extends Page {

   public static $db = array(
'Date' => 'Date',
'Time' => 'Time',
'isNextRace' => 'Boolean'
   );

static $has_one = array (
//'Track' => 'Track'
);

   static $has_many = array (
'ImageResources' =>'ImageResource',
'Results' => 'Result'
   );

public static $many_many = array(
'Teams' => 'Team'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DatePickerField('Date'));
$fields->addFieldToTab("Root.Content.Main", new TimeField('Time'));
$fields->addFieldToTab("Root.Content.Main", new CheckboxField('isNextRace'));

$tablefield = new ManyManyComplexTableField(
$this,
'Teams',
'Team',
array(
'Name' => 'Name',
'CarNumber' => 'CarNumber'
),
'getCMSFields_forPopup'
);
$fields->addFieldToTab("Root.Content.Team Manager",$tablefield);

$managerimages = new ImageDataObjectManager(
$this, // Controller
'Images', // Source name
'ImageResource', // Source class
'Attachment', // File name on DataObject
array(
'Title' => 'Title'
), // Headings
'getCMSFields_forPopup' // Detail fields
// Filter clause
// Sort clause
// Join clause
);
$fields->addFieldToTab("Root.Content.Image Gallery",$managerimages);

return $fields;
}

}
class Event_Controller extends Page_Controller {
   public static $allowed_actions = array (
   );

   public function init() {
parent::init();
   }
}


<?php
class Result extends Page {

   public static $db = array(
'PositionFinished' => 'Int',
'PointedScored' => 'Int',
'isFastestLap' => 'Boolean'
   );

   static $has_many = array (
   );

public static $has_one = array(
'Event' => 'Event',
'Team' => 'Team'
   );

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new NumericField('PositionFinished'));
$fields->addFieldToTab("Root.Content.Main", new NumericField('PointedScored'));
$fields->addFieldToTab("Root.Content.Main", new CheckboxField('isFastestLap'));
$fields->removeFieldFromTab('Root.Content.Main', 'MenuTitle');
return $fields;
}

}
class Result_Controller extends Page_Controller {
   public static $allowed_actions = array (
   );

   public function init() {
parent::init();
   }
}

So I need a function in Event.php to full in entered teams and give them a "Result"...

Any help would be absolutely fantastic :)