1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Editor;
13
14 use ICanBoogie\Module;
15
16 use Brickrouge\Element;
17 use Brickrouge\Text;
18
19 20 21
22 class FeedEditorElement extends Element implements EditorElement
23 {
24 private $elements = array();
25
26 public function __construct(array $attributes=array())
27 {
28 global $core;
29
30 $constructors = array();
31 $modules = $core->modules;
32
33 foreach ($modules->descriptors as $module_id => $descriptor)
34 {
35 if ($module_id == 'contents' || !$modules->is_extending($module_id, 'contents'))
36 {
37 continue;
38 }
39
40 $constructors[$module_id] = $descriptor[Module::T_TITLE];
41 }
42
43 uasort($constructors, 'ICanBoogie\unaccent_compare_ci');
44
45 parent::__construct
46 (
47 'div', $attributes + array
48 (
49 self::CHILDREN => array
50 (
51 $this->elements['constructor'] = new Element
52 (
53 'select', array
54 (
55 Element::LABEL => 'Module',
56 Element::LABEL_POSITION => 'above',
57 Element::REQUIRED => true,
58 Element::OPTIONS => array(null => '<sélectionner un module>') + $constructors
59 )
60 ),
61
62 $this->elements['limit'] = new Text
63 (
64 array
65 (
66 Element::LABEL => "Nombre d'entrées dans le flux",
67 Element::LABEL_POSITION => 'above',
68 Element::REQUIRED => true,
69 Element::DEFAULT_VALUE => 10,
70
71 'size' => 4
72 )
73 ),
74
75 $this->elements['settings'] = new Element
76 (
77 Element::TYPE_CHECKBOX_GROUP, array
78 (
79 Element::LABEL => 'Options',
80 Element::LABEL_POSITION => 'above',
81 Element::OPTIONS => array
82 (
83 'is_with_author' => "Mentionner l'auteur",
84 'is_with_category' => "Mentionner les catégories",
85 'is_with_attached' => "Ajouter les pièces jointes"
86 ),
87
88 'class' => 'list'
89 )
90 )
91 ),
92
93 'class' => 'editor feed combo'
94 )
95 );
96 }
97
98 public function offsetSet($offset, $value)
99 {
100 if ($offset == 'name')
101 {
102 foreach ($this->elements as $identifier => $element)
103 {
104 $element['name'] = $value . '[' . $identifier . ']';
105 }
106 }
107
108 parent::offsetSet($offset, $value);
109 }
110
111 public function render_inner_html()
112 {
113 $value = $this['value'];
114
115 if ($value)
116 {
117 if (is_string($value))
118 {
119 $value = json_decode($value, true);
120 }
121
122 foreach ($value as $identifier => $v)
123 {
124 $this->elements[$identifier]['value'] = $v;
125 }
126 }
127
128 return parent::render_inner_html();
129 }
130 }