Passed
Push — master ( 1d8d13...de8c14 )
by Jean-Christophe
04:21
created

SimpleSemExtComponent::addBehavior()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Ajax\semantic\components;
4
5
use Ajax\common\components\SimpleExtComponent;
6
use Ajax\JsUtils;
7
8
class SimpleSemExtComponent extends SimpleExtComponent {
9
	protected $paramParts;
10
	public function __construct(JsUtils $js=NULL) {
11
		parent::__construct($js);
12
		$this->paramParts=array();
13
	}
14
15
	protected function addBehavior($name) {
16
		$this->paramParts[]=[$name];
17
		return $this;
18
	}
19
	
20
	protected function generateParamParts(){
21
		$results=[];
22
		foreach ($this->paramParts as $paramPart){
23
			$results[]="{$this->uiName}(".\implode(",", $paramPart).")";
24
		}
25
		return \implode(".", $results);
26
	}
27
28
	public function getScript() {
29
		$allParams=$this->params;
30
		$this->jquery_code_for_compile=array ();
31
		$paramParts="";
32
		if(\sizeof($this->paramParts)>0){
33
			$paramParts=".".$this->generateParamParts();
34
		}
35
		$this->jquery_code_for_compile []="$( \"".$this->attachTo."\" ).{$this->uiName}(".$this->getParamsAsJSON($allParams).")".$paramParts.";";
36
		$this->compileEvents();
37
		return $this->compileJQueryCode();
38
	}
39
40
	public function setParamParts($paramParts) {
41
		$this->paramParts=$paramParts;
42
		return $this;
43
	}
44
45
	public function addComponentEvent($event,$jsCode){
46
		$jsCode=\str_ireplace("\"","%quote%", $jsCode);
47
		return $this->setParam($event, "%function(){".$jsCode."}%");
48
	}
49
50
}
51