Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
Go to End
Author Topic: 60268 Views
  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Preview: DataObjectManager module Link to this post

    @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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    @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.

  • schellmax
    Avatar
    Community Member
    126 Posts

    Re: Preview: DataObjectManager module Link to this post

    @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.

  • pali
    Avatar
    Community Member
    33 Posts

    Re: Preview: DataObjectManager module Link to this post

    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

  • Johnny
    Avatar
    Community Member
    34 Posts

    Re: Preview: DataObjectManager module Link to this post

    @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

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Preview: DataObjectManager module Link to this post

    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.....

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    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!

  • Johnny
    Avatar
    Community Member
    34 Posts

    Re: Preview: DataObjectManager module Link to this post

    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

    60268 Views
Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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.