HtmlStep::defineActiveStep()   C
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 23
rs 6.7272
cc 7
eloc 19
nc 5
nop 0
1
<?php
2
3
namespace Ajax\semantic\html\elements;
4
5
use Ajax\semantic\html\base\HtmlSemCollection;
6
use Ajax\semantic\html\content\HtmlStepItem;
7
use Ajax\JsUtils;
8
9
use Ajax\common\html\HtmlDoubleElement;
10
use Ajax\semantic\html\base\constants\Side;
11
12
class HtmlStep extends HtmlSemCollection{
13
	protected $_activeStep;
14
15
	public function __construct( $identifier,$steps=array()){
16
		parent::__construct( $identifier,"div", "ui steps");
17
		$this->addItems($steps);
18
	}
19
20
21
	/**
22
	 * {@inheritDoc}
23
	 * @see \Ajax\common\html\html5\HtmlCollection::createItem()
24
	 */
25
	protected function createItem($value) {
26
		$itemO=new HtmlStepItem("item-".\sizeof($this->content),$value);
27
		return $itemO;
28
	}
29
30
	/**
31
	 * @param string|array $step
32
	 * @return HtmlStepItem
33
	 */
34
	public function addStep($step){
35
		return $this->addItem($step);
0 ignored issues
show
Bug introduced by
It seems like $step defined by parameter $step on line 34 can also be of type array; however, Ajax\common\html\HtmlCollection::addItem() does only seem to accept object<Ajax\common\html\HtmlDoubleElement>|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
36
	}
37
38
	public function setOrdered(){
39
		return $this->addToProperty("class", "ordered");
40
	}
41
42
	public function isOrdered(){
43
		return $this->propertyContains("class", "ordered");
44
	}
45
46
	public function setVertical(){
47
		return $this->addToProperty("class", "vertical");
48
	}
49
50
	protected function defineActiveStep(){
51
		$activestep=$this->_activeStep;
52
		$count=$this->count();
53
		if($this->isOrdered()){
54
			for($i=0;$i<$count;$i++){
55
				$step=$this->content[$i];
56
				$step->removeStatus();
57
				if($i<$activestep)
58
					$step->setCompleted();
59
				elseif ($i===$activestep)
60
					$step->setActive();
61
				else
62
					$step->setDisabled();
63
			}
64
		}else{
65
			foreach ($this->content as $step){
66
				$step->removeStatus();
67
			}
68
			if($activestep<$count)
69
				$this->content[$activestep]->setActive();
70
		}
71
		return $this;
72
	}
73
74
	public function compile(JsUtils $js=NULL, &$view=NULL) {
75
		if(isset($this->_activeStep)===true && \is_numeric($this->_activeStep))
76
			$this->defineActiveStep();
77
		return parent::compile($js,$view);
78
	}
79
80
	public function setActiveStep($_activeStep) {
81
		$this->_activeStep=$_activeStep;
82
		return $this;
83
	}
84
85
	public function setAttached($side="",HtmlDoubleElement $toElement=NULL){
86
		if(isset($toElement)){
87
			$toElement->addToPropertyCtrl("class", "attached",array("attached"));
88
		}
89
		return $this->addToPropertyCtrl("class", $side." attached",Side::getConstantValues("attached"));
90
	}
91
92
	public function asLink(){
93
		foreach ($this->content as $step){
94
			$step->asLink();
95
		}
96
		return $this;
97
	}
98
}