I have ServicePageHolder, ServicePages and LocationPageHolder, LocationPage, each location will have a number of service available to the public, and each service can belong to multiple locations. What I need is to create a interface in the cms where I can manage this many to many relationship. I.E. I would like to create a new tab in the location page where user may select number of services. In the front end where I display the location details, I may also list a number of services which has link to each service page.
Could someone point me to the right direction. I have read the tutorial 5 which gives a example of module - project. However the module extends the DataObject, not Page.
class ServicePage extends Page {
static $db = array(
'Headline' => 'Text'
);
static $has_one = array(
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Headline'), 'Content');
return $fields;
}
}
class ServicePage_Controller extends Page_Controller {
}
###########################################
class ServicePageHolder extends Page {
static $db = array(
);
static $has_one = array(
);
static $allowed_children = array('ServicePage');
}
class ServicePageHolder_Controller extends Page_Controller {
function FirstService($num=1) {
$service = DataObject::get_one("ServicePageHolder");
return ($news) ? DataObject::get("ServicePage", "ParentID = $service->ID", "Headline DESC", "", $num) : false;
}
}
###########################################
class LocationPage extends Page {
static $db = array(
'Headline' => 'Varchar',
'Phone' => 'Varchar',
'Facsimile' => 'Varchar',
'Email' => 'Varchar',
'Monday' => 'Varchar',
'Tuesday' => 'Varchar',
'Wednesday' => 'Varchar',
'Thursday' => 'Varchar',
'Friday' => 'Varchar',
'Saturday' => 'Varchar',
'Sunday' => 'Varchar',
'Street' => 'Varchar',
'Suburb' => 'Varchar',
'State' => 'Varchar',
'Postcode' => 'Varchar'
);
static $has_one = array(
'Photo' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Headline'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Phone'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Facsimile'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Email'), 'Content');
$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
$fields->addFieldToTab('Root.Content.OpenHours', new TextField('Monday'));
$fields->addFieldToTab('Root.Content.OpenHours', new TextField('Tuesday'));
$fields->addFieldToTab('Root.Content.OpenHours', new TextField('Wednesday'));
$fields->addFieldToTab('Root.Content.OpenHours', new TextField('Thursday'));
$fields->addFieldToTab('Root.Content.OpenHours', new TextField('Friday'));
$fields->addFieldToTab('Root.Content.OpenHours', new TextField('Saturday'));
$fields->addFieldToTab('Root.Content.OpenHours', new TextField('Sunday'));
$fields->addFieldToTab('Root.Content.Location', new TextField('Street'));
$fields->addFieldToTab('Root.Content.Location', new TextField('Suburb'));
$fields->addFieldToTab('Root.Content.Location', new TextField('State'));
$fields->addFieldToTab('Root.Content.Location', new TextField('Postcode'));
return $fields;
}
}
class LocationPage_Controller extends Page_Controller {
}
###########################################
class LocationPageHolder extends Page {
static $db = array(
'Headline' => 'Varchar'
);
static $has_one = array(
);
static $allowed_children = array('LocationPage');
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Headline'), 'Content');
return $fields;
}
}
class LocationPageHolder_Controller extends Page_Controller {
}
Thanks.