Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Many to many relationship


Reply


3 Posts   765 Views

Avatar
Stef87

Community Member, 66 Posts

27 August 2012 at 8:52pm

Edited: 07/09/2012 12:59am

Question changed to be more specific
Firstly I'm using SilverStripe 2.4.7. I am tearing my hair out trying to figure out how to do this and I need to help.

Ok so I have a dataobject and I use a dataobjectmanager on the admin's page to look after all of the dataobjects. I also use dataobjectmanager on other user's pages to look after the dataobjects that only relate to them. So the fields in the dataobject are used in the popups on both types of pages (the admin and the user pages).

I need to add a checkbox to the admin page popup only so that when they create one of these dataobjects they can select multiple users and then the ids are saved in a linked table. I hope I'm being clear.

I have my getCMSFields function in my dataobject (Offer) and getCMSFields in AllOffers with a dataobjectmanager. how to I add the checkbox without adding it to every other page too?

Avatar
Fuzz10

Community Member, 787 Posts

7 September 2012 at 1:59am

Edited: 07/09/2012 1:59am

I'm not sure I entirely follow your question, but if I understand correctly, it is about permissions rather than working with the dataobject-manager or relationships ?

You can check whether the user has Admin-rights , and then based on that add the field to the user-interface.

if(Permission::check('ADMIN')) return true;

Make sure to also secure your dataobject-class (you can override the canCreate() / canDelete() methods). E.g. :

function canCreate($member){
if (Permission::check('ADMIN')) return true;
}

Avatar
Stef87

Community Member, 66 Posts

7 September 2012 at 2:05am

Edited: 07/09/2012 2:10am

Hi Fuzz10, thanks for your quick response.

I apologise for being unclear. I'll try to simplify. Basic users have there own page (which only they have access to) and can create movies (dataobject). The movies they create are only linked to them. The admin can edit all movies or create global ones, through their page, that apply to everyone (hence the linked table). Yes I had tried something like that.

if(Permission::check('ADMIN'){
if (! empty($stores))
    {
         
      $checkBox = new CheckboxSetField(
         $name = "Stores",
         $title = "Select Stores",
         $source = $stores
      );

      $fields->push($checkBox);
   }
}

But while this displayed the checkboxes perfectly, it caused a problem with saving in the database. Basically it just didn't save. I was thinking I need a function to populate the linked list but this seems like a bit of a hacky workaround.

I was also old that I should move that to the page rather than the dataobject but I'm not sure how.