Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » File Upload Field in ManyManyComplexTableField popup

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

Page: 1 2 3
Go to End
Author Topic: 3545 Views
  • kevino
    Avatar
    Community Member
    30 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    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.

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    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?

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    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.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    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

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    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.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    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

  • kevino
    Avatar
    Community Member
    30 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    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.

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: File Upload Field in ManyManyComplexTableField popup Link to this post

    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.

    3545 Views
Page: 1 2 3
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.