Jump to:

7921 Posts in 1359 Topics by 933 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Go to End
Author Topic: 54681 Views
  • 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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Preview: DataObjectManager module Link to this post

    Thanks, Johnny!

    FYI, the scenario you're describing only happens with a HasMany or ManyMany ComplexTableField (or a DataObjectManager, for that matter). It's designed to give the user the ability to syndicate content to an unlimited number of areas on the site without having to duplicate anything. We use it all the time for sidebar items, for instance. On a given page, one can choose from the world of all sidebar content which ones will display.

    For most cases, though, a plain CTF or DOM does fine.

    But let us never speak of ComplexTableFields again!

  • NickJacobs
    Avatar
    Community Member
    144 Posts

    Re: Preview: DataObjectManager module Link to this post

    @aram, unclecheese
    yep, me too, I've found all sorts of uses for DataObjectManager, and it seems to find it's way into every project in some form or other. I'll certainly participate in the forum 'petition'

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