Jump to:

7913 Posts in 1355 Topics by 930 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Go to End
Author Topic: 54258 Views
  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    $this->Published is undefined because in your class you called it "Publish", not "Published".

    Do this..

    $manager = new DataObjectManager(
    $this,
    'MyDataObjects',
    'MyDataObject',
    array('Title' => 'Title, 'Published' => 'PublishedValue')
    );


    class MyDataObject extends DataObject
    {
    static $db = array (
    'Title' => 'Varchar(100)',
    'Published' => 'Boolean'
    );

    public function getPublishedValue()
    {
    return $this->Published ? "Published" : "Unpublished";
    }
    }

    If you want to edit records directly on the table, use a TableField. It will limit you to simple editing, however, so if you have checkbox sets or file uploads, or textareas, it isn't an effective solution. DataObjectManager is an upgrade to ComplexTableFields, not regular TableFields.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Scratch that.. that code I sent you was wrong. I put PublishedValue in the headers array. I'm not thinking straight today.

    For your example all you really need is a getPublish() function on your DataObject. And if this doesn't work:

    return $this->Publish ? "Published" : "Unpublished";

    Then try:

    return $this->Publish == 1 ? "Published" : "Unpublished";

    Worst case:

    return $this->getField('Publish') == 1 ? "Published" : "Unpublished";

    The first one should work fine, though. It's what I've always used. I think it failed last time because you were using the wrong property name.

  • drye
    Avatar
    Community Member
    49 Posts

    Re: Preview: DataObjectManager module Link to this post

    No, I was just sticking with your example. I am not a complete noob . For me $this-Publish is also undefined inside of a function called getPublish() (the whole recursive thing). And as for the editing, I am aware of table fields, but I was trying to achieve editing inside a dataObjectManager. If it can't be done, that is fine, just wanted to ask to make sure before I move on.

    Thanks again!

  • Bo_Einzeller
    Avatar
    Community Member
    18 Posts

    Re: Preview: DataObjectManager module Link to this post

    Hy UncleCheese
    I found some bugs:
    1) If you use $manager-> setDefaultView($type) you can’t switch the view anymore.
    The value of the constructor (with $_REQUEST['ctf'][$this->Name()] is overwriten.

    2) I still have problems with 2 FileDataObjectManager. If the first one is in grid-view, the second can’t be ordered in list view, only in grid view. If the fist one is in list view, everything is ok. I think the problem is caused by the id “list-holder”. This id is not singular.

    3) If i have files in a FileDataObjectManager, icons aren’t displayed in grid-view on first run. If I switch the view 2 times, the icons are displayed.

    4) I’ve added some translation tags. See the .diff-File below. Its for the Revision 80 of your svn.
    Cheers

    Attached Files
  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Bo, you're the man! Thanks for these great catches.

    1) setDefaultView() -- FIXED. Stored default_view as separate property.

    2) Sorting issues on multiple FileDataObjectManagers. -- FIXED. You were correct about the duplicate ID.

    3) File icons not displaying. Very weird. The code I was using shouldn't have worked, but for some reason it was working on one and failing on the other. Icon is now obtained correctly through $this->item->fileField->Icon() instead of $this->fileField->Icon() in FileDataObjectManager_Item.

    4) Thank you for your work on the translations. I've checked them in. (Hope they were tested!)

  • 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?

    54258 Views
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.