Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Reverse order for FileDataObjectManager process

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1134 Views
  • Toobad
    Avatar
    Community Member
    5 Posts

    Reverse order for FileDataObjectManager process Link to this post

    I am currently using the FileDataObjectManager for a site that I am working on. Is there a way to begin the process of adding a record by adding the attributes to the DataObject first and then ending the process with the bulk upload or file import? Thanks in advance!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Reverse order for FileDataObjectManager process Link to this post

    Doesn't really make a whole lot of sense. You create all these records, then do a bulk upload. How would all of those uploads know to which dataobject they belong?

    If you want to do it without the bulk uploader, just use a regular DOM. Each record you create will give you a "Save and add {YourFileObject}" button.

  • Toobad
    Avatar
    Community Member
    5 Posts

    Re: Reverse order for FileDataObjectManager process Link to this post

    Ok. Got it. I am using the regular DOM now. Let me see if I can figure this one out. Thanks.

  • Toobad
    Avatar
    Community Member
    5 Posts

    Re: Reverse order for FileDataObjectManager process Link to this post

    I was able to get the file upload to work with the regular DOM, however, I lost the ability to upload multiple files as I could with the FileDataObjectManager. Any recommendations?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Reverse order for FileDataObjectManager process Link to this post

    You can't have both. It's programatically impossible to bulk upload a bunch of files and have them magically know which dataobject they're attached to.

    Right now, the FDOM works like this:

    - Files are bulk uploaded to the controller, which creates a new File object, a new DataObject, links them, and writes both to the database. At this point, the DataObjects have null values for all their fields, other than keys.

    - After upload, the list of all new DataObject IDs is passed to the edit form, which loops through each one and allows you to populate their fields with values, and rewrite.

    You're suggesting:

    - Create a bunch of dataobjects, write them to the DB

    - upload a bunch of files, sorted arbitrarily, to the controller, which pairs them to their corresponding dataobjects.

    The problem is that second part. How does a file know which dataobject it belongs to if the file upload and DataObject creation are happening asynchronously? There's no way at that point to tell the controller that, say, the second file in the list corresponds to the second dataobject you created. Even if it were possible, one would have to remember the exact order of the dataobjects he created to surgically build a properly ordered list of files in the upload queue.

    To me, it just seems needlessly complicated. I think it's a lot clearer to the user if he is asked for a file attachment immediately after creating an object, because the association is readily apparent at that point.

  • Toobad
    Avatar
    Community Member
    5 Posts

    Re: Reverse order for FileDataObjectManager process Link to this post

    Thanks for the response. Just to make sure I am on the same page with you...I have a pop up form that is displayed when a user selects the + ADD button. This brings up a form with several fields for the user to fill out. At the bottom of this form, I have a file upload button that is displayed after the user has saved the data for the first time. In this scenario is it still not possible to upload multiple files? The files would be attached to the data object(s) that is created during the saving of the form.

    Here is a snippet of code:

    ...
    static $has_one = array (
       'PropertyPage' => 'PropertyPage',
       'Brochure' => 'File',
       'SitePlan' => 'File'
       );

    public function getCMSFields_forPopup()
       {
          return new FieldSet
          (
             new TextField('Address1'),
             new TextField('Address2'),
             new TextField('City'),
             new DropdownField('State', 'State', singleton('Property') ->dbObject('State')->enumValues()),
             new TextField('ZipCode'),
             new TextareaField('Description'),
             new TextField('SQFT'),
             new TextField('Rate'),
             new TextField('Status'),
             new CheckboxField('Leasing'),
             new DropdownField('Category','Category', singleton('Property')->dbObject('Category')->enumValues()),
             new FileIFrameField('Brochure'),
             new FileIFrameField('SitePlan')
          );
       }

    As you can see, I am using the FileIFrameField that allows me to upload/replace/delete a single file. What I would like is the ability to use the SWFUploadFileIFrameField object or the BulkUploaderField object instead. I hope this help.

  • Toobad
    Avatar
    Community Member
    5 Posts

    Re: Reverse order for FileDataObjectManager process Link to this post

    Ok. I got it figured out (almost) based upon a recommendation from another post (http://silverstripe.org/general-questions/show/252776). My code now looks like:

    ...
    static $has_one = array (
          'PropertyPage' => 'PropertyPage',
          'Brochure' => 'File',
          'SitePlan' => 'File'
       );
          
       public function getCMSFields_forPopup()
       {
          return new FieldSet
          (
             new TextField('Address1'),
             new TextField('Address2'),
             new TextField('City'),
             new DropdownField('State', 'State', singleton('Property') ->dbObject('State')->enumValues()),
             new TextField('ZipCode'),
             new TextareaField('Description'),
             new TextField('SQFT'),
             new TextField('Rate'),
             new TextField('Status'),
             new CheckboxField('Leasing'),
             new DropdownField('Category','Category', singleton('Property')->dbObject('Category')->enumValues()),      
           new SWFUploadFileIFrameField('Brochure', 'Upload a brochure'),
             new SWFUploadFileIFrameField('SitePlan', 'Upload a site plan')
        );
       }

    Additionally, I added an isset() function check on the $data variable in the SWFUploadFileIFrameField.php file (@ line11). Thanks again for your assistance!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Reverse order for FileDataObjectManager process Link to this post

    Right now there is no tool for managing a has_many file relationship with DataObjects. I would take it up one level and make those dataobjects pages that just don't show in menus in search. You can strip out some of the CMS fields to make it clearer to the user, too. Then you use an FDOM to manage the many files associated with that "object."

    1134 Views
Page: 1
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.