PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
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 1.0, at backend/src/Entity/Entry/Entry.php

249 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * Get the status of the entry.
129 *
130 * @return string The status of the entry.
131 */
132 public function getStatus(): string
133 {
134 return $this->entry->getStatus();
135 }
136
137 /**
138 * Set the status of the entry.
139 *
140 * @param string $status The status to set.
141 */
142 public function setStatus(string $status): void
143 {
144 $this->entry->status = $status;
145 }
146
147 /**
148 * Get the IP address associated with the entry.
149 *
150 * @return string|null The IP address or null if not set.
151 */
152 public function getIpAddress(): ?string
153 {
154 return $this->entry->getIpAddress();
155 }
156
157 /**
158 * Set the IP address associated with the entry.
159 *
160 * @param string|null $ipAddress The IP address to set.
161 */
162 public function setIpAddress(?string $ipAddress): void
163 {
164 $this->entry->ipAddress = $ipAddress;
165 }
166
167 /**
168 * Get the user agent associated with the entry.
169 *
170 * @return string|null The user agent or null if not set.
171 */
172 public function getUserAgent(): ?string
173 {
174 return $this->entry->getUserAgent();
175 }
176 /**
177 * Set the user agent associated with the entry.
178 *
179 * @param string|null $userAgent The user agent to set.
180 */
181 public function setUserAgent(?string $userAgent): void
182 {
183 $this->entry->userAgent = $userAgent;
184 }
185
186 /**
187 * Get the source URL of the entry.
188 *
189 * @return string|null The source URL or null if not set.
190 */
191 public function getSourceURL(): ?string
192 {
193 return $this->entry->getSourceURL();
194 }
195
196 /**
197 * Set the source URL of the entry.
198 *
199 * @param string|null $sourceURL The source URL to set.
200 */
201 public function setSourceURL(?string $sourceURL): void
202 {
203 $this->entry->sourceURL = $sourceURL;
204 }
205
206 /**
207 * Set the starred status of the entry.
208 *
209 * @param bool $starred True if the entry is starred, false otherwise.
210 */
211 public function setStarred(bool $starred): void
212 {
213 $this->entry->starred = $starred;
214 }
215
216 /**
217 * Check if the entry is starred.
218 *
219 * @return bool True if the entry is starred, false otherwise.
220 */
221 public function isStarred(): bool
222 {
223 return $this->entry->isStarred();
224 }
225
226 /**
227 * Convert the entry entity to an array.
228 *
229 * @param bool $raw If true, returns raw values (for DB), otherwise formatted for response.
230 * @return array<string, mixed> The form entity as an array.
231 */
232 public function toArray(bool $raw = false): array
233 {
234 return [
235 'id' => $this->getId(),
236 'formId' => $this->getFormId(),
237 'userId' => $this->getUserId(),
238 'author' => get_userdata($this->getUserId())->user_nicename ?? '',
239 'dateCreated' => $this->getDateCreated(),
240 'dateEdited' => $this->getDateEdited(),
241 'status' => $this->getStatus(),
242 'ipAddress' => $this->getIpAddress(),
243 'userAgent' => $raw ? $this->getUserAgent() : EntryHelper::getBrowserName($this->getUserAgent()),
244 'sourceURL' => $this->getSourceURL(),
245 'starred' => $this->isStarred(),
246 ];
247 }
248 }
249