| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Ajax\semantic\html\base; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Ajax\common\html\HtmlDoubleElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Ajax\JsUtils; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Ajax\semantic\html\content\InternalPopup; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Phalcon\Mvc\View; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Ajax\semantic\html\base\traits\BaseTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Ajax\semantic\html\modules\HtmlDimmer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * Base class for Semantic double elements | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @author jc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @version 1.001 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class HtmlSemDoubleElement extends HtmlDoubleElement { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 	use BaseTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 	protected $_popup=NULL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	protected $_dimmer=NULL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 22 |  | View Code Duplication | 	public function __construct($identifier, $tagName="p", $baseClass="ui", $content=NULL) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		parent::__construct($identifier, $tagName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$this->_baseClass=$baseClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 		$this->setClass($baseClass); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		if (isset($content)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 			$this->content=$content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	public function setPopupAttributes($variation=NULL, $popupEvent=NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 		if (isset($this->_popup)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 			$this->_popup->setAttributes($variation, $popupEvent); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	public function addPopup($title="", $content="", $variation=NULL, $params=array()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		$this->_popup=new InternalPopup($this, $title, $content, $variation, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 		return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	public function addPopupHtml($html="", $variation=NULL, $params=array()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 		$this->_popup=new InternalPopup($this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 		$this->_popup->setHtml($html); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 		$this->_popup->setAttributes($variation, $params); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 		return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	public function addDimmer($content=NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		$dimmer=new HtmlDimmer("dimmer-" . $this->identifier, $content); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$this->addContent($dimmer); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		return $dimmer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  | 	public function jsShowDimmer($show=true) { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  | 		$status="hide"; | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 		if ($show === true) | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  | 			$status="show"; | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  | 		return '$("#.' . $this->identifier . ').dimmer("' . $status . '");'; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	public function compile(JsUtils $js=NULL, View $view=NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		if (isset($this->_popup)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 			$this->_popup->compile(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 		return parent::compile($js, $view); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	public function run(JsUtils $js) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		$this->_bsComponent=$js->semantic()->generic("#" . $this->identifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		parent::run($js); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$this->addEventsOnRun($js); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 		if (isset($this->_popup)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 			$this->_popup->run($js); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 		return $this->_bsComponent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	/* | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * public function __call($name, $arguments){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * $type=\substr($name, 0,3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 * $name=\strtolower(\substr($name, 3)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	 * $names=\array_merge($this->_variations,$this->_states); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	 * $argument=@$arguments[0]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	 * if(\array_search($name, $names)!==FALSE){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	 * switch ($type){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	 * case "set": | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 	 * if($argument===false){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	 * $this->removePropertyValue("class", $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	 * }else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	 * $this->setProperty("class", $this->_baseClass." ".$name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 	 * } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	 * break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	 * case "add": | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	 * $this->addToPropertyCtrl("class", $name,array($name)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	 * break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	 * default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	 * throw new \Exception("Méthode ".$type.$name." inexistante."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	 * } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	 * }else{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	 * throw new \Exception("Propriété ".$name." inexistante."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	 * } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	 * return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 	 * } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 102 |  |  | 	 */ | 
            
                                                        
            
                                    
            
            
                | 103 |  |  | } | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.