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

DataObjectManager many_many belongs_many relatation


Reply

5 Posts   1724 Views

Avatar
Tonyair

18 July 2010 at 1:53am (Last edited: 18 July 2010 2:14am), Community Member, 81 Posts

I have two classes:
Many WarePages = many WareItems
and WareItem belongs many WarePages

When I edit WarePage I have to see all WareItems and if i need i have to add them in that dialog.

That one function displays all WareItems and places 'checked' only for items that belongs WarePage object and I can easily check or uncheck items, but I want to use DataObjectManager to display Items more correctly

$itemList = DataObject::get('WareItem');
$fields->addFieldToTab('Root.Content.WareItems', new CheckboxSetField('WareItems', '', $itemList));

But DataObjectManager just displays all WareItems:

class WarePage extends Page {

   static $many_many = array(
      "WareItems" => "WareItem",
   );
function getCMSFields() {
      $fields = parent::getCMSFields();
      $dataobjectmanager = new FileDataObjectManager(
         $this,
         'WareItems', // Source name
         'WareItem', // Source class
         'Photo', // File name on DataObject
         array('Name' => 'Name','WareBrand.Name'=>'Brand','Article' => 'Article'),
         'getCMSFields_forPopup'
      );
      $dataobjectmanager->setUploadFolder('WareHouse/'.$this->title);
      $dataobjectmanager->enableUploadDebugging();
..
$fields->addFieldToTab("Root.Content.WarePageItems", $dataobjectmanager);

      return $fields;
}
}

class WareItem extends DataObject {
...
   static $belongs_many_many = array(
      'WarePages' => 'WarePage'
   );
..
}

Avatar
UncleCheese

18 July 2010 at 3:21am 4085 Posts

I'm not sure I understand. If the relationship is many_many, why are you using a regular DOM and not a ManyManyDOM?

Avatar
Tonyair

18 July 2010 at 8:41am Community Member, 81 Posts

There're no swf uploader, import images from directory and thumbnails for ManyManyDOM
I temporally made massive uploader for this one DOM, but maybe there're other way to do it.

That's my code:

$dataobjectmanager = new ManyManyDataObjectManager(
         $this, // Controller
         'WareItems', // Source name
         'WareItem', // Source class
         array('Name' => 'Name','Article' => 'Article'),
         'getCMSFields_forPopup'
      );

      // SWF Upload
      SWFUploadConfig::addPostParam('holderID', $this->ID);
      SWFUploadConfig::addPostParam('holderClass', __CLASS__);
      SWFUploadConfig::addPostParam('itemClass', 'WareItem');
      $fields->addFieldToTab("Root.Content.MassiveUploader",
         new SWFUploadField(
            "EditForm",
            "Upload",
            "",
            array(
               'file_upload_limit' => 10,
               'file_queue_limit' => 10,
               'browse_button_text' => 'Add ware items ...',
               'upload_url' => Director::absoluteURL('WarePage_Controller/uploadHandler'), // Custom Handler
               'required' => 'true',
               'debug' => 'true'
            )
         )
      );

Avatar
UncleCheese

18 July 2010 at 9:59am 4085 Posts

I'm still confused. Why not ManyManyFileDataObjectManager?

Avatar
Tonyair

18 July 2010 at 12:41pm (Last edited: 18 July 2010 12:41pm), Community Member, 81 Posts

oh thx =) i'm sorry just didn't see it in manual =)