Passed
Push — master ( 15d416...16888f )
by Jean-Christophe
02:23
created

SimpleSemExtComponent   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 45
rs 10
c 1
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generateParamParts() 0 6 2
A setParamParts() 0 3 1
A getScript() 0 10 2
A addBehavior() 0 3 1
A addComponentEvent() 0 3 1
A setJs() 0 3 1
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
	public function setJs(JsUtils $js){
51
		$this->js=$js;
52
		$js->semantic()->addComponent($this, $this->attachTo, $this->params);
53
	}
54
55
}
56