Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Uploadify and DataObjectManager patches

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: 1901 Views
  • miiihi
    Avatar
    Community Member
    4 Posts

    Uploadify and DataObjectManager patches Link to this post

    Hi,

    I made some improvements on Uploadify and DataObjectManager, which might be considered for including in trunk.
    Uploadify

    1. ANSI database compatibility

    2. Support for ManyMany relations. Ie. support for uploading (attaching) multiple files and reusing them on multiple pages. To use, extend File class:

    MyMultiFile.php

    class MyMultiFile extends File {
       static $belongs_many_many = array (
          'TestPage' => 'TestPage'
       );
    }


    TestPage.php

    class TestPage extends Page {
       static $many_many = array (
          'Documents' => 'MyMultiFile',
       );
       
       function getCMSFields() {
          $fields = parent::getCMSFields();
          $f = new MultipleFileUploadField('Documents','Upload several files');
          $fields->addFieldToTab('Root.Content.Documents', $f);
          return $fields;
       }
    }

    3. deleteEnabled feature
    As deleting files, which can be attached on multiple pages, isn't really desired behavior, I added "deleteEnabled" setting, which is false by default on MultipleFile upload field. To enable delete (as it was before patch), use for example:

          $f = new MultipleFileUploadField('Documents','Upload several files',array('deleteEnabled'=>true));

    uploadify.patch

    Issues/unresolved.
    - there should be only one class, that extends File class. Otherwise, we get unpredictable behaviour.

    DataObjectManager

    1. ANSI database compatibility
    2. ManyManyDataObjectManager and ManyManyFileDataObjectManager use $sourceSort for nonrelated objects.
    Default sorting of non related objects was not implemented, but it is very easy to use $sourceSort setting of the field to do so.
    Example using Testimonials data objects. Non related objects will be sorted by Date DESC.

    _config.php

    SortableDataObject::add_sortable_many_many_relation("TestimonialPage", "Testimonials");


    Testimonial.php

    class Testimonial extends DataObject {
       static $db = array (
          'Date' => 'Date',
          'Author' => 'Text',
          'Quote' => 'HTMLText'
       );

       static $belongs_many_many = array (
          'TestimonialPage' => 'TestimonialPage'
       );

       public function getCMSFields_forPopup()   {
          return new FieldSet(
             new DateField('Date'),
             new TextField('Author'),
             new TextareaField('Quote')
          );
       }
    }


    TestimonialPage.php

    class TestimonialPage extends Page {
       static $has_many = array (
          'Testimonials' => 'Testimonial'
       );

       public function getCMSFields() {
          $f = parent::getCMSFields();
          $f->addFieldToTab("Root.Content.Testimonials", new DataObjectManager(
             $this,
             'Testimonials',
             'Testimonial',
             array('Date' => 'Date','Author'=>'Author','Quote' => 'Quote'),
             'getCMSFields_forPopup',
             '',
             '"Date" DESC'
          ));
          return $f;
       }
    }

    dataobject_manager.patch

    Issues/unresolved.
    - What should sorting do, when we have a sortable many_many relation? Currently, sorting is enabled on client side, but it doesn't do anything.

    Regards, miiihi

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify and DataObjectManager patches Link to this post

    Wow! These are some great patches. The Uploadify many_many patch has been on my list for a while, but I haven't been able to get to it. That's great.

    I know MMDOM has tons of sorting issues, but does your patch break the sortable many_many functionality? That is, when using SortableDataObject::add_sortable_many_many_relation()?

    Have you tested the Uploadify patch with both many_many and has_many relations?

    Thanks again!

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • miiihi
    Avatar
    Community Member
    4 Posts

    Re: Uploadify and DataObjectManager patches Link to this post

    1. MMDOM sorting. My patch doesn't break anything... or so I hope . I just added default sorting (coming from field config options) to the end of sorting field list, so when using with Sortable many_many, we now get ORDER BY MMSort, Checked, DefaultSort. Indeed I created this fix just for the situation, where I had sortable many_many relation, but I had no control on sort order of unrelated items.

    Now, about issue I have mentioned - if we can specify, how user sorting should behave on many_many relations, with Sortable on or not, I'd be happy to fix it. I'm not sure what'd be the desired behaviour (configurable?), but I know, that it is broken now. User can click on column headers, arrows change, but the rows don't...

    2. Uploadify. I have done basic testing with many_many and had_many relations in MySql and in Postgres. But would recommend some more... Specially ANSI compatibility can have some hidden problems... that goes DOM too.

    regards, miiihi

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: Uploadify and DataObjectManager patches Link to this post

    Great patch, using many_many makes including files much intuitive for users and saves uploading the same file multiple times!

    Any insight when this will be included in the official Uploadify and DOM?

  • Wilson
    Avatar
    Community Member
    63 Posts

    Re: Uploadify and DataObjectManager patches Link to this post

    UC,

    Will miiihi's patch fix the double-upload requirement now? Just wanted to check if you think it will make it to trunk soon, if not we'll incorporate the patch in our project.

    Thanks miiihi and UC!

    Wilson

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify and DataObjectManager patches Link to this post

    @Miihi -- I still want to apply this patch. Are you on Github? Could you submit it as a pull request?

  • miiihi
    Avatar
    Community Member
    4 Posts

    Re: Uploadify and DataObjectManager patches Link to this post

    funny... as you are writing, I'm in the process of moving your source from my instant made git repo to a fork of your github repo. It should be ready by tomorrow and you'll pull request.

    miiihi

  • UncleCheese
    Avatar
    4085 Posts

    Re: Uploadify and DataObjectManager patches Link to this post

    Actually, I just applied it.

    Can you submit those DOM patches, though? Those were a real headache to merge. I think it was from an older version of the code.

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