1 <?php
2
3 namespace Icybee\Modules\Forms;
4
5 use Brickrouge\Element;
6 use Brickrouge\Group;
7 use Brickrouge\Text;
8
9 class EmailComposer extends Group
10 {
11 public function __construct(array $attributes=array())
12 {
13 parent::__construct
14 (
15 \ICanBoogie\array_merge_recursive
16 (
17 array
18 (
19 self::CHILDREN => array
20 (
21 'from' => new Text
22 (
23 array
24 (
25 Group::LABEL => 'email_from'
26 )
27 ),
28
29 'destination' => new Text
30 (
31 array
32 (
33 Group::LABEL => 'email_destination'
34 )
35 ),
36
37 'bcc' => new Text
38 (
39 array
40 (
41 Group::LABEL => 'email_bcc'
42 )
43 ),
44
45 'subject' => new Text
46 (
47 array
48 (
49 Group::LABEL => 'email_subject'
50 )
51 ),
52
53 'template' => new Element
54 (
55 'textarea', array
56 (
57 Group::LABEL => 'email_template'
58 )
59 )
60 )
61 ),
62
63 $attributes
64 )
65 );
66 }
67
68 public function offsetSet($offset, $value)
69 {
70 if ($offset == 'name')
71 {
72 $is_suffix = $value{strlen($value) - 1} == '_';
73
74 foreach ($this->children as $name => $child)
75 {
76 $child['name'] = $is_suffix ? $value . $name : $value . "[$name]";
77 }
78 }
79 else if ($offset == self::DEFAULT_VALUE && is_array($value))
80 {
81 foreach ($value as $name => $default_value)
82 {
83 if (empty($this->children[$name]))
84 {
85 continue;
86 }
87
88 $this->children[$name][self::DEFAULT_VALUE] = $default_value;
89 }
90 }
91
92 parent::offsetSet($offset, $value);
93 }
94 }
95