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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

My images are shared amongst all my 'Galleries'.


Go to End


5 Posts   1500 Views

Avatar
anebg

Community Member, 8 Posts

3 December 2010 at 7:09pm

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 :)

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 December 2010 at 5:03am

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

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

Avatar
anebg

Community Member, 8 Posts

4 December 2010 at 5:10am

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 {

}

Avatar
s!m

Community Member, 9 Posts

4 December 2010 at 11:37pm

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

Avatar
anebg

Community Member, 8 Posts

5 December 2010 at 9:23pm

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