Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » ImageDataObjectManager in SiteConfig

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: 732 Views
  • arnhoe
    Avatar
    Community Member
    6 Posts

    ImageDataObjectManager in SiteConfig Link to this post

    Hello,

    I have managed to get myself a many_many relationship in the siteconfig, my goal is that, the user is able to upload a image and select one or more items from the menu.

    Now, I would like to filter in the CMS on a menu item, and then it will show the images this menu item has. But I am not sure if I created my pages in the way it should be. Is there anyone that would like to check my pages?

    <?php
    class BannerImages extends DataObject
    {
       static $db = array('Title' => 'Text');

       static $has_one = array(
          'SiteConfig' => 'SiteConfig',
          'myImage' => 'BetterImage'
       );

       static $many_many = array('Images' => 'SiteTree');

       public function getCMSFields_forPopup()
       {
          $images = DataObject::get('SiteTree', 'ShowInMenus = 1');
          return new FieldSet(new TextField('Title'), new FileIFrameField('myImage'), new CheckboxSetField('Images', 'Images', $images));
       }

    }

    <?php

    class CustomSiteConfig extends DataObjectDecorator
    {

       function extraStatics()
       {
          return array('has_many' => array('Images' => 'BannerImages'));
       }

       public function updateCMSFields(FieldSet &$fields)
       {

          $manager = new ImageDataObjectManager($this -> owner, 'Images', 'BannerImages', 'myImage', array('Title' => 'Title'), 'getCMSFields_forPopup');

          $manager -> setParentClass("SiteConfig");
          $manager -> setPluralTitle('Images');
          $manager -> setRelationAutoSetting(false);
          $manager -> setFilter('ID', // Name of field to filter
          'Filter by Page', // Label for filter
          Dataobject::get("SiteTree") -> toDropdownMap("ID", "Title") // Map for filter (could be $dataObject->toDropdownMap(), e.g.)
          );

          $fields -> addFieldToTab("Root.Images", $manager);

       }

    }

    And I am calling my code in the following way, I am really certain that this isnt the right way, but I tried DataObject::get, but I cannot call the CurrentPageID to equal with the SiteTreeID.

    public function BannerImages()
       {
          // build a new sql query
          $sqlQuery = new SQLQuery();
          $sqlQuery -> select = array('a.SiteTreeID AS sitetreeid, a.BannerImagesID as bannerimagesid, b.myImageID as Image, c.Filename as ImageURL');
          $sqlQuery -> from = array("`bannerimages_images` a LEFT JOIN `bannerimages` b on a.BannerImagesID = b.ID LEFT JOIN `file` c on b.myImageID = c.ID");
          $sqlQuery -> where = array("SiteTreeID = " . $this -> ID . "");
          $sqlQuery -> distinct = true;
          $sqlQuery -> orderby = "RAND()";
          $sqlQuery -> limit = "1";

          $rawSQL = $sqlQuery -> sql();
          $result = $sqlQuery -> execute();

          // create a new data object set
          $myDataObjectSet = new DataObjectSet();

          // push our result into the data object set
          foreach ($result as $row) {
             $myDataObjectSet -> push(new ArrayData($row));
          }

          return $myDataObjectSet;

       }

    I hope you guys can help me, so I will be able to help any other people in the future with this matter.

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