Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Where to use DataObjectManager?

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 2143 Views
  • patte
    Avatar
    Community Member
    63 Posts

    Where to use DataObjectManager? Link to this post

    Hey guys,

    I am using DataObjectManager for my first project using dataobjects. Can someone please give a hint where/how to use it?

    I have two dataobjects 'CertificationBody' and 'Certificate' - a one to many relationship.

    My question is: where do i use DataObjectManager? Until now I dont have a new page type to put it in and I thought that those page types must be in relation with the dataobjects... is that right? Or can I build a new Page just for administration?

    Thanks much in advance!
    patte

  • UncleCheese
    Avatar
    4085 Posts

    Re: Where to use DataObjectManager? Link to this post

    It works almost exactly like a ComplexTableField, relating DataObjects to Page objects. If you have a DataObject -> DataObject relation, you might want to try it in ModelAdmin.

  • patte
    Avatar
    Community Member
    63 Posts

    Re: Where to use DataObjectManager? Link to this post

    Hi UncleCheese,

    thanks for your answer. Perhaps you can help me with some problems I have with my dataobjects? As I wrote these are my first steps with SilverStripe an dataobjects and I am stuck with some things... the tutorials didnt`t help unfortunately...

    IsccPage is my administration page for Certificate, CertificationBody and Region.

    A CertificationBody has Certificates - so a Certificate belongs to one CertificationBody. Both have a region, which should be selectable in any way from within DOM (CheckboxSetField or DropdownField?).

    class IsccPage extends Page
    {
       static $has_many = array (
          'Certificates' => 'Certificate',
          'CertificationBodies' => 'CertificationBody',
          'Regions' => 'Region'
       );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab("Root.Content.Certificates", new DataObjectManager(
       $this,
    'Certificates',
    'Certificate',
    array(
        'CertificateNumber' => 'Certificate Number',
        'DateOfIssue' => 'Date of Issue',
        'DateOfExpiration' => 'Date of Expiration',
        'CompanyCertified' => 'Company Name'
    ),
    'getCMSFields_forPopup'
       ));

    $fields->addFieldToTab("Root.Content.CertificationBodies", new DataObjectManager(
    $this,
    'CertificationBodies',
    'CertificationBody',
    array(
        'CompanyName' => 'Company Name',
        'ContactPerson' => 'Contact Person',
        'Telephone' => 'Telephone',
        'Email' => 'Email'
    ),
    'getCMSFields_forPopup'
    ));

       $fields->addFieldToTab("Root.Content.Regions", new DataObjectManager(
          $this,
          'Regions',
          'Region',
          array('Title' => 'Title'),
          'getCMSFields_forPopup'
       ));

       return $fields;
    }

    }

    class Certificate extends DataObject {
       
       static $db = array (
          'CertificateNumber' => 'Text',
          'DateOfIssue' => 'Date',
          'DateOfExpiration' => 'Date',
          'CompanyCertified' => 'Text',
          'LocationOfCompany' => 'Text',
          'Country' => 'Text'
       );
       
       static $has_one = array (
          'IsccPage' => 'IsccPage',
          'Region' => 'Region'
       );
       
       function getCMSFields_forPopup() {
       $fields = new FieldSet();
       $fields->push( new TextField('CertificateNumber') );
       $fields->push( new CalendarDateField('DateOfIssue') );
       $fields->push( new CalendarDateField('DateOfExpiration') );
       $fields->push( new TextField('CompanyCertified') );
       $fields->push( new TextField('LocationOfCompany') );
       $fields->push( new TextField('Country') );    
       
       $regionsList = DataObject::get('Region');
       $fields->push(new CheckboxSetField('Regions', '', $regionsList));    
       
       return $fields;
       }
    }

    class CertificationBody extends DataObject {
       
       static $db = array (
          'CompanyName' => 'Text',
          'FullAddress' => 'Text',
          'Country' => 'Text',
          'ContactPerson' => 'Text',
          'Telephone' => 'Text',
          'Telefax' => 'Text',
          'Email' => 'Text',
          'Website' => 'Text',
          'CertificationProducts' => 'Text',
          'Region' => 'Text',
          'CertifiedSince' => 'Date'
       );

       static $has_one = array(
          'IsccPage' => 'IsccPage'
       );
          
       static $has_many = array (
          'Certificates' => 'Certificate'
       );
       
       function getCMSFields_forPopup() {
       $fields = new FieldSet();
       
       $fields->push( new TextField('CompanyName') );
       $fields->push( new CalendarDateField('CertifiedSince') );
       $fields->push( new TextareaField('FullAddress') );
       
       $fields->push( new TextField('Country') );
       $fields->push( new TextField('ContactPerson') );
       $fields->push( new TextField('Telephone') );
       $fields->push( new TextField('Telefax') );
       $fields->push( new TextField('Email') );
       $fields->push( new TextField('Website') );
       $fields->push( new TextField('CertificationProducts') );
       $fields->push( new TextField('Region') );
          
       $certList = DataObject::get('Certificate')->toArray();
       $fields->push( new DropdownField(
       'CertificateID',
       'Certificates',
       $certList)
       );
          
          
       $regionList = DataObject::get('Region');
       $fields->push(new CheckboxSetField('Regions', '', $regionList));
              
       return $fields;
       }
    }

    class Region extends DataObject {
       

    static $db = array(
    'Title' => 'Varchar'
    );

    static $belongs_many_many = array(
    'IsccPages' => 'IsccPage',
    'Certificates' => 'Certificate',
    'CertificationBodies' => 'CertificationBody'
    );

       
    }

    puhh... i got the DOM working but..

    Adding a CertificationBody I can select a Region but the form is not saving the value. Editing the Object shows no selection of a region.

    Within CertificationBody I tried to use DropdownField for the Certificate but i shows only 'certificate' for any entry.

    How can I select a CertificationBody from within a Certificate?

    Whats wrong with my dataobjects? I am in a big muddle I think and it would very very great if someone can enlighten me ;-)

    Thanks so much in advance!

    Patte

  • UncleCheese
    Avatar
    4085 Posts

    Re: Where to use DataObjectManager? Link to this post

    How come region has belongs_many_many, but that relation is not reciprocated in any of those three classes listed? If an object has a belongs_many_many then the class in that relation has to have a many_many to that object. Further, you need to use ManyManyDataObjectManager to manage that relation in lieu of a normal DOM.

  • patte
    Avatar
    Community Member
    63 Posts

    Re: Where to use DataObjectManager? Link to this post

    Hi UncleCheese,

    ...thanks much. With belongs_many_many and many_many I got the regions checkboxes working ;-) Perhaps you have an idea why my DropdownField for Certificate is not saving its value?

    I started from the beginning using your TestimonialPage example just to be sure not to make a mistake

    class TestimonialPage extends Page
    {
       static $has_many = array (
          'Testimonials' => 'Testimonial'
       );
       
       public function getCMSFields()
       {
          $fields = parent::getCMSFields();
          $manager = new DataObjectManager(
             $this, // Controller
             'Testimonials', // Source name
             'Testimonial', // Source class
             array('Date' => 'Date', 'Author' => 'Author', 'Quote' => 'Quote'), // Headings
             'getCMSFields_forPopup' // Detail fields function or FieldSet
             // Filter clause
             // Sort clause
             // Join clause
          );
          
          
          $fields->addFieldToTab("Root.Content.Testimonials", $manager);
          
          $fields->addFieldToTab("Root.Content.Main",new DropdownField('Testimonials','Please choose one', Dataobject::get("Testimonial")->toDropdownMap("ID", "Title")));            
          
          return $fields;
       }

    }

    I added addFieldToTab to get the DropDownMap for the Testimonal - I can select one Testimonial but the value is not being saved.

    Any idea?

          
          

  • UncleCheese
    Avatar
    4085 Posts

    Re: Where to use DataObjectManager? Link to this post

    Why are you using a DropdownField to manage a has_many relationship? That makes no sense. A dropdown field can only select one value.

  • patte
    Avatar
    Community Member
    63 Posts

    Re: Where to use DataObjectManager? Link to this post

    Thank you for you patience UncleCheese,
    I just wanted to test the DropdownField...being totally confused with that dataobject relations.

    I have to do the following things - perhaps my whole approach is wrong?

    CertificationBody has many Certificates
    CertificationBody has one Region

    Certificate has one CertificationBody
    Certificate has one Region

    I would like to have a 'holder' for my dataobjects, call it IsccPage. In this page i want to use DOM.

    Within CertificationBody DOM I want to have a CheckBox to select several Certificates and a DropdownField to select one Region
    Within the Certificate DOM i want to have a DropdownField to select one Region and one CertificationBody

    ..

    This is possible isn`t it? Because my client wants to see a first version today I am getting nervous..... can you give me some more hints whats going wrong with my attempts?

    Thanks much

  • UncleCheese
    Avatar
    4085 Posts

    Re: Where to use DataObjectManager? Link to this post

    Yeah, of course..

    For CertificationBody, just add a CheckboxSetField('Certificates') to your popup fields. Also put a dropdown field there for RegionID.

    On Certificate, have a dropdown for CertificationBodyID (should be already set if you've assigned it via the checkboxes on CertificationBody), and a dropdown for RegionID.

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