Hi,
I have got the file data object manager working roughly as I would like it, with the exception of the grid view of my files showing "#5" for example rather than the title of the file? Any ideas why?
Publication
class Publication extends DataObject {
static $db = array(
'IssueNumber' => 'Varchar(25)',
'Date' => 'Date'
);
static $has_one = array(
'Document' => 'File',
'PublicationPage' => 'PublicationPage'
);
function getCMSFields_forPopup() {
$datefield = new DateField('Date');
$datefield->setConfig('showcalendar', true);
$datefield->setConfig('showdropdown', true);
$datefield->setConfig('dateformat', 'dd/MM/YYYY');
return new FieldSet(
new TextField('IssueNumber'),
$datefield,
new FileIFrameField('Document')
);
}
}
PublicationPage
class PublicationPage extends Page {
static $has_many = array(
'Publications' => 'Publication'
);
static $has_one = array (
'RootFolder' => 'Folder'
);
function onBeforeWrite() {
parent::onBeforeWrite();
if($this->ID) {
$this->RootFolder()->Title = $this->Title;
}
}
function onAfterWrite() {
if($this->ID) {
$this->checkFolder();
}
parent::onAfterWrite();
}
function onBeforeDelete() {
parent::onBeforeDelete();
$this->RootFolder()->delete();
}
function checkFolder() {
if(!$this->RootFolderID) {
$folder = Folder::findOrMake("PublicationPage-" . $this->ID);
$folder->Title = $this->Title;
$folder->write();
$this->RootFolderID = $folder->ID;
$this->write();
} else {
$this->RootFolder()->Title = $this->Title;
$this->RootFolder()->write();
}
}
function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this,
'Publications',
'Publication',
'Document',
array(
'IssueNumber' => 'IssueNumber',
'Date' => 'Date'),
'getCMSFields_forPopup'
);
$manager->setUploadFolder("PublicationPage-" . $this->ID);
$manager->setAllowedFileTypes(array ('pdf','doc'));
$fields->addFieldToTab("Root.Content.Publications", $manager);
return $fields;
}
}
class PublicationPage_Controller extends Page_Controller {
public function init() {
parent::init();
}
}