openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

ImageComponent.class.php (2552B)


      1 <?php
      2 
      3 namespace template_engine\components\html\component_image;
      4 
      5 use cms\base\Startup;
      6 use template_engine\components\html\Component;
      7 use template_engine\element\CMSElement;
      8 
      9 class ImageComponent extends Component
     10 {
     11 	public $class;
     12 	public $menu;
     13 	public $action;
     14 	public $method;
     15 	public $config;
     16 	public $file;
     17 	public $url;
     18 	public $icon;
     19 	public $type;
     20 	public $elementtype;
     21 	public $fileext;
     22 	public $tree;
     23 	public $notice;
     24 	public $size;
     25 	public $title;
     26 	public $symbol;
     27 	public $permission;
     28 
     29 	public function createElement()
     30 	{
     31         $styleClasses = [];
     32         $tagName = 'img';
     33         $file = '';
     34 
     35 		if	( $this->symbol )
     36 		{
     37 		    $tagName = 'i';
     38 			$styleClasses = ['image-icon','image-icon--'.$this->symbol];
     39 		}
     40 		elseif	( $this->menu )
     41 		{
     42 		    $tagName = 'i';
     43 			$styleClasses = ['image-icon','image-icon--menu-'.$this->menu];
     44 		}
     45 		elseif	( $this->elementtype )
     46 		{
     47             $tagName = 'i';
     48 			$styleClasses = ['image-icon','image-icon--action-el_'.$this->elementtype];
     49 		}
     50 		elseif	( $this->action )
     51 		{
     52             $tagName = 'i';
     53 			$styleClasses = ['image-icon','image-icon--action-'.$this->action];
     54 		}
     55 		elseif	( $this->permission )
     56 		{
     57             $tagName = 'i';
     58 			$styleClasses = ['image-icon','image-icon--permission-'.$this->permission];
     59 		}
     60 		elseif	( $this->method )
     61 		{
     62             $tagName = 'i';
     63 			$styleClasses = ['image-icon','image-icon--method-'.$this->method];
     64 		}
     65 		elseif	( $this->type )
     66 		{
     67 			$file = Startup::THEMES_DIR.'default/images/icon_'.$this->type.Startup::IMG_ICON_EXT;
     68 		}
     69 		elseif	( $this->icon )
     70 		{
     71 			$file = Startup::THEMES_DIR.'default/images/icon/'.$this->icon.Startup::IMG_ICON_EXT;
     72 		}
     73 		elseif	( $this->notice )
     74 		{
     75 			$file = Startup::THEMES_DIR.'default/images/notice_'.$this->notice.Startup::IMG_ICON_EXT;
     76 		}
     77 		elseif	( $this->tree )
     78 		{
     79 			$file = Startup::THEMES_DIR.'default/images/tree_'.$this->tree.Startup::IMG_EXT;
     80 		}
     81 		elseif	( $this->url )
     82 		{
     83 			$file = $this->url;
     84 		}
     85 		elseif	( $this->fileext )
     86 		{
     87 			$file = Startup::THEMES_DIR.'default/images/icon/'.$this->fileext;
     88 		}
     89 		elseif	( $this->file )
     90 		{
     91 			$file = Startup::THEMES_DIR.'default/images/icon/'.$this->file.Startup::IMG_ICON_EXT;
     92 		}
     93 
     94 		if	( $this->class )
     95         {
     96             $styleClasses = array_merge($styleClasses, Component::splitByComma( $this->class ));
     97         }
     98 
     99 
    100 		$image = new CMSElement($tagName );
    101 
    102 	    $image->addStyleClass($styleClasses);
    103 
    104 		if($this->title)
    105 			$image->addAttribute('title',$this->title);
    106 
    107 		if   ( $file)
    108 			$image->addAttribute('src',$file);
    109 
    110 		return $image;
    111 	}
    112 }