Completed
Push — master ( c7a943...2e4ffb )
by Jean-Christophe
02:55
created

CheckboxTrait::getDataField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace Ajax\semantic\html\collections\form\traits;
4
5
use Ajax\semantic\html\base\constants\CheckboxType;
6
use Ajax\semantic\html\modules\checkbox\AbstractCheckbox;
7
use Ajax\semantic\html\collections\form\HtmlFormField;
8
9
/**
10
 * @author jc
11
 * @property mixed $content
12
 */
13
trait CheckboxTrait {
14
15
	abstract public function addToPropertyCtrl($name, $value, $typeCtrl);
16
17
	public function setType($checkboxType) {
18
		return $this->getHtmlCk()->addToPropertyCtrl("class", $checkboxType, CheckboxType::getConstants());
19
	}
20
21
22
	/**
23
	 * Attach $this to $selector and fire $action
24
	 * @param string $selector jquery selector of the associated element
25
	 * @param string $action action to execute : check, uncheck or NULL for toggle
26
	 * @return HtmlFormField
27
	 */
28
	public function attachEvent($selector, $action=NULL) {
29
		return $this->getHtmlCk()->attachEvent($selector, $action);
30
	}
31
32
	/**
33
	 * Attach $this to an array of $action=>$selector
34
	 * @param array $events associative array of events to attach ex : ["#bt-toggle","check"=>"#bt-check","uncheck"=>"#bt-uncheck"]
35
	 * @return HtmlFormField
36
	 */
37
	public function attachEvents($events=array()) {
38
		return $this->getHtmlCk()->attachEvents($events);
39
	}
40
41
	public function getField(){
42
		return $this->content["field"];
43
	}
44
45
	public function getHtmlCk(){
46
		return $this->content["field"];
47
	}
48
49
	public function setName($name){
50
		$this->getDataField()->setProperty("name", $name);
51
		return $this;
52
	}
53
54
	public function getDataField(){
55
		$field= $this->getField();
56
		if($field instanceof AbstractCheckbox)
57
			$field=$field->getField();
58
		return $field;
59
	}
60
61
	/**
62
	 * Check the checkbox
63
	 * @param boolean $value
64
	 * @return HtmlFormField
65
	 */
66 View Code Duplication
	public function setChecked($value=true){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
67
		if($value===true){
68
			$this->getDataField()->setProperty("checked", "checked");
69
		}else{
70
			$this->getDataField()->removeProperty("checked");
71
		}
72
		return $this;
73
	}
74
75
}
76