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
|
|
View Code Duplication |
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
|
|
|
protected function createCondition($value){ |
29
|
|
|
return ($value instanceof HtmlAccordionItem)===false; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function addPanel($title,$content){ |
33
|
|
|
return $this->addItem([$title,$content]); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* render the content of $controller::$action and set the response to a new panel |
38
|
|
|
* @param JsUtils $js |
39
|
|
|
* @param string $title The panel title |
40
|
|
|
* @param Controller $initialController |
41
|
|
|
* @param string $controller a Phalcon controller |
42
|
|
|
* @param string $action a Phalcon action |
43
|
|
|
* @param array $params |
44
|
|
|
*/ |
45
|
|
|
public function forwardPanel(JsUtils $js,$title,$initialController,$controller,$action,$params=array()){ |
46
|
|
|
return $this->addPanel($title, $js->forward($initialController, $controller, $action,$params)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* render the content of an existing view : $controller/$action and set the response to a new panel |
51
|
|
|
* @param JsUtils $js |
52
|
|
|
* @param string $title The panel title |
53
|
|
|
* @param Controller $initialController |
54
|
|
|
* @param string $viewName |
55
|
|
|
* @param $params The parameters to pass to the view |
56
|
|
|
*/ |
57
|
|
|
public function renderViewPanel(JsUtils $js,$title,$initialController, $viewName, $params=array()) { |
58
|
|
|
return $this->addPanel($title, $js->renderContent($initialController, $viewName,$params)); |
59
|
|
|
} |
60
|
|
|
/* |
61
|
|
|
* (non-PHPdoc) |
62
|
|
|
* @see BaseHtml::run() |
63
|
|
|
*/ |
64
|
|
|
public function run(JsUtils $js) { |
65
|
|
View Code Duplication |
if(isset($this->_bsComponent)===false) |
|
|
|
|
66
|
|
|
$this->_bsComponent=$js->semantic()->accordion("#".$this->identifier,$this->params); |
67
|
|
|
$this->addEventsOnRun($js); |
68
|
|
|
return $this->_bsComponent; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function setStyled(){ |
72
|
|
|
return $this->addToProperty("class", "styled"); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function activate($index){ |
76
|
|
|
$this->getItem($index)->setActive(true); |
|
|
|
|
77
|
|
|
return $this; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function setExclusive($value){ |
81
|
|
|
$this->params["exclusive"]=$value; |
82
|
|
|
} |
83
|
|
|
} |
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.