bundles/FoxHabbit/BasisBundle/Model/DataObject/CssBackground.php line 43

Open in your IDE?
  1. <?php
  2. namespace FoxHabbit\BasisBundle\Model\DataObject;
  3. class CssBackground extends \Pimcore\Model\DataObject\Concrete {
  4.     private $disabled false;
  5.     private $thumbnail null;
  6.     public function setDisabled$disabled) {
  7.         $this->disabled = ! ! $disabled;
  8.     }
  9.     public function setThumbnail$thumbnail) {
  10.         if( is_array$thumbnail) && count$thumbnail)) {
  11.             $this->thumbnail $thumbnail;
  12.         } else if( is_string$thumbnail) || $thumbnail === null || $thumbnail === false) {
  13.             $this->thumbnail $thumbnail;
  14.         }
  15.     }
  16.     public function getClassString$addClass = array()) {
  17.         if( is_string$addClass)) {
  18.             $addClass explode(' '$addClass);
  19.         } else if( ! is_array$addClass)) {
  20.             $addClass = array();
  21.         }
  22.         if( ! $this->disabled) {
  23.             return implode' 'array_merge$addClassexplode' '$this->getBgClass().' '.$this->getContentClass())));
  24.         } else {
  25.             return implode' 'array_merge$addClassexplode' '$this->getContentClass())));
  26.         }
  27.     }
  28.     public function getBgClassString$addClass = array()) {
  29.         if( is_string$addClass)) {
  30.             $addClass explode(' '$addClass);
  31.         } else if( ! is_array$addClass)) {
  32.             $addClass = array();
  33.         }
  34.         if( ! $this->disabled) {
  35.             return implode' 'array_merge$addClassexplode' '$this->getBgClass())));
  36.         } else {
  37.             return implode' '$addClass);
  38.         }
  39.     }
  40.     public function getContentClassString$addClass = array()) {
  41.         if( is_string$addClass)) {
  42.             $addClass explode(' '$addClass);
  43.         } else if( ! is_array$addClass)) {
  44.             $addClass = array();
  45.         }
  46.         return implode' 'array_merge$addClassexplode' '$this->getContentClass())));
  47.     }
  48.     private function getImagePath$addImage$generateThumbnail=true) {
  49.         $image null;
  50.         if( $addImage instanceof \Pimcore\Model\DataObject\Data\Hotspotimage) {
  51.             if( $generateThumbnail && is_string$this->thumbnail)) {
  52.                 $image $addImage->getThumbnail$this->thumbnail);
  53.             } else {
  54.                 $image $addImage->getThumbnail();
  55.             }
  56.         } else if( $addImage instanceof \Pimcore\Model\Asset\Image\Thumbnail) {
  57.             if( $addImage->getPath()) {
  58.                 $image $addImage->getPath();
  59.             }
  60.         } else if( $addImage instanceof \Pimcore\Model\Asset\Image) {
  61.             if( $addImage->getFullPath()) {
  62.                 if( $generateThumbnail && is_string$this->thumbnail) && ! $addImage->isAnimated()) {
  63.                     $image $this->getImagePath$addImage->getThumbnail$this->thumbnail), false);
  64.                 } else {
  65.                     $image $addImage->getFullPath();
  66.                 }
  67.             }
  68.         } else if( $addImage instanceof \Pimcore\Model\Document\Editable\Image) {
  69.             if( $addImage->getSrc()) {
  70.                 if( $generateThumbnail && $this->thumbnail) {
  71.                     // TODO: GENERATE THUMBNAIL
  72.                     $image $addImage->getSrc();
  73.                 } else {
  74.                     $image $addImage->getSrc();
  75.                 }
  76.             }
  77.         } else if( $addImage instanceof \Pimcore\Model\Document\Editable\Href) {
  78.             if( $addImage->getFullPath()) {
  79.                 if( $generateThumbnail && $this->thumbnail) {
  80.                     // TODO: GENERATE THUMBNAIL
  81.                     $image $this->getImagePath$addImage->getElement(), true);
  82.                 } else {
  83.                     $image $addImage->getFullPath();
  84.                 }
  85.             }
  86.         } else {
  87.             //$image = 'addImage class_not_handled:'.get_class( $addImage);
  88.         }
  89.         return $image;
  90.     }
  91.     public function getStyleString$addImage null$addYoutube null$addStyles = array()) {
  92.         if( $this->disabled) {
  93.             return '';
  94.         }
  95.         $prefixStyleProperties = array( 'background-size');
  96.         $prefixStyleVendors = array( '-webkit-''-moz-''-o-');
  97.         $style = array();
  98.         if( is_array$addStyles)) {
  99.             foreach( $addStyles as $k=>$v) {
  100.                 $style[$k] = $v;
  101.             }
  102.         }
  103.         if( $color $this->getColor()) {
  104.             $style['background-color'] = $color;
  105.         }
  106.         $image null;
  107.         if( $this->getAllowImage() && is_object$addImage)) {
  108.             $image $this->getImagePath$addImage$this->thumbnail);
  109.         } else if( is_object$addImage)) {
  110.             //$image = 'CAN NOT ADD IMAGE';
  111.         } else if( $addImage) {
  112.             //$image = 'Image is not an object';
  113.         }
  114.         if( ! $image && is_object$this->getImage())) {
  115.             $image $this->getImagePath$this->getImage(), $this->thumbnail);
  116.         } else if( ! $image) {
  117.             //$image = 'NO IMAGE';
  118.         }
  119.         if( $image) {
  120.             $style['background-image'] = 'url('.$image.')';
  121.             // First set default styles for the background image
  122.             $style['background-repeat'] = 'no-repeat';
  123.             $style['background-position'] = 'center center';
  124.             //$style['-webkit-background-size'] = 'cover';
  125.             //$style['-moz-background-size'] = 'cover';
  126.             //$style['-o-background-size'] = 'cover';
  127.             $style['background-size'] = 'cover';
  128.             // Set styles defind in the object
  129.             if( strlen$this->getBgSize()) && $this->getBgSize() != '') {
  130.                 //$style['-webkit-background-size'] = $this->getBgSize();
  131.                 //$style['-moz-background-size'] = $this->getBgSize();
  132.                 //$style['-o-background-size'] = $this->getBgSize();
  133.                 $style['background-size'] = $this->getBgSize();
  134.             }
  135.             if( strlen$this->getBgPosition()) && $this->getBgPosition() != '') {
  136.                 $style['background-position'] = $this->getBgPosition();
  137.             }
  138.             if( strlen$this->getBgRepeat()) && $this->getBgRepeat() != '') {
  139.                 $style['background-repeat'] = $this->getBgRepeat();
  140.             }
  141.             if( strlen$this->getBgAttachment()) && $this->getBgAttachment() != '') {
  142.                 $style['background-attachment'] = $this->getBgAttachment();
  143.             }
  144.         }
  145.         foreach( $this->getProperties() as $prop) {
  146.             if( $prop->getType() === 'text') {
  147.                 $style[$prop->getName()] = $prop->getData();
  148.             }
  149.         }
  150.         $ret '';
  151.         foreach( $style as $k=>$v) {
  152.             if( in_array$k$prefixStyleProperties)) {
  153.                 foreach($prefixStyleVendors as $prefix) {
  154.                     if( ! array_key_exists$prefix.$k$style)) {
  155.                         $ret .= $prefix.$k.':'.$v.';';
  156.                     }
  157.                 }
  158.             }
  159.             $ret .= $k.':'.$v.';';
  160.         }
  161.         return $ret;
  162.     }
  163.     public function canAddImage() {
  164.         return $this->getAllowImage();
  165.     }
  166.     public function canAddYouTube() {
  167.         return $this->getAllowYoutube();
  168.     }
  169. }