Passed
Push — master ( fdcf95...dcc4d7 )
by Jean-Christophe
03:10
created

HtmlInput::forceValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Ajax\common\html\html5;
3
4
use Ajax\common\html\HtmlSingleElement;
5
use Ajax\service\JString;
6
use Ajax\JsUtils;
7
8
class HtmlInput extends HtmlSingleElement {
9
10
	protected $_placeholder;
11
12
	public function __construct($identifier, $type = "text", $value = NULL, $placeholder = NULL) {
13
		parent::__construct($identifier, "input");
14
		$this->setProperty("name", $identifier);
15
		$this->setValue($value);
16
		$this->setPlaceholder($placeholder);
17
		$this->setProperty("type", $type);
18
	}
19
20
	public function setValue($value) {
21
		if (isset($value))
22
			$this->setProperty("value", $value);
23
		return $this;
24
	}
25
26
	public function setInputType($value) {
27
		return $this->setProperty("type", $value);
28
	}
29
30
	public function forceValue($value = 'true') {
31
		$this->wrap('<input type="hidden" value="false" name="' . $this->identifier . '"/>');
32
		$this->setValue($value);
33
		return $this;
34
	}
35
36
	public function setPlaceholder($value) {
37
		if (JString::isNotNull($value))
38
			$this->_placeholder = $value;
39
		return $this;
40
	}
41
42
	public function compile(JsUtils $js = NULL, &$view = NULL) {
43
		$value = $this->_placeholder;
44
		if (JString::isNull($value)) {
45
			if (JString::isNotNull($this->getProperty("name")))
46
				$value = \ucfirst($this->getProperty("name"));
47
		}
48
		$this->setProperty("placeholder", $value);
49
		return parent::compile($js, $view);
50
	}
51
}
52