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, Ed, biapar, Willr, Ingo, swaiba

DataObjectManager many_many belongs_many relatation


Go to End
Reply


5 Posts   1967 Views

Avatar
Tonyair

Community Member, 81 Posts

18 July 2010 at 1:53am

Edited: 18/07/2010 2:14am

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

Forum Moderator, 4102 Posts

18 July 2010 at 3:21am

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

Community Member, 81 Posts

18 July 2010 at 8:41am

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

Forum Moderator, 4102 Posts

18 July 2010 at 9:59am

I'm still confused. Why not ManyManyFileDataObjectManager?

Avatar
Tonyair

Community Member, 81 Posts

18 July 2010 at 12:41pm

Edited: 18/07/2010 12:41pm

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