| @@ -1,20 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * @copyright © TMS-Plugins. All rights reserved. | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | 5 | * @licence See LICENCE.md for license details. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace IvyForms\Entity\Entry; |
| 9 | 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; | |
| 10 | +use IvyForms\Common\Helpers\EntryHelper; | |
| 17 | 11 | use IvyForms\ValueObjects\Entry\Entry as EntryValueObject; |
| 18 | 12 | |
| 19 | 13 | /** |
| 20 | 14 | * Class Entry |
| @@ -110,8 +104,18 @@ | ||
| 110 | 104 | return $this->entry->getDateCreated(); |
| 111 | 105 | } |
| 112 | 106 | |
| 113 | 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 | + /** | |
| 114 | 118 | * Get the date the entry was last edited. |
| 115 | 119 | * |
| 116 | 120 | * @return string|null The date the entry was last edited or null if not set. |
| 117 | 121 | */ |
| @@ -120,8 +124,18 @@ | ||
| 120 | 124 | return $this->entry->getDateEdited(); |
| 121 | 125 | } |
| 122 | 126 | |
| 123 | 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 | + /** | |
| 124 | 138 | * Get the status of the entry. |
| 125 | 139 | * |
| 126 | 140 | * @return string The status of the entry. |
| 127 | 141 | */ |
| @@ -219,13 +233,14 @@ | ||
| 219 | 233 | return $this->entry->isStarred(); |
| 220 | 234 | } |
| 221 | 235 | |
| 222 | 236 | /** |
| 223 | - * Convert the entry entity to an array for returning as a response. | |
| 237 | + * Convert the entry entity to an array. | |
| 224 | 238 | * |
| 239 | + * @param bool $raw If true, returns raw values (for DB), otherwise formatted for response. | |
| 225 | 240 | * @return array<string, mixed> The form entity as an array. |
| 226 | 241 | */ |
| 227 | - public function toArray(): array | |
| 242 | + public function toArray(bool $raw = false): array | |
| 228 | 243 | { |
| 229 | 244 | return [ |
| 230 | 245 | 'id' => $this->getId(), |
| 231 | 246 | 'formId' => $this->getFormId(), |
| @@ -234,30 +249,9 @@ | ||
| 234 | 249 | 'dateCreated' => $this->getDateCreated(), |
| 235 | 250 | 'dateEdited' => $this->getDateEdited(), |
| 236 | 251 | 'status' => $this->getStatus(), |
| 237 | 252 | '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(), | |
| 253 | + 'userAgent' => $raw ? $this->getUserAgent() : EntryHelper::getBrowserName($this->getUserAgent()), | |
| 260 | 254 | 'sourceURL' => $this->getSourceURL(), |
| 261 | 255 | 'starred' => $this->isStarred(), |
| 262 | 256 | ]; |
| 263 | 257 | } |