I have been searching all references and been trying the DataObjectModel examples for pagination until I realized that a has_many reference isn't part of the DOM scope. Duh.
Sorry to be "lazy", I've spent about 3 days on this now, loved the challenge of trying to crack it, but now I am just tired. Here's what I am trying to do.
class ProfileListPage extends Page {
static $db = array(
);
static $has_one = array(
);
static $has_many = array(
'Performers' => 'ProfileListProfile'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$performerManager = new DataObjectManager(
$this, // Controller
'Performers', // Source name
'ProfileListProfile', // Source class
array(
'Name' => 'Name',
'LastName' => 'LastName',
'Location' => 'Location',
'Sex' => 'Sex',
'Styles' => 'Styles',
'CV' => 'CV',
'About' => 'About',
'Thumbnail' => 'Image',
'Links' => 'ProfileListLink'
),
'getCMSFields_forPopup',
'',
'LastName ASC'
);
$f->addFieldToTab("Root.Content.Profiles",$performerManager);
}
}
The underlying ProfileListProfile class is here:
class ProfileListProfile extends DataObject
{
static $db = array (
'Name' => 'Text',
'LastName' => 'Text',
'Location' => 'Text',
'Sex' => "Enum('Male, Female', 'Female')",
'Styles' => 'Text',
'CV' => 'Text',
'About' => 'Text'
);
static $has_one = array (
'Image' => 'Image',
'Page' => 'ProfileListPage'
);
static $has_many = array (
'Links' => 'ProfileListLink'
);
function Thumbnail() {
$Image = $this->Image();
if ( $Image ) {
return $Image->CMSThumbnail();
} else {
return null;
}
}
static $default_sort = "LastName ASC";
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new TextField('LastName'),
new DropdownField('Sex', 'Choose', singleton('ProfileListProfile')->dbObject('Sex')->enumValues()),
new TextField('Location'),
new TextAreaField('Styles'),
new TextAreaField('CV'),
new SimpleImageField('Image','Profile Picture',null,null,null,'ProfilePhotos'),
new DataObjectManager ($this, 'Links', 'ProfileListLink', array('Title'=>'Link Name', 'Link' => 'URL'))
);
}
}
Now... On a given ProfileListPage there should display a limited number (8) subset of Performers. The template sees $this->Performers properly, but I just need a subset. I am not good enough with the Silverstripe database queries and dataset casting to figure out how on a given page I can have e.g. a CurrentSet which will include the records from 0-7 if no argument is passed to the page. If a page argument is somehow passed, the next 8 - and so on - will display. I wasn't even sure whether I'd need to create a special action on the page (how would a CurrentSet function otherwise receive the page argument?). Sorry for requesting to be babied, but I'm really stuck here :) Thanks.