Jump to:

7940 Posts in 1543 Topics by 946 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

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
Go to End
Author Topic: 61019 Views
  • vstrazz
    Avatar
    Community Member
    63 Posts

    Re: Preview: DataObjectManager module Link to this post

    I'm trying to add DataObjectManager to UserDefinedForm to help with sorting submissions, and exporting. ( for instance for mailing lists ). I did get it to add into UserDefinedForm, it just wont delete or edit or export lololol

  • Amir Mostofi
    Avatar
    Community Member
    59 Posts

    Re: Preview: DataObjectManager module Link to this post

    To Hu, UncleCheese or anyone who could help.

    The issue I have is what ntessore mentioned back on page 6 of this topic. When filedataobjectmanager is used on page class "Page" for instance it all works fine and there's no need for a filter clause or setParentClass. However, when you subclass Page, the subclassed pages show all the managed files. You can circumvent this by using a filter clause. However, with or without the filter clause, you cannot add any managed files to the subclassed pages. Basically, when you try to add a file to a page which is a subclass of Page, the added file does not stick to that page. Its PageID remains 0.
    So the issue is always related to subclasses of a page type, not the page type itself. I'm not sure how ntessore resolved this issue. He mentioned using setParentClass, but I'm not sure exactly how and where I should use this, because my attempts at setParentClass have not worked.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    You do have to use setParentClass. That's what it's for. You have to do the same thing on a ComplexTableField. I've tested it, and the same thing happens.

  • Amir Mostofi
    Avatar
    Community Member
    59 Posts

    Re: Preview: DataObjectManager module Link to this post

    Thank you UncleCheese!
    The problem I have is I guess not knowing exactly where to apply the setparentClass. Would you kindly assist? I really want to get the hang of this module as it's by far the most useful module.

    Below are the files in question. Adding ImageAttachments does not stick to ResourcePage types which is a subclass of Page. And I have to use filter clause "PageID = {$this->ID}" in Page.php to prevent all added ImageAttachments to appear under the ResourcePage types (even ones from other Pages). Thank you in advance.

    ImageAttachment.php
    ----------------
    <?php
    class ImageAttachment extends DataObject
    {
       static $db = array (
          'Name' => 'Text',
          'URL' => 'Text'
       );
       
       static $has_one = array (
          'Attachment' => 'File',
          'Page' => 'Page'
       );
       
       public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Name'),
             new TextField('URL'),
             new FileIFrameField('Attachment')
          );
       }
    }
    ?>
    ----------------

    Page.php
    ----------------
    <?php

    class Page extends SiteTree {
       
       public static $db = array(
       );
       
       public static $has_one = array(
       );
       
       static $has_many = array (
          'ImageAttachments' => 'ImageAttachment'
       );
       
       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new FileDataObjectManager(
             $this, // Controller
             'ImageAttachments', // Source name
             'ImageAttachment', // Source class
             'Attachment', // File name on DataObject
             array(
                'Name' => 'Name',
                'URL' => 'URL'
             ), // Headings
             'getCMSFields_forPopup', // Detail fields (function name or FieldSet object)
             "PageID = {$this->ID}" // Filter clause
             // Sort clause
             // Join clause
          );
          
          // If undefined, all types are allowed. Pass with or without a leading "."      
          $manager->setAllowedFileTypes(array('jpg','gif','swf'));
          
          // Label for the upload button in the popup
          $manager->setBrowseButtonText("Upload (JPG, GIF or SWF)");
          
          // In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
          $manager->setGridLabelField('Name');
          
          // Plural form of the objects being managed. Used on the "Add" button.
          // If left out, this defaults to [MyObjectName]s
          $manager->setPluralTitle('Images');
                
          $f->addFieldToTab("Root.Content.Images", $manager);

          return $f;
       }
    }

    class Page_Controller extends ContentController {
    ...   
    }

    ?>
    ----------------

    ResourcePage.php
    ----------------
    <?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
             'Attachment', // File name on DataObject
             array(
                'Name' => 'Name',
                'Description' => 'Description',
                'Category' => 'Category'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
          
          $manager->setFilter(
             'Category', // Name of field to filter
             'Filter by Category', // Label for filter
             singleton('Resource')->dbObject('Category')->enumValues() // Map for filter (could be $dataObject->toDropdownMap(), e.g.)
          );
          
          // If undefined, all types are allowed. Pass with or without a leading "."      
          $manager->setAllowedFileTypes(array('pdf','doc'));
          
          // Label for the upload button in the popup
          $manager->setBrowseButtonText("Upload (PDF or DOC only)");
          
          // In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
          $manager->setGridLabelField('Name');
          
          // Plural form of the objects being managed. Used on the "Add" button.
          // If left out, this defaults to [MyObjectName]s
          $manager->setPluralTitle('Resources');
                
          $f->addFieldToTab("Root.Content.Resources", $manager);

          return $f;
       }

    }

    class ResourcePage_Controller extends Page_Controller
    {
    }
    ?>
    ----------------

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    What happens when you add $manager->setParentClass("Page") and $manager->setParentClass("ResourcePage"); to those functions, respectively?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    I believe this happens because there is no such thing as a PageID in most cases. Page has no unique fields so it has no table in the Database. I think SiteTree might be a more appropriate relationship.

    I do know what you're talking about, though. I have used DataObjectMangaers to manage objects of a Page before and I have resolved the issue using setParentClass().

  • Amir Mostofi
    Avatar
    Community Member
    59 Posts

    Re: Preview: DataObjectManager module Link to this post

    Adding $manager->setParentClass("Page") and $manager->setParentClass("ResourcePage") to respective functions and rebuilding the database unfortunately did not resolve anything. I had tried that before. PageID still remains 0 for ImageAttachments added to ResourcePage page(s).

    What do you suggest? I'm at a loss here and need to finish the project quickly.

    I really appreciate your help and patience.

  • Amir Mostofi
    Avatar
    Community Member
    59 Posts

    Re: Preview: DataObjectManager module Link to this post

    UncleCheese, I think the only sure way of getting this to work is to not apply ImageAttachment directly to Page and then use it also in subclasses of Page (e.g. ResourcePage). Instead, I should remove it from Page class, create a subclass of Page, like PageWithImages and apply ImageAttachments to that and to ResourcePage class separately. Both of these classes are subclasses of Page and have no direct relationship to eachother. This works, but requires code duplication which is a bit of a shame!

    61019 Views
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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.