Completed
Push — master ( f99fed...57dceb )
by Jean-Christophe
03:29
created

AjaxCall   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
D compile() 0 40 9
A getMethod() 0 3 1
A setMethod() 0 4 1
A getParameters() 0 3 1
A setParameters() 0 4 1
1
<?php
2
3
namespace Ajax\service;
4
5
6
use Ajax\JsUtils;
7
class AjaxCall {
8
	private $method;
9
	private $parameters;
10
11
	public function __construct($method, $parameters) {
12
		$this->method=$method;
13
		$this->parameters=$parameters;
14
	}
15
16
	public function compile(JsUtils $js=null) {
17
		if ($js==null)
18
			return;
19
		$result="";
20
		$params="{}";
21
		$jsCallback=NULL;
22
		$attr="id";
23
		$validation=false;
24
		$stopPropagation=true;
25
		$preventDefault=true;
26
		$jqueryDone="html";
27
		$ajaxTransition=null;
28
		$hasLoader=true;
29
		$method="get";
30
		extract($this->parameters);
31
		if ($preventDefault===true) {
32
			$result.=Javascript::$preventDefault;
33
		}
34
		if ($stopPropagation===true) {
35
			$result.=Javascript::$stopPropagation;
36
		}
37
		switch($this->method) {
38
			case "get":
39
				$result.=$js->getDeferred($url, $responseElement, $params, $jsCallback, $attr,$jqueryDone,$ajaxTransition);
40
				break;
41
			case "post":
42
				$result.=$js->postDeferred($url, $responseElement, $params, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition);
43
				break;
44
			case "postForm":
45
				$result.=$js->postFormDeferred($url, $form, $responseElement, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition);
46
				break;
47
			case "json":
48
				$result.=$js->jsonDeferred($url,$method,$params,$jsCallback);
49
				break;
50
			case "jsonArray":
51
				$result.=$js->jsonArrayDeferred($modelSelector, $url,$method,$params,$jsCallback);
52
				break;
53
		}
54
		return $result;
55
	}
56
57
	public function getMethod() {
58
		return $this->method;
59
	}
60
61
	public function setMethod($method) {
62
		$this->method=$method;
63
		return $this;
64
	}
65
66
	public function getParameters() {
67
		return $this->parameters;
68
	}
69
70
	public function setParameters($parameters) {
71
		$this->parameters=$parameters;
72
		return $this;
73
	}
74
}