Completed
Push — master ( bb3350...c8eebb )
by Jean-Christophe
03:32
created

HtmlProgress::setWarning()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Ajax\semantic\html\modules;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\JsUtils;
7
use Ajax\service\JArray;
8
9
use Ajax\semantic\html\base\constants\State;
10
11
class HtmlProgress extends HtmlSemDoubleElement {
12
	private $_params=array ();
13
14
	public function __construct($identifier, $value=NULL, $label=NULL, $attributes=array()) {
15
		parent::__construct($identifier, "div", "ui progress");
16
		if (isset($value) === true)
17
			$this->setProperty("data-percent", $value);
18
		$this->createBar();
19
		if (isset($label) === true)
20
			$this->setLabel($label);
21
		$this->_states=[ State::SUCCESS,State::WARNING,State::ERROR,State::ACTIVE,State::DISABLED ];
22
		$this->addToProperty("class", $attributes);
23
	}
24
25
	public function setLabel($label) {
26
		$this->content["label"]=new HtmlSemDoubleElement("lbl-" . $this->identifier, "div", "label", $label);
27
		return $this;
28
	}
29
30
	private function createBar() {
31
		$bar=new HtmlSemDoubleElement("bar-" . $this->identifier, "div", "bar", new HtmlSemDoubleElement("progress-" . $this->identifier, "div", "progress"));
32
		$this->content["bar"]=$bar;
33
		return $this;
34
	}
35
36
	public function setTotal($value) {
37
		return $this->setProperty("data-total", $value);
38
	}
39
40
	public function setValue($value) {
41
		return $this->setProperty("data-value", $value);
42
	}
43
44
	public function setPercent($value) {
45
		return $this->setProperty("data-percent", $value);
46
	}
47
48
	public function setIndicating() {
49
		return $this->addToProperty("class", "indicating");
50
	}
51
52
	public function setWarning() {
53
		return $this->addToProperty("class", "warning");
54
	}
55
56
	public function setError() {
57
		return $this->addToProperty("class", "error");
58
	}
59
60
	/**
61
	 *
62
	 * {@inheritDoc}
63
	 *
64
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
65
	 */
66
	public function compile(JsUtils $js=NULL, &$view=NULL) {
67
		$this->content=JArray::sortAssociative($this->content, [ "bar","label" ]);
68
		return parent::compile($js, $view);
69
	}
70
71
	public function jsSetValue($value) {
72
		return '$("#' . $this->identifier . '").progress({value:' . $value . '});';
73
	}
74
75
	public function jsIncValue() {
76
		return '$("#' . $this->identifier . '").progress("increment");';
77
	}
78
79
	public function jsDecValue() {
80
		return '$("#' . $this->identifier . '").progress("decrement");';
81
	}
82
83
	/**
84
	 *
85
	 * @param mixed $active
86
	 * @param mixed $error
87
	 * @param mixed $success
88
	 * @param mixed $warning
89
	 * @param mixed $percent
90
	 * @param mixed $ratio
91
	 * @return HtmlProgress
92
	 */
93
	public function setTextValues($active=false, $error=false, $success=false, $warning=false, $percent="{percent}%", $ratio="{value} of {total}") {
94
		if (\is_array($active) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
95
			$array=$active;
96
			$active=JArray::getDefaultValue($array, "active", false);
97
			$success=JArray::getDefaultValue($array, "success", $success);
98
			$warning=JArray::getDefaultValue($array, "warning", $warning);
99
			$percent=JArray::getDefaultValue($array, "percent", $percent);
100
			$ratio=JArray::getDefaultValue($array, "ratio", $ratio);
101
		}
102
		$this->_params["text"]="%{active  : " . \var_export($active, true) . ",error: " . \var_export($error, true) . ",success : " . \var_export($success, true) . ",warning : " . \var_export($warning, true) . ",percent : " . \var_export($percent, true) . ",ratio   : " . \var_export($ratio, true) . "}%";
103
		return $this;
104
	}
105
106
	public function onChange($jsCode) {
107
		return $this->_params["onChange"]="%function(percent, value, total){" . $jsCode . "}%";
108
	}
109
110
	/*
111
	 * (non-PHPdoc)
112
	 * @see BaseHtml::run()
113
	 */
114
	public function run(JsUtils $js) {
115 View Code Duplication
		if (isset($this->_bsComponent) === false)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
116
			$this->_bsComponent=$js->semantic()->progress("#" . $this->identifier, $this->_params);
117
		$this->addEventsOnRun($js);
118
		return $this->_bsComponent;
119
	}
120
121
	public static function create($identifier, $value=NULL, $label=NULL, $attributes=array()) {
122
		return new HtmlProgress($identifier, $value, $label, $attributes);
123
	}
124
}