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

Reverse order for FileDataObjectManager process


Go to End


8 Posts   1947 Views

Avatar
Toobad

Community Member, 5 Posts

8 June 2009 at 5:22am

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!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 June 2009 at 5:54am

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.

Avatar
Toobad

Community Member, 5 Posts

8 June 2009 at 7:29am

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

Avatar
Toobad

Community Member, 5 Posts

8 June 2009 at 1:52pm

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?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

8 June 2009 at 2:29pm

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.

Avatar
Toobad

Community Member, 5 Posts

8 June 2009 at 4:29pm

Edited: 08/06/2009 4:51pm

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.

Avatar
Toobad

Community Member, 5 Posts

8 June 2009 at 5:18pm

Edited: 08/06/2009 5:23pm

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!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

9 June 2009 at 2:25am

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."