Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » ideas for a simple page type "slideshow"

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 538 Views
  • lozhowlett
    Avatar
    Community Member
    140 Posts

    ideas for a simple page type "slideshow" Link to this post

    Hi everyone,

    i just want a bit of pointing in the right direction. I have a site that is selling golfing breaks. One of the pages is a hotel view page. On this hotel page I need to be able to...

    1. Add a content block (fine - part of the normal Page type)
    2. Add images to a slideshow using a simple upload form (in the CMS)
    3. Add related hotels (i.e. hotels near by) by selecting what is essentially another page with the same type.
    4. Add a thumbnail for the hotel (so it will appear in the related hotels section) with a tiny abstract (20 words or something)

    This is what I think I need to do...

    Extend the page controller
    Use uploadify

    Any ideas would be great! thanks,

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: ideas for a simple page type "slideshow" Link to this post

    Hi,

    I'm no PHP expert, but i would do something like the following.

    I would create a new page type HotelViewPage

    1. Use Content as you say
    2. Create a Dataobject with a has many relation for the images / content in the slideshow (http://doc.silverstripe.org/sapphire/en/tutorials/5-dataobject-relationship-management the student mentor section)
    3. Add a many many relation for the related hotels (same URL as above but the section "Project - Module relation")
    4. Just add an image field to the related hotels Page / Dataobject

    Hope this helps

    BTW: No need for Uploadify if using Dataobjects instead.

    --

    Thomas B. Nielsen
    webdesign esbjerg

  • lozhowlett
    Avatar
    Community Member
    140 Posts

    Re: ideas for a simple page type "slideshow" Link to this post

    Thanks... i have come up with this code...

    Hotel.php

    <?php
    class Hotel extends DataObject
    {
       static $db = array (
          'Name' => 'Text',
          'LocationCity' => 'Text',
          'Lat' => 'Text',
          'Long' => 'Text'
       );

       static $has_many = array(
    'HotelImages' => 'HotelImages'
    );

       function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Name' ) );
    $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'LocationCity' ) );
    $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Lat' ) );
       $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Long' ) );
          return $fields;
    }
    }
    class Hotel_Controller extends Page_Controller {}

    HotelImages.php

    <?php
    class HotelImage extends DataObject {

       static $db = array(
    'Alt' => 'Text',
    );
       
       static $has_one = array (
          'Attachment' => 'File',
          'MyHotelImage' => 'Hotel'
       );

    public function getCMSFields_forPopup()
       {
          return new FieldSet(
             new TextField('Alt'),
             new FileIFrameField('Attachment')
          );
       }
    }

    HotelPage.php

    <?php
    class HotelPage extends Page
    {
       static $has_many = array (
          'Hotels' => 'Hotel'
       );

       public function getCMSFields()
       {
          $f = parent::getCMSFields();
          $manager = new ImageDataObjectManager(
             $this, // Controller
             'Hotels', // Source name
             'Hotel', // Source class
             'Attachment', // File name on DataObject
             array(
                'Alt' => 'Alt'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
    $f->addFieldToTab("Root.Content.HotelImages",$manager);
    return $f;
       }
    }

    Which is a mash of code found on your mentioned tut, plus http://doc.silverstripe.org/old/modules:dataobjectmanager

    All that happens when I try to add the page type is I get an error "There has been an error"

    I am unsure where I went wrong.

    In previous code I got a list of images added to the page fine, but I wanted to get the relationship right so I could extend with multiple tabs, i.e. one for images, then one for related other hotels.

    Any help would be great!

    thanks

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: ideas for a simple page type "slideshow" Link to this post

    You Hotel class is extending Dataobject, but you also have
    class Hotel_Controller extends Page_Controller {}
    not sure if you can do that.

    I would make the hotels pages, as i dont think you can manage a many many relation in a Dataobject in the CMS.

    Enable debugging to get some more usefull error messages, add the following to mysite/_config.php:
    // Debug mode - remember to set to live before going live!
    Director::set_environment_type( 'dev' );

  • lozhowlett
    Avatar
    Community Member
    140 Posts

    Re: ideas for a simple page type "slideshow" Link to this post

    great thanks... getting somewhere!

    now with the related hotels... this is where I am confused, as it has a many_many relationship with itself? I.e. a hotel can have many related hotels?

    static $many_many = array(
    'Hotels' => 'Hotel'
    );

    is that right?

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: ideas for a simple page type "slideshow" Link to this post

    Sorry, i think i will need to see the relevant code now: post to http://www.sspaste.com/ or somewhere.

    The tutorial should explain how this is done - not sure i can do a better job

  • lozhowlett
    Avatar
    Community Member
    140 Posts

    Re: ideas for a simple page type "slideshow" Link to this post

    Hi

    i went with a bit of a work around...

    <?php
    class ResourcePage extends Page
    {
       static $db = array(
    'HotelName' => 'Text',
    'Lat' => 'Text',
    'Long' => 'Text'
    );
       
       static $has_many = array (
          'Resources' => 'Resource'
       );
       
       public static $has_one = array(
          'RelatedLink1' => 'SiteTree',
          'RelatedLink2' => 'SiteTree',
          'RelatedLink3' => 'SiteTree',
          'HotelThumb' => 'File'
       );
       
       public function getCMSFields()
       {
          $fields = parent::getCMSFields();
          $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'HotelName' ) );
    $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Lat' ) );
    $fields->addFieldToTab( 'Root.Content.Main', new TextField( 'Long' ) );
          $fields->addFieldToTab( 'Root.Content.Main', new FileIFrameField( 'HotelThumb' ) );
          
          $treedropdownfield1 = new TreeDropdownField("RelatedLink1ID", "Choose a hotel that wish to link to:", "SiteTree");
          $treedropdownfield2 = new TreeDropdownField("RelatedLink2ID", "Choose a hotel that wish to link to:", "SiteTree");
          $treedropdownfield3 = new TreeDropdownField("RelatedLink3ID", "Choose a hotel that wish to link to:", "SiteTree");
          
          $fields->addFieldToTab("Root.Content.RelatedHotels", $treedropdownfield1);
          $fields->addFieldToTab("Root.Content.RelatedHotels", $treedropdownfield2);
          $fields->addFieldToTab("Root.Content.RelatedHotels", $treedropdownfield3);
          
          
          $manager = new ImageDataObjectManager(
             $this, // Controller
             'Resources', // Source name
             'Resource', // Source class
             'Attachment', // File name on DataObject
             array(
                'Description' => 'Description'
             ), // Headings
             'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
             // Filter clause
             // Sort clause
             // Join clause
          );
          $fields->addFieldToTab("Root.Content.Hotel Images",$manager);
          return $fields;
       }
    }

    seems to work well!

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