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
|
|
|
|
8
|
|
|
trait CheckboxTrait { |
9
|
|
|
|
10
|
|
|
public abstract function addToPropertyCtrl($name, $value, $typeCtrl); |
11
|
|
|
|
12
|
|
|
public function setType($checkboxType) { |
13
|
|
|
return $this->getHtmlCk()->addToPropertyCtrl("class", $checkboxType, CheckboxType::getConstants()); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Attach $this to $selector and fire $action |
19
|
|
|
* @param string $selector jquery selector of the associated element |
20
|
|
|
* @param string $action action to execute : check, uncheck or NULL for toggle |
21
|
|
|
* @return \Ajax\semantic\html\collections\form\AbstractHtmlFormRadioCheckbox |
22
|
|
|
*/ |
23
|
|
|
public function attachEvent($selector, $action=NULL) { |
24
|
|
|
return $this->getHtmlCk()->attachEvent($selector, $action); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Attach $this to an array of $action=>$selector |
29
|
|
|
* @param array $events associative array of events to attach ex : ["#bt-toggle","check"=>"#bt-check","uncheck"=>"#bt-uncheck"] |
30
|
|
|
* @return \Ajax\semantic\html\collections\form\AbstractHtmlFormRadioCheckbox |
31
|
|
|
*/ |
32
|
|
|
public function attachEvents($events=array()) { |
33
|
|
|
return $this->getHtmlCk()->attachEvents($events); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getField(){ |
37
|
|
|
return $this->content["field"]->getField(); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getHtmlCk(){ |
41
|
|
|
return $this->content["field"]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getDataField(){ |
45
|
|
|
$field= $this->getField(); |
46
|
|
|
if($field instanceof AbstractCheckbox) |
47
|
|
|
$field=$field->getField(); |
48
|
|
|
return $field; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Check the checkbox |
53
|
|
|
* @param boolean $value |
54
|
|
|
* @return \Ajax\semantic\html\collections\form\traits\CheckboxTrait |
|
|
|
|
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function setChecked($value=true){ |
|
|
|
|
57
|
|
|
if($value===true){ |
58
|
|
|
$this->getDataField()->setProperty("checked", "checked"); |
59
|
|
|
}else{ |
60
|
|
|
$this->getDataField()->removeProperty("checked"); |
61
|
|
|
} |
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: