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.

Customising the CMS /

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

File Upload Field in ManyManyComplexTableField popup


Go to End


21 Posts   5660 Views

Avatar
kevino

Community Member, 30 Posts

11 November 2009 at 11:52pm

Hm. No, I can't get anything to display unsing an IF statement either.
It's clearly saving to the database though, as the info is still in the CMS when I go back to it.

So other than this telling me that AvailableUnits() isn't returning anything, is there a likely route I'd take to diagnose why?

I've also tried doing the IF with anything which looks remotely connected to the AvailableUnits - ie UnitList, Units to see if it was something as simple as calling the wrong thing.

I'm not sure if it would make any difference, but the MMCF is one of a whole load of tabs..
The whole page looks like this: http://pastie.org/693438
Is there any issue with doing it this way rather than having a dedicated page?

Thanks for your help so far aram. It's very much appreciated.

Avatar
kevino

Community Member, 30 Posts

12 November 2009 at 12:40am

GRRRR..!

I forgot to tick the boxes in the MMCF tab in the CMS.

-
By the way, is there any way to have these ticked as default when I add a new dataset?

Avatar
kevino

Community Member, 30 Posts

19 November 2009 at 7:31am

Well, as it turns out, a many many complex table field is perhaps not what I actually wanted.

The unit list with the many many relationship is the same per for all the properties, whereas I wanted to be able to make a unit list per property..

I did try to swap out the many_many portions of my code for has_many but that didn't actually work as I expected.

Is there a particular route I should be taking to get this to work?

PropertyPage.php

	static $has_many = array(
		'AvailableUnits' => 'UnitList'
	);
   
	function getCMSFields() {
	$fields = parent::getCMSFields();

		
	$Unitstablefield = new HasManyComplexTableField(
		$this,
			'AvailableUnits',
			'UnitList',
		array(
			'UnitNumber' => 'UnitNumber',
			'UnitType' => 'Unit Type',
			'UnitArea' => 'Unit Area',
			'UnitRent' => 'Unit Rent',
			'UnitLet' => 'Unit Let'
		),
			'getCMSFields_forPopup'
		);
	$Unitstablefield->setAddTitle( 'A Unit' );
	$Unitstablefield->setPageSize(100);
	$fields->addFieldToTab( 'Root.Content.Units', $Unitstablefield );

UnitList.php

<?php

class UnitList extends DataObject {

static $db = array(
'UnitNumber' => 'Text',
'UnitType' => 'Text',
'UnitArea' => 'Text',
'UnitRent' => 'Text',
'UnitLet' => 'Boolean' 
);

static $has_one = array(
'UnitSpec' => 'File',
'UnitLease' => 'File'
);

static $belongs_has_many = array(
'PropertyPages' => 'PropertyPage'
);

function getCMSFields_forPopup() {
return new FieldSet(
         new TextField( 'UnitNumber', 'UnitNumber' ),
         new TextField( 'UnitType', 'Unit Type' ),
         new TextField( 'UnitArea', 'Unit Area' ),
         new TextField( 'UnitRent', 'Unit Rent' ),
         new CheckboxField ('UnitLet', 'Tick if Let' ),
         new FileIFrameField( 'UnitSpec', 'Unit Specsheet' ),
         new FileIFrameField( 'UnitLease', 'Unit Lease Document' )
    );

}

}
?>

Any ideas?

Kevin.

Avatar
Carbon Crayon

Community Member, 598 Posts

19 November 2009 at 7:44am

Hi Kevino

Could you describe exactly what you want? Do the UnitList data objects need to be attached to more than one property page? If so then the ManyMany is teh correct way, you create your list per Property by checking the relevant ones for that page.....am I missing something?

Aram

Avatar
kevino

Community Member, 30 Posts

19 November 2009 at 11:15pm

Edited: 19/11/2009 11:17pm

Hi Aram,

Thanks for looking.

I want to have one set of units per property.

So I'd have

PropertyA with UnitA1 UnitA2 UnitA3 UnitA4 UnitA5 etc..
PropertyB with UnitB1 UnitB2 UnitB3 UnitB4 UnitB5 UnitB6 etc..
PropertyC with UnitC1 UnitC2 UnitC3 UnitC4 UnitC5 etc..

If that makes sense?

There would be potentially 200+ units, so want to be able to control each Properties unit list only within the preoperty page it belongs to.

Avatar
Carbon Crayon

Community Member, 598 Posts

20 November 2009 at 1:23am

ok, so actually all you need is a regular has many relationship.

Change your DataObject relationship to: $has_one=array('PropertyPage'=>'PropertyPage');

and your PropertyPage relationship to: $has_many=array('UnitLists' => 'UnitList');

then download the DataObjectManager mopdule (when you put it in your SilverStripe folder make sure the folder is called 'dataobject_manager' and use this code in your getCMSFields() function:

		$manager = new DataObjectManager(
			$this, // Controller
			'UnitLists', // Source name
			'UnitList', // Source class
                        array('UnitNumber' => 'UnitNumber', 'UnitType' => 'Unit Type', 'UnitArea' => 'Unit Area','UnitRent' => 'Unit Rent'), 
			'getCMSFields_forPopup'		
		);
		
		$fields->addFieldToTab("Root.Content.UnitLists", $manager);	

That should do it :)

Avatar
kevino

Community Member, 30 Posts

20 November 2009 at 11:55pm

Many thanks for your help with this Aram.

I've actually just used a normal ComplexTableField for now; but like the idea of using the DOM as it looks pretty good.

Avatar
Carbon Crayon

Community Member, 598 Posts

21 November 2009 at 3:08pm

Your most welcome :)

Yea the DOM is really fantastic, it introduces all of the functionality that the CTF should have, I'd reccomend giving it a go as soon as you get the chance.