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