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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Preview: DataObjectManager module


Go to End


379 Posts   95930 Views

Avatar
Carbon Crayon

Community Member, 598 Posts

30 April 2009 at 1:44am

Edited: 30/04/2009 1:46am

@Shellmax

If you are using a has_one relationship on the attached DataObject it will have one column called MyPageTypeID which corresponds to the page they are attached to. When you duplicate that page, the new page has a different ID and so those dataObjects will not be associated with that page. You would need to use a has_many or belongs_many_many relationship and a ManyManyDataObjectManager to have DataObjects visible on more than one page.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

30 April 2009 at 1:48am

@Johnny -- That's really strange. Can you change the die statement to print_r($_POST) and make sure that "parentIDName" is in the array? Also check line 263 of FileDataObjectManager and make sure that it is being added as a post param

'parentIDName' => $this->getParentIdName( $this->getParentClass(), $this->sourceClass() ),

If it is, try echoing out $this->getParentIdName( $this->getParentClass(), $this->sourceClass() ) somewhere below the addPostParams() function and see if you can get anything to come out.

As a reminder, you need to set up your data model like so:

FileHolder -> has_many -> FileObjects -> has_one -> File

And of course, FileObject->has_one FileHolder.

It's all in the FDOM docs.

@pali -- Please post your code. It doesn't seem right that $ImageAtts is the control and ImageAtt is the object in that loop.

@schellmax - Please forward your request to Silverstripe. I've asked them and they turned me down. I think I need a bigger army. :)

Avatar
schellmax

Community Member, 126 Posts

30 April 2009 at 2:44am

@aram:
you're right, but for a cms user, it would make more sense if a page 'duplicate' has exactly the same 'contents' as the original one, he might not understand it has to do with related 'dataobjects' - but this is another topic.

@unclecheese:
i sent an email to silverstripe begging for an own forum for dataobjectmanager. i'll post response here.

Avatar
pali

Community Member, 33 Posts

30 April 2009 at 3:38am

thanky UncleCheese for your interest:

ecommerce/code/products/Product.php:

<?php
/**
 * This is a standard Product page-type with fields like
 * Price, Weight, Model/Author and basic management of
 * groups.
 * 
 * It also has an associated Product_OrderItem class,
 * an extension of OrderItem, which is the mechanism
 * that links this page type class to the rest of the
 * eCommerce platform. This means you can add an instance
 * of this page type to the shopping cart.
 * 
 * @package ecommerce
 */
class Product extends Page {
	
	public static $db = array(
		'Price' => 'Currency',
		'Weight' => 'Decimal(9,2)',
		'Model' => 'Varchar',
		'FeaturedProduct' => 'Boolean',
		'AllowPurchase' => 'Boolean',
		'InternalItemID' => 'Varchar(30)'
	);
	

	public static $has_many = array(
		'Variations' => 'ProductVariation',
        'Resources' => 'Resource',
        'ImageAtts' => 'ImageAtt'
	);
	
	public static $many_many = array(
		'ProductGroups' => 'ProductGroup'
	);
	
	public static $belongs_many_many = array();
	
	public static $defaults = array(
		'AllowPurchase' => true
	);
	
	public static $casting = array();
	
	static $default_parent = 'ProductGroup';
	
	static $add_action = 'a Product Page';
	
	static $icon = 'cms/images/treeicons/book';
	
	function getCMSFields() {
		$fields = parent::getCMSFields();

		// Standard product detail fields
		$fields->addFieldsToTab(
			'Root.Content.Main',
			array(
				new TextField('Weight', _t('Product.WEIGHT', 'Weight (kg)'), '', 12),
				new TextField('Price', _t('Product.PRICE', 'Price'), '', 12),
				new TextField('Model', _t('Product.MODEL', 'Model/Author'), '', 50),
				new TextField('InternalItemID', _t('Product.CODE', 'Product Code'), '', 7)
			)
		);
        
            $manager = new FileDataObjectManager(
			$this, // Controller
			'Resources', // Source name
			'Resource', // Source class
			'Attachment', // File name on DataObject
			array(
				'Name' => 'Name', 
				'Description' => 'Description', 
				'Category' => 'Category'
			), // Headings 
			'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
			// Filter clause
			// Sort clause
			// Join clause
		);
        
        $fields->addFieldToTab("Root.Content.Resources", $manager);
        
        $imageAtt = new ImageDataObjectManager(
			$this, // Controller
			'ImageAtts', // Source name
			'ImageAtt', // Source class
			'ImageAtt', // File name on DataObject
			array(
				'Name' => 'Name', 
				'Description' => 'Description'
			), // Headings 
			'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
			// Filter clause
			// Sort clause
			// Join clause
		);
        
        $fields->addFieldToTab("Root.Content.Images", $imageAtt);


		// Flags for this product which affect it's behaviour on the site
		$fields->addFieldsToTab(
			'Root.Content.Main',
			array(
				new CheckboxField('FeaturedProduct', _t('Product.FEATURED', 'Featured Product')),
				new CheckboxField('AllowPurchase', _t('Product.ALLOWPURCHASE', 'Allow product to be purchased'), 1)
			)
		);

		$fields->addFieldsToTab(
			'Root.Content.Variations', 
			array(
				new HeaderField(_t('Product.VARIATIONSSET', 'This product has the following variations set')),
				new LiteralField('VariationsNote', '<p class="message good">If this product has active variations, the price of the product will be the price of the variation added by the member to the shopping cart.</p>'),
				$this->getVariationsTable()
			)
		);

		$fields->addFieldsToTab(
			'Root.Content.Product Groups',
			array(
				new HeaderField(_t('Product.ALSOAPPEARS', 'This product also appears in the following groups')),
				$this->getProductGroupsTable()
			)
		);
		
		return $fields;
	}
	
	...

mysite/code/ImageAtt.php:

<?php
class ImageAtt extends DataObject
{
	static $db = array (
		'Name' => 'Text',
		'Description' => 'Text'
	);
	
	static $has_one = array (
		'ImageAtt' => 'File',
		'Product' => 'Product'
	);
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Name'),
			new TextareaField('Description'),
			new FileIFrameField('ImageAtt')
		);
	}
}
// EOF

Avatar
Johnny

Community Member, 34 Posts

30 April 2009 at 5:04am

@UncleCheeze : You where right there were a problem with the model! It works A number one now! Sorry about that!

Also, I really think your module should be part of SS core!!!

JP

Avatar
Carbon Crayon

Community Member, 598 Posts

30 April 2009 at 5:36am

Edited: 30/04/2009 5:38am

Also, I really think your module should be part of SS core!!!

Amen to that, the idea of using a CTF now makes me shudder!

Viva la DataObjectManager!

And it certainly needs it's own form at the very least....I suspect it's now one of, if not the most widely used module. I use it in pretty much every project I do.....

Avatar
UncleCheese

Forum Moderator, 4102 Posts

30 April 2009 at 5:41am

I find this all very flattering. Please show your support of DataObjectManager by contacting the Silverstripe folks and letting them know all of these things. I can't get it accomplished alone!

Thanks, everyone!

Avatar
Johnny

Community Member, 34 Posts

30 April 2009 at 5:48am

The DataObject part of SS core is lacking a lot of features. I was surprised to find out that a hasMany relationship would show records for other objects and you also need to check the records for which you want to use (but you can't check a record that is already used)... which is non-sense to me... DataObjectManager doesn't do that...!

I gotta write SS folks! They do also an amazing job! We just need to work all togheter!

Thanks again!

JP

Go to Top