Completed
Push — master ( 3ded41...1b9fb1 )
by Jean-Christophe
03:08
created

InternalPopup::compile()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 12
rs 9.2
c 1
b 0
f 0
cc 4
eloc 8
nc 8
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\content;
4
5
use Ajax\JsUtils;
6
use Ajax\service\JString;
7
use Ajax\semantic\html\base\HtmlSemDoubleElement;
8
9
class InternalPopup {
10
	protected $title;
11
	protected $content;
12
	protected $html;
13
	protected $variation;
14
	protected $params;
15
	protected $semElement;
16
17
	public function __construct($semElement,$title="",$content="",$variation=NULL,$params=array()){
18
		$this->semElement=$semElement;
19
		$this->title=$title;
20
		$this->content=$content;
21
		$this->setAttributes($variation,$params);
22
	}
23
24
	public function setHtml($html) {
25
		$this->html= $html;
26
		return $this;
27
	}
28
29
	public function setAttributes($variation=NULL,$params=array()){
30
		$this->variation=$variation;
31
		$this->params=$params;
32
	}
33
34
	public function onShow($jsCode){
35
		$this->params["onShow"]=$jsCode;
36
	}
37
38
	public function compile(JsUtils $js=NULL){
39
		if(JString::isNotNull($this->title)){
40
			$this->semElement->addToProperty("data-title", $this->title);
41
		}
42
		if(JString::isNotNull($this->content)){
43
			$this->semElement->addToProperty("data-content", $this->content);
44
		}
45
		$this->_compileHtml($js);
46
		if(JString::isNotNull($this->variation)){
47
			$this->semElement->addToProperty("data-variation", $this->variation);
48
		}
49
	}
50
51
	private function _compileHtml(JsUtils $js=NULL){
52
		if(JString::isNotNull($this->html)){
53
			$html=$this->html;
54
			if(\is_array($html)){
55
				\array_walk($html, function(&$item) use($js){
56
					if($item instanceof HtmlSemDoubleElement){
57
						$comp=$item->compile($js);
58
						if(isset($js)){
59
							$bs=$item->run($js);
60
							if(isset($bs))
61
								$this->params['onShow']=$bs->getScript();
62
						}
63
						$item=$comp;
64
					}
65
				});
66
				$html=\implode("",$html);
67
			}
68
			$html=\str_replace("\"", "'", $html);
69
			$this->semElement->addToProperty("data-html", $html);
70
		}
71
	}
72
73
	public function run(JsUtils $js){
74
		$js->semantic()->popup("#".$this->semElement->getIdentifier(),$this->params);
75
	}
76
77
}