So, What you've got going on currently is extending the File class and then assigning a has_one of more files and images to it. I think things would be a lot easier to work with if MediaReport extended DataObject and then create a has_one relationship for each type of file. You'll need to add Title to the $db array on MediaReport instead of referencing the PDF as Parent, it will be a has_one like the PDF_en file. Then you can easily query your MediaReport and sort by Date, once in the control loop in your template you will be able to access each of the files that the Object has.
In MediaReport.php
class MediaReport extends DataObject {
static $db = array(
'Title' => 'Text',
'Title_en' => 'Text',
'Magazin' => 'Text',
'Date' => 'Date',
'ExtLink' => 'Varchar(255)'
);
static $has_one = array(
'Photo' => 'Image',
'PDF' => 'File',
'PDF_en' => 'File'
);
...
public function getCMSFields_forPopup()
{
$datefield = new DateField('Date',_t('MEDIAREPORT.DATE','Date'));
$datefield->setConfig('showcalendar', true);
$datefield->setConfig('dateformat', 'dd.MM.YYYY');
$filefield = new FileUploadField('PDF','PDF');
$filefield->removeFolderSelection();
$filefield2 = new FileUploadField('PDF_en','PDF_en');
$filefield2->removeFolderSelection();
$filefield->uploadFolder = 'mediareports/pdfs/';
$filefield2->uploadFolder = 'mediareports/pdfs/';
$imagefield = new ImageUploadField('Photo',_t('MEDIAREPORT.PHOTO','Photo'));
$imagefield->removeFolderSelection();
$imagefield->uploadFolder = 'mediareports/images/';
return new FieldSet(
new TextField('Title'),
new TextField('Title_en'),
$datefield,
new TextField('Magazin'),
new TextField('ExtLink'),
$filefield,
$filefield2,
$imagefield
);
}
In MediaReportsPage.php
class MediaReportsPage extends Page implements PermissionProvider {
...
function getMediaReports_ThisYear() {
$data = DataObject::get("MediaReport", "", 'Date DESC', "", "");
return $data;
}
...
}
In MediaReportsPage.ss
<% if MediaReports_ThisYear %>
<ul>
<% control MediaReports_ThisYear %>
<h2>$title</h2>
<% if PDF %>
<% control PDF %>
<p><a href="$link">$Name</a></p>
<% end_control %>
<% end_if %>
<% end_control %>
</ul>
<% end_if %>