Jump to:

22977 Posts in 11657 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Simple Booking Module WIP

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

Page: 1
Go to End
Author Topic: 272 Views
  • FireMe!
    Avatar
    Community Member
    74 Posts

    Simple Booking Module WIP Link to this post

    Hi I am trying to learn php and the new SS3, and I am trying to create a simple booking module for me.

    code so far.

    EventsHolder.php

    <?php

    class EventsHolderPage extends Page {
       
       public static $db = array(
       );
       
       public static $has_many = array(
           'Events' => 'Event'
       );
       
       public static $allowed_children = array (
          'Event'
       );
       
       public static $icon = "images/calendar-file.gif";
       
    }

    class EventsHolderPage_Controller extends Page_Controller {

    }

    Event.php

    ?php

    class Event extends Page {

    public static $db = array(
       'Date' => 'Date'
    );

    public static $has_many = array(
       'TimeSlots' => 'TimeSlot',
       'Bookings' => 'Bookings'
    );

    public static $has_one = array(
    'EventsHolder' => 'EventsHolder'
    );

    public static $icon = "images/event-file.gif";

    function getCMSFields() {
       $fields = parent::getCMSFields();
       
       $fields->addFieldToTab('Root.Main', $dateField = new DateField('Date', 'Date For Event'), 'Content');
       $dateField->setConfig('showcalendar', true);
       $fields->addFieldToTab('Root.Main', $dateField, 'Content');
       
       $timeslotTableConfig = GridFieldConfig_RecordEditor::create();
       $timeslotTableConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
        'SlotName' => 'Slot Time(s)',
          'Places' => 'Places In Event',
       ));

       $timeslotTable = new GridField('TimeSlots','TimeSlots in Event',$this->TimeSlots(), $timeslotTableConfig);

       $fields->addFieldToTab('Root.Main',$timeslotTable);
       return $fields;

    }

    }

    class Event_Controller extends Page_Controller {

    }

    TimeSlot.php

    <?php

    class TimeSlot extends DataObject {

    public static $db = array(
       'SlotID'=>'Int',   
       'SlotName'=>'Varchar(255)',
       'Places' => 'Int'
    );

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

    public static $has_many = array(
       'Bookings' => 'Booking'
    );

    public function getCMSFields() {
          $fields = parent::getCMSFields();
          $fields->removeFieldFromTab("Root.Main","EventID");
          $fields->removeFieldFromTab("Root.Main","SlotID");
          
          $bookingsTableConfig = GridFieldConfig_RecordViewer::create();
        $bookingsTableConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(array(
        'Name' => 'Name',
             'Email' => 'Email',
        ));
        $bookingsTable = new GridField("Bookings","Bookings in Event Time Slot",$this->Bookings(), $bookingsTableConfig);
        $fields->addFieldsToTab("Root.Main", $bookingsTable, $timeslotTable);
          return $fields;      
    }

    public function Availability() {
       if ($this->Places < 1) {
          return "Unavailable";
       } else {
          return "Available";
       }
    }

    }

    Booking.php

    <?php

    class Booking extends DataObject {

    public static $db = array(
       'BookingID'=>'Int',   
       'Name'=>'Varchar(255)',
       'Email'=>'Varchar(255)'
    );

    public static $has_one = array(
    'TimeSlot' => 'TimeSlot'
    );

    }

    So was just thinking if you guys think im going in the right direction with it no experience with php, firstly a problem i have, i have added the the bookings gridfield to the timeslot gridfield entry pages instead of in another tab but there has been created an empty tab called bookings and im not sure why?.

    272 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.