Unit.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php

class Unit extends DataObject {

   static $db = array(
      'Sessions' => "Enum('1,2,3,4,5,6,7,8','2')",
      'Date1' => "Date",
      'StartTime1' => 'Time',
      'EndTime1' => 'Time',
      'Date2' => "Date",
      'StartTime2' => 'Time',
      'EndTime2' => 'Time',
      'Date3' => "Date",
      'StartTime3' => 'Time',
      'EndTime3' => 'Time',
      'Date4' => "Date",
      'StartTime4' => 'Time',
      'EndTime4' => 'Time',
      'Date5' => "Date",
      'StartTime5' => 'Time',
      'EndTime5' => 'Time',
      'Date6' => "Date",
      'StartTime6' => 'Time',
      'EndTime6' => 'Time',
      'Date7' => "Date",
      'StartTime7' => 'Time',
      'EndTime7' => 'Time',
      'Date8' => "Date",
      'StartTime8' => 'Time',
      'EndTime8' => 'Time'
   );

   static $has_one = array(
      'MyWorkshop' => 'Workshop',
      'MyLocation' => 'Location'
   );

   static $many_many = array(
      'Instructors' => 'Instructor'
   );

   function getCMSFields_forPopup() {
      $fields = new FieldSet();

      $fields->push( new HeaderField( 'How many sessions?', '3' ) );
      $fields->push( new DropdownField( 'Sessions', 'Sessions', singleton('Unit')->dbObject('Sessions')->enumValues() ) );

      $fields->push( new HeaderField( 'Session 1', '3' ) );
      $fields->push( new CalendarDateField( 'Date1', 'Date' ) );
      $fields->push( new DropdownTimeField( 'StartTime1', 'Start Time' ) );
      $fields->push( new DropdownTimeField( 'EndTime1', 'End Time' ) );

      $fields->push( new HeaderField( 'Session 2', '3' ) );
      $fields->push( new CalendarDateField( 'Date2', 'Date' ) );
      $fields->push( new DropdownTimeField( 'StartTime2', 'Start Time' ) );
      $fields->push( new DropdownTimeField( 'EndTime2', 'End Time' ) );

      $fields->push( new HeaderField( 'Session 3', '3' ) );
      $fields->push( new CalendarDateField( 'Date3', 'Date' ) );
      $fields->push( new DropdownTimeField( 'StartTime3', 'Start Time' ) );
      $fields->push( new DropdownTimeField( 'EndTime3', 'End Time' ) );

      $fields->push( new HeaderField( 'Session 4', '3' ) );
      $fields->push( new CalendarDateField( 'Date4', 'Date' ) );
      $fields->push( new DropdownTimeField( 'StartTime4', 'Start Time' ) );
      $fields->push( new DropdownTimeField( 'EndTime4', 'End Time' ) );

      $fields->push( new HeaderField( 'Session 5', '3' ) );
      $fields->push( new CalendarDateField( 'Date5', 'Date' ) );
      $fields->push( new DropdownTimeField( 'StartTime5', 'Start Time' ) );
      $fields->push( new DropdownTimeField( 'EndTime5', 'End Time' ) );

      $fields->push( new HeaderField( 'Session 6', '3' ) );
      $fields->push( new CalendarDateField( 'Date6', 'Date' ) );
      $fields->push( new DropdownTimeField( 'StartTime6', 'Start Time' ) );
      $fields->push( new DropdownTimeField( 'EndTime6', 'End Time' ) );

      $fields->push( new HeaderField( 'Session 7', '3' ) );
      $fields->push( new CalendarDateField( 'Date7', 'Date' ) );
      $fields->push( new DropdownTimeField( 'StartTime7', 'Start Time' ) );
      $fields->push( new DropdownTimeField( 'EndTime7', 'End Time' ) );

      $fields->push( new HeaderField( 'Session 8', '3' ) );
      $fields->push( new CalendarDateField( 'Date8', 'Date' ) );
      $fields->push( new DropdownTimeField( 'StartTime8', 'Start Time' ) );
      $fields->push( new DropdownTimeField( 'EndTime8', 'End Time' ) );

      $fields->push( new HeaderField( 'Instructors', '3' ) );
      $fields->push( new ManyManyComplexTableField($this, 'Instructors', 'Instructor', array('Title' => 'Name') ) );

      $fields->push( new HeaderField( 'Location', '3' ) );
      $fields->push( new HasOneComplexTableField($this, 'MyLocation', 'Location', array('Title' => 'Name', 'State' => 'State', 'Country' => 'Country') ) );
      return $fields;
     }

}

?>

Location.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php

class Location extends Page {

  static $allowed_children = "none";
  static $default_parent = "locations";
  static $can_be_root = false;

   static $db = array(
      'Address' => 'Text',
      'Town' => 'Text',
      'State' => "Enum('None,ACT,New South Wales,Northern Territory,Queensland,South Australia,Tasmania,Victoria,Western Australia','South Australia')",
      'Country' => "Enum('Australia,New Zealand','Australia')",
      'Website' => 'Text'
   );

   static $belongs_many = array(
      'Units' => 'Unit'
   );

   function getCMSFields_forPopup() {
      $fields = new FieldSet();
      $fields->push( new TextField( 'Title' ) );
      $fields->push( new TextField( 'Address' ) );
      $fields->push( new TextField( 'Town' ) );
      $fields->push( new DropdownField( 'State', 'State', singleton('Location')->dbObject('State')->enumValues() ) );
      $fields->push( new DropdownField( 'Country', 'Country', singleton('Location')->dbObject('Country')->enumValues() ) );
      $fields->push( new TextField( 'Website' ) );
      $fields->push( new HtmlEditorField( 'Content' ) );
      return $fields;
     }

   function getCMSFields() {
      $fields = parent::getCMSFields();

      $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Address' ), 'Content' );
      $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Town' ), 'Content' );
      $fields->addFieldToTab( 'Root.Content.Main', new DropdownField( 'State', 'State', singleton('Location')->dbObject('State')->enumValues() ), 'Content' );
      $fields->addFieldToTab( 'Root.Content.Main', new DropdownField( 'Country', 'Country', singleton('Location')->dbObject('Country')->enumValues() ), 'Content' );
      $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Website' ), 'Content' );

      return $fields;
   }
}

class Location_Controller extends Page_Controller {

}

?>

Instructor.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php

class Instructor extends Page {

  static $allowed_children = "none";
  static $default_parent = "instructors";
  static $can_be_root = false;

   static $db = array(
      'Position' => 'Text'
   );

   static $belongs_many_many = array(
      'Units' => 'Unit'
   );

   function getCMSFields_forPopup() {
      $fields = new FieldSet();
      $fields->push( new TextField( 'Title' ) );
      $fields->push( new TextField( 'Position' ) );
      $fields->push( new HtmlEditorField( 'Content' ) );
      return $fields;
     }

   function getCMSFields() {
      $fields = parent::getCMSFields();

      $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Position' ), 'Content' );

      return $fields;
   }
}

class Instructor_Controller extends Page_Controller {

}

?>