PluginProbe
The Innovative Form Builder – IvyForms / 0.3
The Innovative Form Builder – IvyForms v0.3
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Entity / Entry / Entry.php

Entry.php in The Innovative Form Builder – IvyForms 0.3, at backend/src/Entity/Entry/Entry.php

265 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace IvyForms\Entity\Entry;
9
10 // phpcs:disable PSR1.Files.SideEffects
11 if (!defined('ABSPATH')) {
12 exit; // Exit if accessed directly
13 }
14
15 use IvyForms\Entity\EntryField\EntryField;
16 use IvyForms\Repository\Entry\EntryRequestHelper;
17 use IvyForms\ValueObjects\Entry\Entry as EntryValueObject;
18
19 /**
20 * Class Entry
21 *
22 * @package IvyForms\Entity\Entry
23 */
24 class Entry
25 {
26 public const DEFAULT_STATUS = 'unread';
27
28 /**
29 * @var EntryValueObject
30 */
31 private EntryValueObject $entry;
32
33 /**
34 * Entry constructor.
35 *
36 * @param EntryValueObject $entry The entry object.
37 */
38 public function __construct(EntryValueObject $entry)
39 {
40 $this->entry = $entry;
41 }
42
43 /**
44 * Get the ID of the entry.
45 *
46 * @return int The entry ID.
47 */
48 public function getId(): int
49 {
50 return $this->entry->getId();
51 }
52
53 /**
54 * Set the ID of the entry.
55 *
56 * @param int $entryId The entry ID to set.
57 */
58 public function setId(int $entryId): void
59 {
60 $this->entry->id = $entryId;
61 }
62
63 /**
64 * Get the form ID associated with the entry.
65 *
66 * @return int The form ID.
67 */
68 public function getFormId(): int
69 {
70 return $this->entry->getFormId();
71 }
72
73 /**
74 * Set the form ID associated with the entry.
75 *
76 * @param int $formId The form ID to set.
77 */
78 public function setFormId(int $formId): void
79 {
80 $this->entry->formId = $formId;
81 }
82
83 /**
84 * Get the user ID associated with the entry.
85 *
86 * @return int|null The user ID or null if not set.
87 */
88 public function getUserId(): ?int
89 {
90 return $this->entry->getUserId();
91 }
92
93 /**
94 * Set the user ID associated with the entry.
95 *
96 * @param int|null $userId The user ID to set.
97 */
98 public function setUserId(?int $userId): void
99 {
100 $this->entry->userId = $userId;
101 }
102
103 /**
104 * Get the date the entry was created.
105 *
106 * @return string The date the entry was created.
107 */
108 public function getDateCreated(): string
109 {
110 return $this->entry->getDateCreated();
111 }
112
113 /**
114 * Get the date the entry was last edited.
115 *
116 * @return string|null The date the entry was last edited or null if not set.
117 */
118 public function getDateEdited(): ?string
119 {
120 return $this->entry->getDateEdited();
121 }
122
123 /**
124 * Get the status of the entry.
125 *
126 * @return string The status of the entry.
127 */
128 public function getStatus(): string
129 {
130 return $this->entry->getStatus();
131 }
132
133 /**
134 * Set the status of the entry.
135 *
136 * @param string $status The status to set.
137 */
138 public function setStatus(string $status): void
139 {
140 $this->entry->status = $status;
141 }
142
143 /**
144 * Get the IP address associated with the entry.
145 *
146 * @return string|null The IP address or null if not set.
147 */
148 public function getIpAddress(): ?string
149 {
150 return $this->entry->getIpAddress();
151 }
152
153 /**
154 * Set the IP address associated with the entry.
155 *
156 * @param string|null $ipAddress The IP address to set.
157 */
158 public function setIpAddress(?string $ipAddress): void
159 {
160 $this->entry->ipAddress = $ipAddress;
161 }
162
163 /**
164 * Get the user agent associated with the entry.
165 *
166 * @return string|null The user agent or null if not set.
167 */
168 public function getUserAgent(): ?string
169 {
170 return $this->entry->getUserAgent();
171 }
172 /**
173 * Set the user agent associated with the entry.
174 *
175 * @param string|null $userAgent The user agent to set.
176 */
177 public function setUserAgent(?string $userAgent): void
178 {
179 $this->entry->userAgent = $userAgent;
180 }
181
182 /**
183 * Get the source URL of the entry.
184 *
185 * @return string|null The source URL or null if not set.
186 */
187 public function getSourceURL(): ?string
188 {
189 return $this->entry->getSourceURL();
190 }
191
192 /**
193 * Set the source URL of the entry.
194 *
195 * @param string|null $sourceURL The source URL to set.
196 */
197 public function setSourceURL(?string $sourceURL): void
198 {
199 $this->entry->sourceURL = $sourceURL;
200 }
201
202 /**
203 * Set the starred status of the entry.
204 *
205 * @param bool $starred True if the entry is starred, false otherwise.
206 */
207 public function setStarred(bool $starred): void
208 {
209 $this->entry->starred = $starred;
210 }
211
212 /**
213 * Check if the entry is starred.
214 *
215 * @return bool True if the entry is starred, false otherwise.
216 */
217 public function isStarred(): bool
218 {
219 return $this->entry->isStarred();
220 }
221
222 /**
223 * Convert the entry entity to an array for returning as a response.
224 *
225 * @return array<string, mixed> The form entity as an array.
226 */
227 public function toArray(): array
228 {
229 return [
230 'id' => $this->getId(),
231 'formId' => $this->getFormId(),
232 'userId' => $this->getUserId(),
233 'author' => get_userdata($this->getUserId())->user_nicename ?? '',
234 'dateCreated' => $this->getDateCreated(),
235 'dateEdited' => $this->getDateEdited(),
236 'status' => $this->getStatus(),
237 'ipAddress' => $this->getIpAddress(),
238 'userAgent' => EntryRequestHelper::getBrowserName($this->getUserAgent()),
239 'sourceURL' => $this->getSourceURL(),
240 'starred' => $this->isStarred(),
241 ];
242 }
243 /**
244 * Convert the entry entity to an array for inserting into the database.
245 *
246 * @return array<string, mixed> The form entity as an array.
247 */
248 public function getData(): array
249 {
250 return [
251 'id' => $this->getId(),
252 'formId' => $this->getFormId(),
253 'userId' => $this->getUserId(),
254 'author' => get_userdata($this->getUserId())->user_nicename ?? '',
255 'dateCreated' => $this->getDateCreated(),
256 'dateEdited' => $this->getDateEdited(),
257 'status' => $this->getStatus(),
258 'ipAddress' => $this->getIpAddress(),
259 'userAgent' => $this->getUserAgent(),
260 'sourceURL' => $this->getSourceURL(),
261 'starred' => $this->isStarred(),
262 ];
263 }
264 }
265