Completed
Push — master ( e9bdcb...b0560a )
by Jean-Christophe
04:52
created

HtmlProgress::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 7
nc 4
nop 3
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
use Phalcon\Mvc\View;
9
10
class HtmlProgress extends HtmlSemDoubleElement {
11
	private $_params=array ();
12
13
	public function __construct($identifier, $value=NULL, $label=NULL) {
14
		parent::__construct($identifier, "div", "ui progress");
15
		if (isset($value) === true)
16
			$this->setProperty("data-percent", $value);
17
		$this->createBar();
18
		if (isset($label) === true)
19
			$this->setLabel($label);
20
	}
21
22
	public function setLabel($label) {
23
		$this->content["label"]=new HtmlSemDoubleElement("lbl-" . $this->identifier, "div", "label", $label);
24
		return $this;
25
	}
26
27
	private function createBar() {
28
		$bar=new HtmlSemDoubleElement("bar-" . $this->identifier, "div", "bar", new HtmlSemDoubleElement("progress-" . $this->identifier, "div", "progress"));
29
		$this->content["bar"]=$bar;
30
		return $this;
31
	}
32
33
	public function setIndicating() {
34
		return $this->addToProperty("class", "indicating");
35
	}
36
37
	public function setActive() {
38
		return $this->addToProperty("class", "active");
39
	}
40
41
	/**
42
	 *
43
	 * {@inheritDoc}
44
	 *
45
	 * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
46
	 */
47
	public function compile(JsUtils $js=NULL, View $view=NULL) {
48
		$this->content=JArray::sortAssociative($this->content, [ "bar","label" ]);
49
		return parent::compile($js, $view);
50
	}
51
52
	public function jsSetValue($value) {
53
		return '$("#' . $this->identifier . '").progress({value:' . $value . '});';
54
	}
55
56
	public function jsIncValue() {
57
		return '$("#' . $this->identifier . '").progress("increment");';
58
	}
59
60
	public function jsDecValue() {
61
		return '$("#' . $this->identifier . '").progress("decrement");';
62
	}
63
64
	/**
65
	 *
66
	 * @param mixed $active
67
	 * @param mixed $error
68
	 * @param mixed $success
69
	 * @param mixed $warning
70
	 * @param mixed $percent
71
	 * @param mixed $ratio
72
	 * @return HtmlProgress
73
	 */
74
	public function setTextValues($active=false, $error=false, $success=false, $warning=false, $percent="{percent}%", $ratio="{value} of {total}") {
75
		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...
76
			$array=$active;
77
			$active=JArray::getDefaultValue($array, "active", false);
78
			$success=JArray::getDefaultValue($array, "success", $success);
79
			$warning=JArray::getDefaultValue($array, "warning", $warning);
80
			$percent=JArray::getDefaultValue($array, "percent", $percent);
81
			$ratio=JArray::getDefaultValue($array, "ratio", $ratio);
82
		}
83
		$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) . "}%";
84
		return $this;
85
	}
86
87
	public function onChange($jsCode) {
88
		return $this->_params["onChange"]="%function(percent, value, total){" . $jsCode . "}%";
89
	}
90
91
	/*
92
	 * (non-PHPdoc)
93
	 * @see BaseHtml::run()
94
	 */
95
	public function run(JsUtils $js) {
96 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...
97
			$this->_bsComponent=$js->semantic()->progress("#" . $this->identifier, $this->_params);
98
		$this->addEventsOnRun($js);
99
		return $this->_bsComponent;
100
	}
101
}