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

Help needed with DataObjectDecorator Code


Reply


6 Posts   905 Views

Avatar
Webdoc

Community Member, 334 Posts

19 September 2011 at 1:10pm

How to set Slider Width And Height in line of code
swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "Slider Width here", "Slider Height here", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes);

The code is below

<?php

class PMDecorator extends DataObjectDecorator{

   function extraStatics() {
      return array(
      'db' => array(
            'SliderWidth' => 'Varchar',
            'SliderHeight' => 'Varchar'
         ),
         'defaults' => array(
            'SliderWidth' => '760',
            'SliderHeight' => '300'      
         ),
         'has_many' => array(
            'PMItems' => 'PMItem',
         )
      );
   }

   public function updateCMSFields(FieldSet &$fields) {
      $Banners = new DataObjectManager(
            $this->owner,
            'PMItems',
            'PMItem',
            array(
               "Thumbnail" => "Thumbnail",
               'AlternateText' =>'AlternateText'
            ),
            'getCMSFields_forPopup'
      );
      $fields->addFieldToTab( 'Root.Showcase', $Banners );         
      $fields->addFieldsToTab("Root.PiecemakerSettings",array(
         new TextField('SliderWidth',_t('PieceMaker.IMAGEWIDTH',"Image Width")),
         new TextField('SliderHeight',_t('PieceMaker.IMAGEHEIGHT',"Image Height"))
      ));      
   }         
}

class PMDecorator_Controller extends SiteTreeDecorator {

   public function contentcontrollerInit($controller) {
      Requirements::javascript("PieceMaker/javascript/swfaddress.js");
      Requirements::javascript("PieceMaker/javascript/swfobject.js");
      
      $xmllink = $controller->Link('sliderconfig');
      Requirements::customScript('
      
    var attributes = {id:"PieceMaker-container"};

       var flashvars = {};
    flashvars.cssSource = "PieceMaker/css/piecemaker.css";
    flashvars.xmlSource = "'.$xmllink.'";

    var params = {};
    params.play = "true";
    params.menu = "false";
    params.scale = "showall";
    params.wmode = "transparent";
    params.allowfullscreen = "true";
    params.allowscriptaccess = "always";
    params.allownetworking = "all";

    swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "Help-needed", "Help-needed", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes);
      
      ');
   }   
}

class PMDecorator_Extension extends Extension{
   public static $allowed_actions = array(
      'sliderconfig'
   );
   
   function sliderconfig(){
      ContentNegotiator::disable();
      $configBody = $this->owner->renderWith('Config');
      $rsp = new SS_HTTPResponse($configBody,200,'OK');
      $rsp->addHeader('Content-Type', 'application/xml; charset="utf-8"');      
      return $rsp;      
   }
}

class PM_ImageDecorator extends DataObjectDecorator {
   public function FullImageURL() {
      $url = $this->owner->getRelativePath();
      return Director::absoluteURL($url);   
   }
}

Avatar
UncleCheese

Forum Moderator, 4096 Posts

19 September 2011 at 1:57pm

Why not just $SliderWidth and $SliderHeight? I'm not sure I understand the problem.

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

Avatar
Webdoc

Community Member, 334 Posts

19 September 2011 at 6:47pm

The Part where it writes the
swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "Slider Width here", "Slider Height here", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes);

is inside the code not in template

tried:
swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "$SliderWidth", "$SliderHeight", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes);

But it didn work it passed the size of flash object as:
<object id="PieceMaker-container" width="$SliderWidth" height="$SliderHeight" type="application/x-shockwave-flash" data="PieceMaker/flash/piecemaker.swf" style="visibility: visible;">

The code part i modified was The module Piecemaker because there wasnt plase in admin where u can edit how much is the slider width and height

Avatar
UncleCheese

Forum Moderator, 4096 Posts

20 September 2011 at 8:19am

Use Requirements::customScript() and place the variables in there.

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

Avatar
Webdoc

Community Member, 334 Posts

20 September 2011 at 8:21am

Edited: 20/09/2011 8:25am

sorry im a bit newbie can u make an example or give some tutorial link how to do it
also in pmitem part is the AlternateText thing in template i use the
<% control PMItems %>
         <% control PMItemFile %>
                  $Top.AlternateText
         <% end_control %>
<% end_control %>

but it doesnt show up

Avatar
UncleCheese

Forum Moderator, 4096 Posts

22 September 2011 at 5:36am

Instead of using an external JS file, just use a custom script.

Requirements::customScript('swfobject.embedSWF("PieceMaker/flash/piecemaker.swf", "PieceMaker-container", "'.$this->SliderWidth.'", "'.$this->SliderHeight.'", "10", "PieceMaker/flash/expressInstall.swf", flashvars, params, attributes)');