7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 54227 Views |
-
Re: Preview: DataObjectManager module

27 February 2009 at 11:58pm Last edited: 28 February 2009 12:56am
Hi Les
I am pretty sure you can just add a filter clause in the same way as the complex table field:
$manager = new FileDataObjectManager(
$this, // Controller
'FileResources', // Source name
'FileResource', // Source class
'Attachment', // File name on DataObject ( Resource::$has_one = array('Attachment' => 'File') )
array(
'DisplayTitle' => 'DisplayTitle'
), // Headings
'getCMSFields_forPopup', // Detail fields (function name or FieldSet object)
"ServicePageID = $this->ID" //Filter clause ******HERE****** make sure to add the coma above too
// Sort clause
// Join clause
); -
Re: Preview: DataObjectManager module

28 February 2009 at 12:20am
Wow, that was a quick response! Thank you Aram.
I'm not sure exactly how to implement what you suggested, as it immediately throws a PHP error in my server logs, so I've done a quick search and improvised:
$manager = new FileDataObjectManager(
$this, // Controller
'FileResources', // Source name
'FileResource', // Source class
'Attachment', // File name on DataObject ( Resource::$has_one = array('Attachment' => 'File') )
array(
'DisplayTitle' => 'DisplayTitle'
), // Headings
'getCMSFields_forPopup', // Detail fields (function name or FieldSet object)
$filter = 'ServicesPageID = '.$this->ID// Filter clause
// Sort clause
// Join clause
);Now it's complaining that there's and "Unknown column 'ServicesPageID' in 'where clause'" - is this something that I need to define elsewhere (maybe in the FileResource class)?
Sorry, I'm having a Friday morning brain problem today!!
-
Re: Preview: DataObjectManager module

28 February 2009 at 12:31am
Ahahaha!! A cupt of tea and fits into place...
It turns out that I'd declared a has_one relationship in the FileResource class, but had named it Page, not ServicesPage - a simple change in the FileResource class to:
static $has_one = array (
'Attachment' => 'File',
'ServicesPage' => 'ServicesPage'
);and a quick rebuild of the DB and all is working.
Now, my next question is - do I need to create a Resource class for each of the page types that I want to display this control on, or is there an easy way for me to set the filter on the main page ID? Can I do it through the SiteTree table at all?
-
Re: Preview: DataObjectManager module

28 February 2009 at 12:38am
I think you should be able to just add the page types to the has one relation ship, so you will have a number of has_one's but only one will be used at a time. Not sure if there is a better way to do it though
-
Re: Preview: DataObjectManager module

28 February 2009 at 12:46am
Thanks for the nudge Aram, that works perfectly.
-
Re: Preview: DataObjectManager module

28 February 2009 at 2:08am Last edited: 28 February 2009 3:33am
Okey dokey, two more quick questions:
1. How do you define the default upload folder for the FileDataObjectManager module?
I don't want my users to be uploading to the root of the Upload folder, as it'll make attaching files and images very messy!2. And, is there a way to store or display the file properties such as filesize and filetype?
I can see that the control for editing the asset shows both, but can't see how I call this in the UI.Cheers
L
-
Re: Preview: DataObjectManager module

28 February 2009 at 3:43am
1) This is actually in production right now. I've had a number of requests for it. Check out the svn later today (it's Friday morning here). The implementation is $manager->allowUploadFolderSelection();
2) File size and type are stored automatically in the File table. Use $Size and $Type (I believe). In the example code for "Resource" that would look like this:
$Attachment.Size
$Attachment.Type(might be FileType, or something like that. I forget the exact name of the property)
-
Re: Preview: DataObjectManager module

28 February 2009 at 3:49am
Thank you UncleCheese!
This module has properly saved me a tonne of hassle
I feel all warm and fuzzy about open source today!
And for anyone else I also found that $Attachment.Extension returns the file extension - huzzah!
| 54227 Views | ||
| Go to Top | Next > |


