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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

Simple Booking Module WIP


Go to End


1200 Views

Avatar
FireMe!

Community Member, 74 Posts

13 May 2013 at 8:16am

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?.