1 <?php
2
3 /*
4 * This file is part of the Icybee package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 use Brickrouge\Element;
13 use Brickrouge\Form;
14 use Brickrouge\Text;
15
16 class WdEMailNotifyElement extends \Brickrouge\Group
17 {
18 protected $elements;
19
20 public function __construct(array $attributes=array())
21 {
22 global $core;
23
24 parent::__construct
25 (
26 $attributes + array
27 (
28 Element::CHILDREN => array
29 (
30 'subject' => $this->elements['subject'] = new Text
31 (
32 array
33 (
34 Form::LABEL => "Subject",
35 Element::REQUIRED => true
36 )
37 ),
38
39 'from' => $this->elements['from'] = new Text
40 (
41 array
42 (
43 Form::LABEL => "Sender address",
44 Element::REQUIRED => true,
45 Element::DEFAULT_VALUE => $core->site->email,
46 Element::VALIDATOR => array('Brickrouge\Form::validate_email')
47 )
48 ),
49
50 'bcc' => $this->elements['bcc'] = new Text
51 (
52 array
53 (
54 Form::LABEL => "Blind copy",
55 )
56 ),
57
58 'template' => $this->elements['template'] = new Element
59 (
60 'textarea', array
61 (
62 Form::LABEL => "Message template",
63 Element::REQUIRED => true,
64
65 'rows' => 8
66 )
67 )
68 ),
69
70 'class' => 'combo'
71 )
72 );
73 }
74
75 /**
76 * Forward the `DEFAULT_VALUE` and `name` attribute to its children.
77 */
78 public function offsetSet($offset, $value)
79 {
80 switch ($offset)
81 {
82 case self::DEFAULT_VALUE:
83 {
84 foreach ($value as $identifier => $default)
85 {
86 $this->elements[$identifier][self::DEFAULT_VALUE] = $default;
87 }
88 }
89 break;
90
91 case 'name':
92 {
93 foreach ($this->elements as $identifier => $el)
94 {
95 $el[$offset] = $value . '[' . $identifier . ']';
96 }
97 }
98 break;
99 }
100
101 parent::offsetSet($offset, $value);
102 }
103 }