Completed
Push — master ( 409900...f20dfb )
by Jean-Christophe
03:24
created

HtmlMenu::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace Ajax\semantic\html\collections;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\bootstrap\html\HtmlLink;
7
use Ajax\common\html\HtmlDoubleElement;
8
9
class HtmlMenu extends HtmlSemDoubleElement {
10
11
	public function __construct($identifier, $items=array()) {
12
		parent::__construct($identifier, "div");
13
		$this->setClass("ui menu");
14
		foreach ($items as $item){
15
			$this->addItem($item);
16
		}
17
	}
18
19
	/**
20
	 * Sets the menu type
21
	 * @param string $type one of text,item
22
	 * @return \Ajax\semantic\html\collections\HtmlMenu
23
	 */
24
	public function setType($type=""){
25
		return $this->addToPropertyCtrl("class", $type, array("","item","text"));
26
	}
27
28
	public function addItem($item){
29
		$itemO=$item;
30
		if(\is_string($item)){
31
				$itemO=new HtmlLink("item-".\sizeof($this->content),"",$item);
32
				$itemO->setClass("item");
33
		}
34
		$this->addContent($itemO);
35
	}
36
37
	/**
38
	 * Return the item at index
39
	 * @param int $index
40
	 * @return HtmlDoubleElement
41
	 */
42 View Code Duplication
	public function getItem($index) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
43
		if (is_int($index))
44
			return $this->content[$index];
45
			else {
46
				$elm=$this->getElementById($index, $this->content);
47
				return $elm;
48
			}
49
	}
50
51
	public function setActiveItem($index){
52
		$item=$this->getItem($index);
53
		if($item!==null){
54
			$item->addToProperty("class", "active");
55
		}
56
		return $this;
57
	}
58
}