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: 58368 Views
  • drye
    Avatar
    Community Member
    49 Posts

    Re: Preview: DataObjectManager module Link to this post

    ok, well I got it to work, learned that you can't use $this->MyBoolean inside a getMyBoolean, had to change function to getMyBooleanField.

    Now that seems to work for viewing, but the edits don't persist. Any Ideas?

    http://pastie.org/415982

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    You're not understanding how a custom getter works.

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

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

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

    That's all you need. When drawing the values for each record, SS first looks for a function named get[PropertyName]. If that function exists, it returns the value of that function. Otherwise, it just returns the value of PropertyName, which in the case of a boolean, is a 1 or 0.

  • drye
    Avatar
    Community Member
    49 Posts

    Re: Preview: DataObjectManager module Link to this post

    I appreciate your comments, however I do understand how the get functions work. Your code will not work, you get an error. $this->Published is undefined, by asking in the IRC channel I found out that it was because that basically creates infinite recursion. You are calling the get function you just defined within it's self by asking for $this->Published. So I had to write a differently named getter to get the field I wanted, I want an ACTUAL check box field so I need to return a field. Well my code achieves this portion of my question. The open question I have is it possible to directly edit the data from the table and not within the light box? I have a checkbox, and I can change it's state from the table, but the changes do not persist. On a similar note, what if you wanted the text to be editable from the table, is this possible?

    Again, I appreciate your help! Thanks again!

  • 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!)

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