Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Go to End
Author Topic: 58328 Views
  • LesC
    Avatar
    Community Member
    70 Posts

    Re: Preview: DataObjectManager module Link to this post

    This looks like a pretty powerful module, but I've got one question:

    How do I keep uploaded resources related to just the page they're uploaded to? I can see this has been done on the demo site, but can't see where the relationship is defined in the example code.

    When I upload a file, all other pages that have that class can also see the file in the related files list.

    Code: http://pastie.org/401950

    Can anyone point me in the right direction?

    Cheers

    L

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Preview: DataObjectManager module Link to this post

    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
          );

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: Preview: DataObjectManager module Link to this post

    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!!

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: Preview: DataObjectManager module Link to this post

    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?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Preview: DataObjectManager module Link to this post

    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

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: Preview: DataObjectManager module Link to this post

    Thanks for the nudge Aram, that works perfectly.

  • LesC
    Avatar
    Community Member
    70 Posts

    Re: Preview: DataObjectManager module Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    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)

    58328 Views
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.