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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ImageDataObjectManager


Go to End
Reply


10 Posts   1641 Views

Avatar
yug

Community Member, 17 Posts

22 February 2011 at 6:43pm

Hi everyone

So i am trying to set up the ability to manage Banners. I need the ability for different pages to have different banners and in different orders. It would be nice so that when i add a Banner for a certain page, this banner is also automatically available for another page type. So my idea is to loop through a folder in assets, and link every image to that page.

I have created a BannerImage class and currently have it working so that when i upload an image, other pages can see this image. However if i rearrange this image on one particular page, it changes in all the other pages

Can anyone help please?

Avatar
UncleCheese

4085 Posts

23 February 2011 at 10:52am

Sounds like you want a ManyManyFileDataObjectManager? That will allow you to upload banners from every page, and choose which banners you want, new or existing, to appear on any given page.

Avatar
yug

Community Member, 17 Posts

23 February 2011 at 12:05pm

Ok so i think i have this set up.....so when i add an image, i can see this image on all pages. But if i change the order of the images on one page, it changes the order on every other page

Can you please help me in setting this up properly

Avatar
UncleCheese

4085 Posts

23 February 2011 at 12:38pm

Yeah, I think somewhere in this forum you'll see a write up on SortableDataObject::add_sortable_many_many_relation();.. I think it's in a sticky.

Avatar
yug

Community Member, 17 Posts

23 February 2011 at 1:31pm

I cant seem to find anything and what is a sticky

Avatar
UncleCheese

4085 Posts

23 February 2011 at 2:44pm

Try this http://silverstripe.org/dataobjectmanager-module-forum/show/7323?start=16

Avatar
yug

Community Member, 17 Posts

23 February 2011 at 4:30pm

Can you see where i am going wrong

BannerImage.php
-------------------------------------------------------------------------------------

<?php

class BannerImage extends DataObject {
   
    static $db = array(
          'Title' => 'Text',
       'URL' => 'Text'
    );
   
      static $has_one = array(
       'BannerImage' => 'Image'
    );
   
      static $belongs_many_many = array(
       'Pages' => 'Page'
    );
   
    public function getCMSFields_forPopup()
    {
          return new FieldSet(
               new TextField('URL'),
               new FileIFrameField('BannerImage')
            );
    }
}

?>

Page.php
-----------------------------------------------------

<?php
class Page extends SiteTree {

   public static $db = array(
   );

   public static $has_one = array(
   );
   
   static $many_many = array(
      "BannerImages" => "BannerImage"
   );

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

   $idom = new ManyManyFileDataObjectManager (
    $this,
    'BannerImages',
    'BannerImage',
    'BannerImage',

    array(
    'URL' => 'URL'
    ),
    'getCMSFields_forPopup'
   );

$idom->setUploadFolder("BannerImages");

$fields->addFieldToTab("Root.Content.Image", $idom);
   
return $fields;
}

_config.php
-----------------------------------------------------

And i added this to the config file

SortableDataObject::add_sortable_many_many_relation('Page', 'BannerImage');

Avatar
UncleCheese

4085 Posts

23 February 2011 at 4:44pm

I think the second argument is the relation name..

SortableDataObject::add_sortable_many_many_relation('Page', 'BannerImages');

Go to Top