1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Editor;
13
14 use Brickrouge\Alert;
15
16 use Brickrouge\Document;
17 use Brickrouge\Element;
18
19 class WidgetsEditorElement extends Element implements EditorElement
20 {
21 static protected function add_assets(Document $document)
22 {
23 parent::add_assets($document);
24
25 $document->css->add('assets/editor.css');
26 $document->js->add('assets/editor.js');
27 }
28
29 public function __construct(array $attributes=array())
30 {
31 parent::__construct
32 (
33 'ul', $attributes + array
34 (
35 'class' => 'widgets-selector combo'
36 )
37 );
38
39 if ($this[Element::DESCRIPTION] === null)
40 {
41 $this[Element::DESCRIPTION] = "Sélectionner les widgets à afficher. Vous pouvez les ordonner par glissé-déposé.";
42 }
43 }
44
45 public function render_inner_html()
46 {
47 global $core;
48
49 $config = $core->configs->synthesize('widgets', 'merge');
50
51 if (!$config)
52 {
53 return new Alert('There is no widget defined.', array(Alert::CONTEXT => Alert::CONTEXT_INFO));
54 }
55
56 $rc = parent::render_inner_html();
57
58 $value = $this['value'];
59 $name = $this['name'];
60
61 $value = is_array($value) ? array_flip($value) : array();
62
63
64
65 $list = array_merge($value, $config);
66
67
68
69 foreach ($list as $id => $widget)
70 {
71 $rc .= '<li>';
72
73 $rc .= new Element
74 (
75 Element::TYPE_CHECKBOX, array
76 (
77 Element::LABEL => $widget['title'],
78
79 'name' => $name . '[' . $id . ']',
80 'checked' => isset($value[$id])
81 )
82 );
83
84 $rc .= '</li>';
85 }
86
87 return $rc;
88 }
89 }