Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » My images are shared amongst all my 'Galleries'.

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 722 Views
  • anebg
    Avatar
    Community Member
    8 Posts

    My images are shared amongst all my 'Galleries'. Link to this post

    Ok.. So I built the pagetype ProjectHOlder who is supposed to have many projects and under the Project Page a lot of images( different for each project).
    The problem is that when I go to the CMS it shows up the images from my slideshow on the homepage. I copied and pasted the code from my slideshow and renamed the classes to ProjectPage

    <?php

    // /mysite/code/GalleryPage.php

    class ProjectPage extends Page

    {

    static $has_many = array (

    'Images' => 'ImageResource'

    );

    public static $db = array(
       'YoutubeURL'=>'Text'

    );

    public static $has_one = array('Before'=>'Image', 'Design'=>'Image');

    public function getCMSFields()

    {

    $f = parent::getCMSFields();

    $manager = new ImageDataObjectManager(

    $this, // Controller

    'Images', // Source name

    'ImageResource', // Source class

    'Attachment', // File name on DataObject

    array(

    'Caption' => 'Caption',

    'Link' => 'Link'

    ), // Headings

    'getCMSFields_forPopup' // Detail fields

    // Filter clause

    // Sort clause

    // Join clause

    );
       $f->addFieldToTab('Root.Content.Main', new TextField($name='YoutubeURL',$title="YouTube Video ID: /watch?v=XXXXX&"), 'Content');
       $f->addFieldToTab("Root.Content.BeforeAndDesign", new ImageField('Before'));
       $f->addFieldToTab("Root.Content.BeforeAndDesign", new ImageField('Design'));

    $f->addFieldToTab("Root.Content.Gallery",$manager);
       

    return $f;

    }

    }

    class ProjectPage_Controller extends Page_Controller {

    }

    ProjectHolder.php

    <?php
    /**
    * Defines the ProjectHolder page type
    */
    class ProjectHolder extends Page {
    static $db = array(
    );
    static $has_one = array(
    );

    static $allowed_children = array('ProjectPage');
    }

    class ProjectHolder_Controller extends Page_Controller {

    }

    ?>


    ImageResource.php

    <?php

    class ImageResource extends DataObject

    {

    static $db = array (

    'Caption' => 'Text',

          'Link' => 'Text'

    );

    static $has_one = array (

    'Attachment' => 'Image',

    'GalleryPage' => 'GalleryPage'
    /* This is where i think i should put something, gallerypage is my slideshow-- i need project page */
    );

    public function getCMSFields_forPopup()

    {

    return new FieldSet(

    new TextField('Caption'),

    new TextField('Link'),

    new FileIFrameField('Attachment')

    );

    }

    }

    I am assuming it has something to do with the has one has many so it can link the attachments to just one gallery, I just don't know it.
    Help Please

  • UncleCheese
    Avatar
    4085 Posts

    Re: My images are shared amongst all my 'Galleries'. Link to this post

    Shouldn't that be a $has_one ProjectPage? What is GalleryPage?

    --------------------
    SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

  • anebg
    Avatar
    Community Member
    8 Posts

    Re: My images are shared amongst all my 'Galleries'. Link to this post

    GalleryPage is the other gallery I have on my site. Its a slideshow manager.

    class GalleryPage extends Page

    {

    static $has_many = array (

    'Images' => 'ImageResource'

    );

    public static $db = array(

    );

    public static $has_one = array(

    );

    public function getCMSFields()

    {

    $f = parent::getCMSFields();

    $manager = new ImageDataObjectManager(

    $this, // Controller

    'Images', // Source name

    'ImageResource', // Source class

    'Attachment', // File name on DataObject

    array(

    'Caption' => 'Caption',

    'Link' => 'Link'

    ), // Headings

    'getCMSFields_forPopup' // Detail fields

    // Filter clause

    // Sort clause

    // Join clause

    );

    $f->addFieldToTab("Root.Content.Gallery",$manager);

    return $f;

    }

    }

    class GalleryPage_Controller extends Page_Controller {

    }

  • s!m
    Avatar
    Community Member
    9 Posts

    Re: My images are shared amongst all my 'Galleries'. Link to this post

    Hi,

    I once had the same problem and solved it with a custom filter and a new database-entry in the class that extends Dataobject, this would be ImageResource in your case.
    I described the steps here: http://www.silverstripe.org/dataobjectmanager-module-forum/show/14434#post293616

    I think in your case, you just have to use the filter on your ImageDataObjectManger and you should be fine, the additional steps with onAfterWrite() won't be required, I think...

    Best regards,
    s!m

  • anebg
    Avatar
    Community Member
    8 Posts

    Re: My images are shared amongst all my 'Galleries'. Link to this post

    I had to add another resource.. And it worked afterwards... Thanks..

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