1 <?php
2 /**
3 * Tabs.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 a tab system in a view
13 *
14 * @package View\Plugins
15 */
16 class Tabs 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 tabs set
33 *
34 * @var array
35 */
36 $tabs = array();
37
38 /**
39 * Display the tabs
40 *
41 * @return string The displayed HTML
42 */
43 public function display(){
44 if(!$this->id) {
45 $this->id = uniqid();
46 }
47 foreach($this->tabs as &$tab){
48 if(empty($tab['id'])) {
49 $tab['id'] = uniqid();
50 }
51 }
52 if(!$this->selected) {
53 $this->selected = array_keys($this->tabs)[0];
54 }
55
56 return \Hawk\View::make(
57 \Hawk\Theme::getSelected()->getView('tabs.tpl'), array(
58 'id' => $this->id,
59 'tabs' => $this->tabs,
60 'selected' => $this->selected
61 )
62 );
63
64 }
65 }
66