Completed
Push — master ( b77ba2...042f42 )
by Jean-Christophe
03:22
created

HtmlSemNavElement::setAttr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
namespace Ajax\semantic\html\base;
3
4
use Ajax\service\JArray;
5
use Ajax\common\html\traits\NavElementTrait;
6
/**
7
 * Sem class for navigation elements : Breadcrumbs and Pagination
8
 * @author jc
9
 * @version 1.001
10
 */
11
abstract class HtmlSemNavElement extends HtmlSemCollection {
12
	use NavElementTrait;
13
	/**
14
	 * @var string the root site
15
	 */
16
	protected $root;
17
18
	/**
19
	 * @var String the html attribute which contains the elements url. default : data-ajax
20
	 */
21
	protected $attr;
22
23
	/**
24
	 * @var string|array
25
	 */
26
	protected $_contentSeparator="";
27
28
29
	public function __construct($identifier,$tagName,$baseClass){
30
		parent::__construct($identifier,$tagName,$baseClass);
31
		$this->root="";
32
		$this->attr="data-ajax";
33
	}
34
35
	/**
36
	 * Associate an ajax get to the elements, displayed in $targetSelector
37
	 * @param string $targetSelector the target of the get
38
	 * @return HtmlNavElement
39
	 */
40
	public function autoGetOnClick($targetSelector){
41
		return $this->getOnClick($this->root, $targetSelector,array("attr"=>$this->attr));
42
	}
43
44
	public function contentAsString(){
45
		return JArray::implode($this->_contentSeparator, $this->content);
46
	}
47
48
	public function setContentDivider($divider,$index=NULL) {
49
		$divider="<div class='divider'> {$divider} </div>";
50
		return $this->setDivider($divider, $index);
51
	}
52
53
	public function setIconContentDivider($iconContentDivider,$index=NULL) {
54
		$contentDivider="<i class='".$iconContentDivider." icon divider'></i>";
55
		return $this->setDivider($contentDivider, $index);
56
	}
57
58
	protected function setDivider($divider,$index){
59
		if(isset($index)){
60
			if(!\is_array($this->_contentSeparator))
61
				$this->_contentSeparator=array_fill (0, $this->count()-1,$this->_contentSeparator);
62
			$this->_contentSeparator[$index]=$divider;
63
		}else{
64
			$this->_contentSeparator=$divider;
65
		}
66
		return $this;
67
	}
68
69
	protected function getContentDivider($index){
70
		if(\is_array($this->_contentSeparator)){
71
			return @$this->_contentSeparator[$index];
72
		}
73
		return $this->_contentSeparator;
74
	}
75
76
77
}