Jump to:

7939 Posts in 1472 Topics by 944 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: 58435 Views
  • Bo_Einzeller
    Avatar
    Community Member
    18 Posts

    Re: Preview: DataObjectManager module Link to this post

    Thanks for your fast reply! I've tested it and everything's fine. Great work!
    I've tested the translation, if your interested, i could send you the german translation-File.
    Cheers

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hello Everyone,

    I would like to use FileDataObjectManager to relate files to a given page. Example: page a is associated with 'File1.pdf' and 'File6.pdf', page b is associated with other files, etc.

    The problem I've hit is that the FileDataObjectManager in the QualityPDFPage below shows all files associated with any page, not just those files associated with the given page.

    Any ideas on what I'm doing wrong?

    Thanks!
    Ben

    class QualityPDFPage extends QualityChildPage {
       static $has_many = array(
          'PDFResource' => 'PDFResource'
       );
       static $db = array();
       static $can_be_root = false;
       static $allowed_children = array();

       function getCMSFields() {
          $fields = parent::getCMSFields();

          $manager = new FileDataObjectManager(
             $this, // Controller
             'PDFResource', // Source name
             'PDFResource', // Source class
             'PDF',
             array(
                'Name' => 'Name'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)

          );
          
          $fields->addFieldToTab('Root.Content.Resources', $manager);
          $fields->removeFieldFromTab("Root.Content.Main", "Content");
       
          return $fields;
       }
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Is QualityPDFPage the only page type that uses the FileDataObjectManager? Or is it used in another class as well? If so, you need to use the setParentClass() method.

    Can you post your PDFResource class?

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Preview: DataObjectManager module Link to this post

    No, it's not the only class that uses FileDataObjectManager. I'll try setParentClass().

    Here's PDFResource:

    class PDFResource extends DataObject
    {
       static $db = array (
          'Name' => 'Varchar(30)'
       );
       
       static $has_one = array (
          'Thumbnail' => 'Image',
          'PDF' => 'PDF', // this class is an extension of File which adds the ability to generate a thumbnail of the PDF's first page.
          'Page' => 'Page'
       );
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Yeah, you need to because $has_one Page is too ambiguous. It's going to try to set QualityPDFPageID on your object, which is a field that doesn't exist, so you wont' get the relation. Make sure you set your FileDataObjectManager object to ->setParentClass("Page")

  • Chucky2k
    Avatar
    Community Member
    32 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hi Uncle Cheese,

    Checked out the latest today and noticed a few issues. Looks like revision 82 has caused a couple of issues with DataObjectManager.php. On line 288 I changed from:

    $dropdown = new DropdownField('Filter',$this->filter_label . " (<a href='#' class='refresh'>'._t('DataObjectManager.REFRESH','refresh').'</a>)", $map, $value);

    to:

    $dropdown = new DropdownField('Filter',$this->filter_label . " (<a href='#' class='refresh'> "._t('DataObjectManager.REFRESH','refresh')."</a>)", $map, $value);

    Also, the removal of...

    protected $view = "list";

    and the public function ListStyle() causes the DataObjectManager Tab layout and the Albums Tab layout on an ImageGalleryPage to break.

    David

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Preview: DataObjectManager module Link to this post

    Uncle Cheese,

    Thanks for the help. Still no go. With --

    $manager->setParentClass('Page');

    -- no files show up in the file data object manager. Of note, PageID in the database table pdfresource is being set to zero. I'm guessing that if we figured out how to get field PageID to be set to the correct value, things might work. Any ideas?

    Revised code below.

    Thank you,
    Ben
    --------------

    Revised Code:

    class QualityPDFPage extends QualityChildPage {
       static $has_many = array(
          'PDFResource' => 'PDFResource'
       );
       static $db = array();
       static $can_be_root = false;
       static $allowed_children = array();

       function getCMSFields() {
          $fields = parent::getCMSFields();

          $manager = new FileDataObjectManager(
             $this, // Controller
             'PDFResource', // Source name
             'PDFResource', // Source class
             'PDF',
             array(
                'Name' => 'Name'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)

          );
          $manager->setParentClass('Page');
          
          $fields->addFieldToTab('Root.Content.Resources', $manager);
          $fields->removeFieldFromTab("Root.Content.Main", "Content");
       
          return $fields;
       }
    }

    class PDFResource extends DataObject
    {
       static $db = array (
          'Name' => 'Varchar(30)'
       );
       
       static $has_one = array (
          'PDF' => 'PDF',
          'Page' => 'Page'
       );
    }

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: Preview: DataObjectManager module Link to this post

    Good thought, ntessore. I don't think it will work, though, as there is no QualityPDFPageID column in the PDFResource table.

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