initial commit
[namibia] / module / Newsletter / src / Newsletter / Entity / Newsletter.php
1 <?php
2 namespace Newsletter\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7
8 /**
9  * A newsletter.
10  * @ORM\Entity
11  * @ORM\HasLifecycleCallbacks
12  * @ORM\Table(name="newsletter")
13  */
14 class Newsletter
15 {
16
17         /**
18          * Can archive records.
19          */
20         const ARCHIVE = true;
21         /**
22          * Pull Synchronization Strategy for this table.
23          */
24         const PULL_SYNCH_STRATEGY = false;
25         /**
26          * Push Synchronization Strategy for this table.
27          */
28         const PUSH_SYNCH_STRATEGY = false;
29
30         /**
31          * @ORM\Id
32          * @ORM\Column(type="integer");
33          * @ORM\GeneratedValue(strategy="AUTO")
34          */
35         protected $id;
36
37         /**
38          * @ORM\Column(type="string", length=100)
39          */
40         protected $subject;
41
42         /**
43          * @ORM\Column(type="text")
44          */
45         protected $content;
46
47         /**
48          * @ORM\Column(type="integer", name="sent_to")
49          */
50         protected $sentTo = 0;
51
52         /**
53          * @ORM\ManyToOne(targetEntity="\Utility\Entity\Attachment")
54          * @ORM\JoinColumn(nullable=true, name="lib_attachment_id")
55          **/
56         protected $attachment;
57
58         /**
59          * @ORM\Column(type="string", length=25, nullable=true, name="previous_status");
60          */
61         protected $previousState;
62
63         /**
64          * @ORM\Column(type="string", length=25, nullable=true, name="status");
65          */
66         protected $jobState;
67
68         /**
69          * @ORM\Column(type="datetime");
70          */
71         protected $created;
72
73         /**
74          * @ORM\Column(type="datetime", nullable=true);
75          */
76         protected $updated;
77
78         /**
79          * @ORM\Column(type="boolean");
80          */
81         protected $archived = false;
82
83
84         /**
85          * Magic getter to expose protected properties.
86          * @param string $property
87          * @return mixed
88          */
89         public function __get($property)
90         {
91                 return $this->$property;
92         }
93
94         /**
95          * Magic setter to save protected properties.
96          * @param string $property
97          * @param mixed $value
98          */
99         public function __set($property, $value)
100         {
101                 $this->$property = $value;
102         }
103
104         /**
105          * @ORM\PrePersist
106          */
107         public function setCreateTime()
108         {
109                 $this->created = new \DateTime("now");
110         }
111
112         /**
113          * @ORM\PreUpdate
114          */
115         public function setUpdateTime()
116         {
117                 $this->updated = new \DateTime("now");
118         }
119
120         /**
121          * Convert the object to an array.
122          * @param array $expand
123          * @return array
124          */
125         public function toArray(array $expand = array('attachment'))
126         {
127                 return array(
128                                 'id'         => $this->id,
129                                 'subject'    => $this->subject,
130                                 'content'    => $this->content,
131                                 'sentTo'     => $this->sentTo,
132                                 'attachment' => in_array('attachment', $expand)
133                                                                                 && !is_null($this->attachment)
134                                         ? $this->attachment->toArray($expand)
135                                         : null,
136                                 'jobState'   => $this->jobState,
137                                 'created'    => !is_null($this->created)
138                                         ? $this->created->format(\Utility\Registry::getConfigParam('DateTimeFormat'))
139                                         : null,
140                                 'updated'    => !is_null($this->updated)
141                                         ? $this->updated->format(\Utility\Registry::getConfigParam('DateTimeFormat'))
142                                         : null
143                 );
144         }
145
146         /**
147          * Populate from an array.
148          * @param array $data
149          */
150         public function fromArray($data = array())
151         {
152                 isset($data['id'])
153                         && $this->id = $data['id'];
154                 isset($data['subject'])
155                         && $this->subject  = $data['subject'];
156                 isset($data['content'])
157                         && $this->content  = $data['content'];
158                 isset($data['sentTo'])
159                         && $this->sentTo  = $data['sentTo'];
160                 isset($data['attachment'])
161                         && $this->attachment  = $data['attachment'];
162         }
163
164 }