Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » many Attachments on FileDataObjectManager

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3
Go to End
Author Topic: 3843 Views
  • jmax
    Avatar
    Community Member
    17 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Great!!!

    That's exactly that i need!

    ;-)

    thanks so much UncleCheese

  • moloko_man
    Avatar
    Community Member
    72 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    I'm building a historic timeline of sorts using a nested DataObjectManager, and my structure is currently like this:

    HistoryPage extends Page has_many HistoryDate
    HistoryDate extends DataObject has_many HistoryDateItem
    HistoryDateItem extends DataObject

    HistoryDateItems can consist of a Picture, Quote, Story, or Stats.
    HistoryDateItems will NEVER be more than 8 items.

    everything is pretty much working but when I open the window for the nested DOM its only 433px wide. Is there a way to set the width of a nested DOM object?
    I've tried using $nestedDOM->setPopupWidth('600'); but no workie.

    Also, just looking for some friendly advice on this, but for my HistoryDateItem, is a DataObject the best route to take for this?
    The Timeline looks like this - https://img.skitch.com/20110211-fx4max63nmensgbygriuqj4bi7.jpg
    when the items underneath the date are clicked they open a "lightbox" type window with the Picture, quote or whatever inside said window.

    Thanks.

  • VanceK
    Avatar
    Community Member
    17 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Hi Unclecheese, thank you for all your hard work on the DataObjectManager.

    I have a need to attach multiple files to Silverstripe pages and keep bouncing my head against the wall trying to get this to work correctly.

    I started with the code you posted in this thread on 2 February 2011 at 4:04am, where you listed three files: ResourcePage.php, Resource.php, and ResourceFile.php. Originally, I was getting errors with the $manager-> modifiers until I changed the line $manager = new DataObjectManager(...) to $manager = new FileDataObjectManager(...).

    I understand that I need to insert another parameter into the construct after the source class for a "File name on DataObject" but I can't seem to figure out just what to use there. It seems no matter what I try the CMS keeps dying with the error "FileDataObjectManager::__construct():Could not determine file relationship". Using your example code as a start could you shed light on what I need to use there?

    Also, utilizing this example will I be able to attach the same multiple files to multiple pages. (ie File1 & File2 attached to both Page1 and Page2)?

    Thanks!

  • UncleCheese
    Avatar
    4085 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Whatever the file relationship you have on your DataObject, put that as the fourth argument. So if your DataObject has a $has_one 'MyFile' => 'File', then use 'MyFile'.

  • VanceK
    Avatar
    Community Member
    17 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Thanks for the fast response!

    Sorry for my inexperience in this, but I'm new to Silverstripe and still a little unsure what to use. Following the code from the example, I have three files with the following setup:

    File: ResourcePage.php

    class ResourcePage extends Page
    {
       static $has_many = array (
          'Resources' => 'Resource'
       );

    public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, // Controller
             'Resources', // Source name
             'Resource', // Source class
             '?',   // File name on DataObject
             array(
                'Name' => 'Name',
                'Description' => 'Description',
                'Category' => 'Category',
                'Attachment.Name' => 'Attachment',
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
    ...

    File: Resource.php

    class Resource extends DataObject
    {
       static $db = array (
          'Name' => 'Text',
          'Description' => 'Text',
          'Category' => "Enum('Industry, Finance, Education')",
       );
       
       static $has_one = array (
          'ResourcePage' => 'ResourcePage'
       );
       
       static $has_many = array (
          'Attachments' => 'ResourceFile'
       );
    ...

    File: ResourceFile.php

    class ResourceFile extends File
    {   
       static $has_one = array (
          'Resource' => 'Resource'
       );

    Which label would I use as the fourth argument?

  • UncleCheese
    Avatar
    4085 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    This doesn't work:

    static $has_many = array (
    'Attachments' => 'ResourceFile'
    );

    FileDOM is for DataObjects with a has_one file.

    You can use a regular DOM to manage those Resources and just use a MultipleFileUploadField for the Attachments field. You'll have to either decorate the File class or create a file subclass to put a has_one Resource on the File.

  • VanceK
    Avatar
    Community Member
    17 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Thank you UncleCheese! I will give that a whirl!

  • bunheng
    Avatar
    Community Member
    78 Posts

    Re: many Attachments on FileDataObjectManager Link to this post

    Good morning UncleCheese,

    Is it possible way to have category from other table.

    Thanks in advance for your reply.

    Regards,
    Bunheng

    3843 Views
Page: 1 2 3
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.