1 : <?php
2 : class Application_Model_GuestbookEntry
3 1 : {
4 :
5 :
6 :
7 : protected $_fullName;
8 :
9 :
10 :
11 : protected $_emailAddress;
12 :
13 :
14 :
15 : protected $_website;
16 :
17 :
18 :
19 : protected $_comment;
20 :
21 :
22 :
23 : protected $_timestamp;
24 :
25 :
26 :
27 : protected $_mapper;
28 :
29 :
30 :
31 :
32 :
33 :
34 : public function __construct($params = null)
35 : {
36 6 : if (null !== $params) {
37 3 : $this->populate($params);
38 3 : }
39 6 : }
40 :
41 :
42 :
43 :
44 :
45 :
46 : public function setFullName ($fullName)
47 : {
48 4 : $this->_fullName = (string) $fullName;
49 4 : return $this;
50 : }
51 :
52 :
53 :
54 :
55 :
56 : public function getFullName()
57 : {
58 5 : return $this->_fullName;
59 : }
60 :
61 :
62 :
63 :
64 :
65 :
66 : public function setEmailAddress($emailAddress)
67 : {
68 4 : $this->_emailAddress = (string) $emailAddress;
69 4 : return $this;
70 : }
71 :
72 :
73 :
74 :
75 :
76 : public function getEmailAddress()
77 : {
78 5 : return $this->_emailAddress;
79 : }
80 :
81 :
82 :
83 :
84 :
85 :
86 : public function setWebsite($website)
87 : {
88 4 : $this->_website = (string) $website;
89 4 : return $this;
90 : }
91 :
92 :
93 :
94 :
95 :
96 : public function getWebsite()
97 : {
98 5 : return $this->_website;
99 : }
100 :
101 :
102 :
103 :
104 :
105 :
106 : public function setComment($comment)
107 : {
108 4 : $this->_comment = (string) $comment;
109 4 : return $this;
110 : }
111 :
112 :
113 :
114 :
115 :
116 : public function getComment()
117 : {
118 5 : return $this->_comment;
119 : }
120 :
121 :
122 :
123 :
124 :
125 :
126 : public function setTimestamp($timestamp)
127 : {
128 4 : $this->_timestamp = $timestamp;
129 4 : return $this;
130 : }
131 :
132 :
133 :
134 :
135 :
136 : public function getTimestamp()
137 : {
138 5 : return $this->_timestamp;
139 : }
140 :
141 :
142 :
143 :
144 :
145 : public function populate($row)
146 : {
147 3 : if (is_array($row)) {
148 3 : $row = new ArrayObject($row, ArrayObject::ARRAY_AS_PROPS);
149 3 : }
150 3 : if (isset ($row->fullName)) { $this->setFullName($row->fullName); }
151 3 : if (isset ($row->emailAddress)) { $this->setEmailAddress($row->emailAddress); }
152 3 : if (isset ($row->website)) { $this->setWebsite($row->website); }
153 3 : if (isset ($row->comment)) { $this->setComment($row->comment); }
154 3 : if (isset ($row->timestamp)) { $this->setTimestamp($row->timestamp); }
155 3 : }
156 :
157 :
158 :
159 :
160 :
161 : public function __toArray()
162 : {
163 : return array (
164 3 : 'fullName' => $this->getFullName(),
165 3 : 'emailAddress' => $this->getEmailAddress(),
166 3 : 'website' => $this->getWebsite(),
167 3 : 'comment' => $this->getComment(),
168 3 : 'timestamp' => $this->getTimestamp(),
169 3 : );
170 : }
171 :
172 :
173 :
174 :
175 :
176 :
177 : public function __set($name, $value)
178 : {
179 0 : $method = 'set' . ucFirst($name);
180 0 : if (method_exists($this, $method)) {
181 0 : $this->$method($value);
182 0 : }
183 0 : }
184 :
185 :
186 :
187 :
188 :
189 :
190 : public function __get($name)
191 : {
192 0 : $value = null;
193 0 : $method = 'get' . ucfirst($name);
194 0 : if (method_exists($this, $method)) {
195 0 : $value = $this->$method();
196 0 : }
197 0 : return $value;
198 : }
199 :
200 :
201 :
202 :
203 :
204 :
205 :
206 : public function setMapper($mapper)
207 : {
208 1 : if (is_string($mapper)) {
209 1 : if (!class_exists($mapper)) {
210 0 : throw new RuntimeException('Invalid mapper provided');
211 : }
212 1 : $mapper = new $mapper;
213 1 : }
214 1 : $this->_mapper = $mapper;
215 1 : return $this;
216 : }
217 :
218 :
219 :
220 :
221 :
222 : public function getMapper()
223 : {
224 1 : if (null === $this->_mapper) {
225 1 : $this->setMapper('Application_Model_Mapper_GuestbookEntry');
226 1 : }
227 1 : return $this->_mapper;
228 : }
229 :
230 :
231 :
232 :
233 :
234 :
235 : public function fetchRow($where = null, $order = null)
236 : {
237 0 : $this->getMapper()->fetchRow($this, $where, $order);
238 0 : }
239 :
240 :
241 :
242 : public function save()
243 : {
244 1 : $this->getMapper()->save($this);
245 1 : }
246 : }
247 :
248 :
|