Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

Preview: DataObjectManager module


Go to End


379 Posts   95930 Views

Avatar
Bo_Einzeller

Community Member, 18 Posts

18 March 2009 at 6:23am

Thanks for your fast reply! I've tested it and everything's fine. Great work!
I've tested the translation, if your interested, i could send you the german translation-File.
Cheers

Avatar
Ben Gribaudo

Community Member, 181 Posts

19 March 2009 at 9:56am

Hello Everyone,

I would like to use FileDataObjectManager to relate files to a given page. Example: page a is associated with 'File1.pdf' and 'File6.pdf', page b is associated with other files, etc.

The problem I've hit is that the FileDataObjectManager in the QualityPDFPage below shows all files associated with any page, not just those files associated with the given page.

Any ideas on what I'm doing wrong?

Thanks!
Ben

class QualityPDFPage extends QualityChildPage {
	static $has_many = array(
		'PDFResource' => 'PDFResource'
	);
	static $db = array();
	static $can_be_root = false;
	static $allowed_children = array();

	function getCMSFields() {
		$fields = parent::getCMSFields();

		$manager = new FileDataObjectManager(
			$this, // Controller
			'PDFResource', // Source name
			'PDFResource', // Source class
			'PDF',
			array(
				'Name' => 'Name'
			), // Headings 
			'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)

		);
		
		$fields->addFieldToTab('Root.Content.Resources', $manager);
		$fields->removeFieldFromTab("Root.Content.Main", "Content");
	
		return $fields;
	}
}

Avatar
UncleCheese

Forum Moderator, 4102 Posts

19 March 2009 at 10:03am

Edited: 19/03/2009 10:03am

Is QualityPDFPage the only page type that uses the FileDataObjectManager? Or is it used in another class as well? If so, you need to use the setParentClass() method.

Can you post your PDFResource class?

Avatar
Ben Gribaudo

Community Member, 181 Posts

19 March 2009 at 10:36am

Edited: 19/03/2009 10:37am

No, it's not the only class that uses FileDataObjectManager. I'll try setParentClass().

Here's PDFResource:

class PDFResource extends DataObject
{
	static $db = array (
		'Name' => 'Varchar(30)'
	);
	
	static $has_one = array (
		'Thumbnail' => 'Image',
		'PDF' => 'PDF',   // this class is an extension of File which adds the ability to generate a thumbnail of the PDF's first page.
		'Page' => 'Page'
	);
}

Avatar
UncleCheese

Forum Moderator, 4102 Posts

19 March 2009 at 10:52am

Yeah, you need to because $has_one Page is too ambiguous. It's going to try to set QualityPDFPageID on your object, which is a field that doesn't exist, so you wont' get the relation. Make sure you set your FileDataObjectManager object to ->setParentClass("Page")

Avatar
Chucky2k

Community Member, 32 Posts

19 March 2009 at 11:10pm

Hi Uncle Cheese,

Checked out the latest today and noticed a few issues. Looks like revision 82 has caused a couple of issues with DataObjectManager.php. On line 288 I changed from:

$dropdown = new DropdownField('Filter',$this->filter_label . " (<a href='#' class='refresh'>'._t('DataObjectManager.REFRESH','refresh').'</a>)", $map, $value);

to:

$dropdown = new DropdownField('Filter',$this->filter_label . " (<a href='#' class='refresh'> "._t('DataObjectManager.REFRESH','refresh')."</a>)", $map, $value);

Also, the removal of...

protected $view = "list";

and the public function ListStyle() causes the DataObjectManager Tab layout and the Albums Tab layout on an ImageGalleryPage to break.

David

Avatar
Ben Gribaudo

Community Member, 181 Posts

20 March 2009 at 3:57am

Edited: 20/03/2009 3:58am

Uncle Cheese,

Thanks for the help. Still no go. With --

$manager->setParentClass('Page');
-- no files show up in the file data object manager. Of note, PageID in the database table pdfresource is being set to zero. I'm guessing that if we figured out how to get field PageID to be set to the correct value, things might work. Any ideas?

Revised code below.

Thank you,
Ben
--------------

Revised Code:

class QualityPDFPage extends QualityChildPage {
	static $has_many = array(
		'PDFResource' => 'PDFResource'
	);
	static $db = array();
	static $can_be_root = false;
	static $allowed_children = array();

	function getCMSFields() {
		$fields = parent::getCMSFields();

		$manager = new FileDataObjectManager(
			$this, // Controller
			'PDFResource', // Source name
			'PDFResource', // Source class
			'PDF',
			array(
				'Name' => 'Name'
			), // Headings 
			'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)

		);
		$manager->setParentClass('Page');
		
		$fields->addFieldToTab('Root.Content.Resources', $manager);
		$fields->removeFieldFromTab("Root.Content.Main", "Content");
	
		return $fields;
	}
}

class PDFResource extends DataObject
{
	static $db = array (
		'Name' => 'Varchar(30)'
	);
	
	static $has_one = array (
		'PDF' => 'PDF',
		'Page' => 'Page'
	);
}

Avatar
Ben Gribaudo

Community Member, 181 Posts

20 March 2009 at 4:12am

Good thought, ntessore. I don't think it will work, though, as there is no QualityPDFPageID column in the PDFResource table.

Go to Top