1 <?php
2 /**
3 * Accordion.php
4 *
5 * @author Elvyrra SAS
6 * @license http://rem.mit-license.org/ MIT
7 */
8
9 namespace Hawk\View\Plugins;
10
11 /**
12 * This class is used to display an accordion in a view
13 *
14 * @package View\Plugins
15 */
16 class Accordion extends \Hawk\ViewPlugin{
17 /**
18 * The 'id' attribute of the accordion
19 *
20 * @var string
21 */
22 public $id,
23
24 /**
25 * The defaultly selected panel
26 *
27 * @var string
28 */
29 $selected,
30
31 /**
32 * The panels set
33 *
34 * @var array
35 */
36 $panels;
37
38
39 /**
40 * Display the accordion
41 *
42 * @return string The displayed HTML
43 */
44 public function display(){
45 if(!$this->id) {
46 $this->id = uniqid();
47 }
48
49 foreach($this->panels as $name => &$panel){
50 if(empty($panel['id'])) {
51 $panel['id'] = uniqid();
52 }
53
54 if(!isset($this->selected)) {
55 $this->selected = $name;
56 }
57 }
58
59 return \Hawk\View::make(
60 \Hawk\Theme::getSelected()->getView('accordion.tpl'), array(
61 'id' => $this->id,
62 'panels' => $this->panels,
63 'selected' => $this->selected
64 )
65 );
66 }
67 }
68