示例#1
0
 public function renderSlider()
 {
     if (!isset($this->sliderName)) {
         throw new InvalidConfigException("The slider name option is required.");
     }
     $slider = SliderService::findByName($this->sliderName);
     $items = [];
     if (!isset($slider)) {
         return "<div>Slider having name set to {$this->sliderName} does not exist. Please create it via admin.</div>";
     }
     // Views Path
     $slidePath = $this->template . '/slide';
     // Generate Slides Html
     $slides = $slider->slides;
     foreach ($slides as $slide) {
         $items[] = $this->render($slidePath, ['fxOptions' => $this->fxOptions, 'slide' => $slide, 'slideTexture' => $this->slideTexture, 'genericContent' => $this->genericContent]);
     }
     // TODO: Configure from database settings
     // Register JS
     $sliderOptions = json_encode($this->fxOptions);
     $sliderJs = "jQuery( '#" . $this->options['id'] . "' ).foxslider( {$sliderOptions} );";
     $this->getView()->registerJs($sliderJs, View::POS_READY);
     // Return HTML
     return Html::tag('div', implode("\n", $items), $this->options);
 }
示例#2
0
 public static function update($slide, $slideImage = null)
 {
     // Find User and Slider
     $slider = SliderService::findById($slide->sliderId);
     // Find existing Slide
     $slideToUpdate = self::findById($slide->id);
     // Copy Attributes
     $slideToUpdate->copyForUpdateFrom($slide, ['imageId', 'name', 'description', 'content', 'url']);
     // Save Slide Image to Slide Dimensions
     if (isset($slideImage)) {
         FileService::saveImage($slideImage, ['model' => $slideToUpdate, 'attribute' => 'imageId', 'width' => $slider->slideWidth, 'height' => $slider->slideHeight]);
     }
     $slideToUpdate->update();
     return $slideToUpdate;
 }