1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Installer;
13
14 use Brickrouge\Element;
15
16 17 18
19 class PanelDecorator
20 {
21 const TITLE = '#panel-title';
22 const DESCRIPTION = '#panel-description';
23
24 25 26 27 28
29 protected $component;
30
31 public function __construct(Element $component)
32 {
33 $this->component = $component;
34 }
35
36 public function __toString()
37 {
38 try
39 {
40 return $this->render();
41 }
42 catch (\Exception $e)
43 {
44 return \Brickrouge\render_exception($e);
45 }
46 }
47
48 public function render()
49 {
50 global $core;
51
52 $panel = new Element
53 (
54 'div', array
55 (
56 'class' => 'install-panel'
57 )
58 );
59
60 $component = $this->component;
61 $rendered_component = (string) $component;
62 $content = '';
63 $name = $component['name'];
64 $title = $component[self::TITLE];
65 $description = $component[self::DESCRIPTION];
66
67 if ($rendered_component)
68 {
69 $content = '<div class="install-panel-content">' . $rendered_component . '</div>';
70 }
71 else
72 {
73 $panel->add_class('no-content');
74 }
75
76 if ($name)
77 {
78 $panel['id'] = "panel-$name";
79 $panel->add_class("install-panel--$name");
80 }
81
82 if (!empty($core->session->install['done'][$name]))
83 {
84 $panel->add_class('done');
85 }
86
87 $panel[Element::INNER_HTML] = <<<EOT
88 <div class="install-panel-inner">
89 <h3 class="install-panel-title">$title</h3>
90 <div class="install-panel-description">$description</div>
91 $content
92 </div>
93 EOT;
94
95 return (string) $panel;
96 }
97 }