initial commit
[namibia] / module / Utility / src / Utility / Entity / Template.php
1 <?php
2 namespace Utility\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * A notification template.
10  * @ORM\Entity
11  * @ORM\Table(name="lib_template", uniqueConstraints={@ORM\UniqueConstraint(name="unique_template", columns={"name"})})
12  */
13 class Template
14 {
15
16         /**
17          * Can archive records.
18          */
19         const ARCHIVE = false;
20         /**
21          * Pull Synchronization Strategy for this table.
22          */
23         const PULL_SYNCH_STRATEGY = false;
24         /**
25          * Push Synchronization Strategy for this table.
26          */
27         const PUSH_SYNCH_STRATEGY = false;
28
29         /**
30          * @ORM\Id
31          * @ORM\Column(type="integer");
32          * @ORM\GeneratedValue(strategy="AUTO")
33          */
34         protected $id;
35
36         /**
37          * @ORM\Column(type="string", length=50, unique=true)
38          */
39         protected $name;
40
41         /**
42          * @ORM\Column(type="string", length=100)
43          */
44         protected $subject;
45
46         /**
47          * @ORM\Column(type="text")
48          */
49         protected $tags;
50
51         /**
52          * @ORM\Column(type="text", name="email_template")
53          */
54         protected $emailTemplate;
55
56         /**
57          * @ORM\Column(type="text", name="sms_template")
58          */
59         protected $smsTemplate;
60
61         /**
62          * @ORM\OneToOne(targetEntity="RepeaterTemplate")
63          * @ORM\JoinColumn(name="lib_repeater_template_id")
64          **/
65         protected $repeaterTemplate;
66
67
68         /**
69          * Magic getter to expose protected properties.
70          * @param string $property
71          * @return mixed
72          */
73         public function __get($property)
74         {
75                 return $this->$property;
76         }
77
78         /**
79          * Magic setter to save protected properties.
80          * @param string $property
81          * @param mixed $value
82          */
83         public function __set($property, $value)
84         {
85                 $this->$property = $value;
86         }
87
88         /**
89          * Convert the object to an array.
90          * @param array $expand
91          * @return array
92          */
93         public function toArray(array $expand = array('repeaterTemplate'))
94         {
95                 return array(
96                                 'id'               => $this->id,
97                                 'name'             => $this->name,
98                                 'subject'          => $this->subject,
99                                 'tags'             => $this->tags,
100                                 'emailTemplate'    => $this->emailTemplate,
101                                 'smsTemplate'      => $this->smsTemplate,
102                                 'repeaterTemplate' => in_array('repeaterTemplate', $expand)
103                                                                                 && !is_null($this->repeaterTemplate)
104                                         ? $this->repeaterTemplate->toArray($expand)
105                                         : null
106                 );
107         }
108
109         /**
110          * Populate from an array.
111          * @param array $data
112          */
113         public function fromArray($data = array())
114         {
115                 isset($data['id'])
116                         && $this->id = $data['id'];
117                 isset($data['name'])
118                         && $this->name  = $data['name'];
119                 isset($data['subject'])
120                         && $this->subject  = $data['subject'];
121                 isset($data['tags'])
122                         && $this->tags  = $data['tags'];
123                 isset($data['emailTemplate'])
124                         && $this->emailTemplate  = $data['emailTemplate'];
125                 isset($data['smsTemplate'])
126                         && $this->smsTemplate  = $data['smsTemplate'];
127                 isset($data['repeaterTemplate'])
128                         && $this->repeaterTemplate  = $data['repeaterTemplate'];
129         }
130
131 }