Hey all,
I need a dataobject wich has two images, one large banner and a stamp banner. However this seems not possible with the current dataobjectmanager. I doesnt take two images. I gives a undefined index for the second image and also resets all fields set for the dataobject. I might be doing something wrong. The line it is about is:
$total = isset($_POST['totalsize']) ? $_POST['totalsize'] : sizeof($_POST['uploaded_files']);
Advertisement.php
<?php class Advertisement extends DataObject {
static $db = array (
'Name' => 'Text',
'Site' => 'Text'
);
static $has_one = array (
'Banner' => 'Image',
'Stamp' => 'Image',
'AdvertisementPage' => 'AdvertisementPage'
);
static $icon = "mysite/icons/advertisement";
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name', 'Naam van de sponsor'),
new TextField('Site', 'URL naar de sponsor'),
new ImageField('Banner', 'Banner groot, 680x200'),
new ImageField('Stamp', 'Stamp klein, 207x200')
);
}
}
AdvertisementPage:
<?php
class AdvertisementPage extends Page {
public static $db = array(
);
static $has_many = array (
'Advertisements' => 'Advertisement'
);
public static $has_one = array(
);
static $icon = "mysite/icons/advertisementholder";
function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this, // Controller
'Advertisements', // Source name
'Advertisement', // Source class
'Banner', // File name on DataObject
array(
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
//$fields->addFieldToTab("Root.Content.BannerRotator", new HTMLEditorField('BannerRotator','Banner Rotator Content'));
$fields->removeFieldFromTab('Root.Content','Content');
$fields->addFieldToTab("Root.Content.Main",$manager);
// If undefined, all types are allowed. Pass with or without a leading "."
$manager->setAllowedFileTypes(array('jpg','png', 'gif'));
// Label for the upload button in the popup
$manager->setBrowseButtonText("Upload (680x200)");
// In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
$manager->setGridLabelField('Name');
// Plural form of the objects being managed. Used on the "Add" button.
$manager->setDefaultView('list');
//Remove the folder selection from uploadify
$manager->allowUploadFolderSelection = false;
//Set the upload folder
$manager->setUploadFolder('Uploads/advertisements');
return $fields;
}
}
class AdvertisementPage_Controller extends Page_Controller {
}
You can't define more than one filename on the dataobject so thats kind of hard to fix. Only other thing i can think of to fix it is to make subpages that take two images. But that is kind of overload on pages. I think this can work through the dataobjectmanager, if i can figure out what i am doing wrong.
Does it need another relationship? Im not quite sure if this is a bug or bad writing of the dataobjectmanager but i wouldve been fine with the way dataobjectmanager behaved, except for that i got undefined index and the settings of the main upload dont stick for the secondary.