I have a Profile class and a CaseStudy class. I've created a man_many relationship between the two and I'm trying to display the CaseStudies that belong to the Profile page. So far I have:
function ProfileCaseStudies() {
return DataObject::get('CaseStudy', "", '', '', '');
}
which pulls all the CaseStudies. How do I filter it so its only pulling the CaseStudies that belong to the specific Profile.
Full Code
Profile.php
<?php
class Profile extends Page {
static $db = array(
'Summary' => 'Text'
);
static $has_one = array(
'Photo' => 'Image'
);
static $many_many = array(
'CaseStudies' => 'CaseStudy'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Summary'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new ImageField('Photo'), 'Content');
$profileList = new ManyManyComplexTableField(
$this,
'CaseStudies',
'CaseStudy',
array(
'Title' => 'Title'
),
'getCMSFields_forPopup'
);
$fields->addFieldToTab('Root.Content.Categories', $profileList);
return $fields;
}
}
class Profile_Controller extends Page_Controller {
function ProfileCaseStudies() {
return DataObject::get('CaseStudy', "", '', '', '');
}
}
?>
CaseStudy.php
<?php
class CaseStudy extends Page {
static $db = array(
'Summary' => 'Varchar',
'Featured' => 'Boolean'
);
static $many_many = array(
'Categories' => 'Category'
);
static $belongs_many_many = array(
'Profiles' => 'Profile'
);
static $default_parent = 'CaseStudyCategory';
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Summary'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new CheckboxField('Featured'), 'Content');
$categoryList = new HasManyComplexTableField(
$this,
'Categories',
'Category',
array(
'Name' => 'Name'
),
'getCMSFields_forPopup'
);
$fields->addFieldToTab('Root.Content.Categories', $categoryList);
return $fields;
}
}
class CaseStudy_Controller extends Page_Controller {
}
?>