Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjectManager many_many belongs_many relatation

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1641 Views
  • Tonyair
    Avatar
    Community Member
    81 Posts

    DataObjectManager many_many belongs_many relatation Link to this post

    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'
       );
    ..
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager many_many belongs_many relatation Link to this post

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

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: DataObjectManager many_many belongs_many relatation Link to this post

    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'
                )
             )
          );

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager many_many belongs_many relatation Link to this post

    I'm still confused. Why not ManyManyFileDataObjectManager?

  • Tonyair
    Avatar
    Community Member
    81 Posts

    Re: DataObjectManager many_many belongs_many relatation Link to this post

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

    1641 Views
Page: 1
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.