Passed
Push — master ( d75a73...4a339e )
by Jean-Christophe
02:07
created

HtmlAccordion::getItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ajax\semantic\html\modules;
4
5
use Ajax\semantic\html\base\HtmlSemCollection;
6
use Ajax\semantic\html\content\HtmlAccordionItem;
7
use Ajax\JsUtils;
8
9
class HtmlAccordion extends HtmlSemCollection{
10
11
	protected $params=array();
12
13
	public function __construct( $identifier, $tagName="div", $baseClass="ui"){
14
		parent::__construct( $identifier, "div", "ui accordion");
15
	}
16
17
18
	protected function createItem($value){
19
		$count=$this->count();
20
		$title=$value;
21
		$content=NULL;
22
		if(\is_array($value)){
23
			$title=@$value[0];$content=@$value[1];
24
		}
25
		return new HtmlAccordionItem("item-".$this->identifier."-".$count, $title,$content);
26
	}
27
	
28
	/**
29
	 * @return HtmlAccordionItem
30
	 */
31
	public function getItem($index){
32
		return parent::getItem($index);
33
	}
34
35
	protected function createCondition($value){
36
		return ($value instanceof HtmlAccordionItem)===false;
37
	}
38
39
	public function addPanel($title,$content){
40
		return $this->addItem([$title,$content]);
41
	}
42
43
	/**
44
	 * render the content of $controller::$action and set the response to a new panel
45
	 * @param JsUtils $js
46
	 * @param string $title The panel title
47
	 * @param object $initialController
48
	 * @param string $controller a Phalcon controller
49
	 * @param string $action a Phalcon action
50
	 * @param array $params
51
	 */
52
	public function forwardPanel(JsUtils $js,$title,$initialController,$controller,$action,$params=array()){
53
		return $this->addPanel($title, $js->forward($initialController, $controller, $action,$params));
54
	}
55
56
	/**
57
	 * render the content of an existing view : $controller/$action and set the response to a new panel
58
	 * @param JsUtils $js
59
	 * @param string $title The panel title
60
	 * @param object $initialController
61
	 * @param string $viewName
62
	 * @param array $params The parameters to pass to the view
63
	 */
64
	public function renderViewPanel(JsUtils $js,$title,$initialController, $viewName, $params=array()) {
65
		return $this->addPanel($title, $js->renderContent($initialController, $viewName,$params));
66
	}
67
	/*
68
	 * (non-PHPdoc)
69
	 * @see BaseHtml::run()
70
	 */
71
	public function run(JsUtils $js) {
72
		if(isset($this->_bsComponent)===false)
73
			$this->_bsComponent=$js->semantic()->accordion("#".$this->identifier,$this->params);
74
			$this->addEventsOnRun($js);
75
			return $this->_bsComponent;
76
	}
77
78
	public function setStyled(){
79
		return $this->addToProperty("class", "styled");
80
	}
81
82
	public function activate($index){
83
		$this->getItem($index)->setActive(true);
84
		return $this;
85
	}
86
87
	public function setExclusive($value){
88
		$this->params["exclusive"]=$value;
89
	}
90
}
91