| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * @package VikBooking |
| 4 | 4 | * @subpackage core |
| 5 | 5 | * @author E4J s.r.l. |
| 6 | - * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. | |
| 6 | + * @copyright Copyright (C) 2026 E4J s.r.l. All Rights Reserved. | |
| 7 | 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | 8 | * @link https://vikwp.com |
| 9 | 9 | */ |
| 10 | 10 | |
| @@ -75,8 +75,16 @@ | ||
| 75 | 75 | */ |
| 76 | 76 | protected $createdby; |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | + * The ID of the external resource this message is linked to. | |
| 80 | + * | |
| 81 | + * @var string | |
| 82 | + * @since 1.8.8 | |
| 83 | + */ | |
| 84 | + protected $ref_id = null; | |
| 85 | + | |
| 86 | + /** | |
| 79 | 87 | * Whether the message has been read by the user. |
| 80 | 88 | * |
| 81 | 89 | * @var bool |
| 82 | 90 | */ |
| @@ -286,15 +294,20 @@ | ||
| 286 | 294 | */ |
| 287 | 295 | public function setCreationDate($date) |
| 288 | 296 | { |
| 289 | 297 | try { |
| 290 | - if (is_string($date)) { | |
| 298 | + if (!$date instanceof DateTime) { | |
| 291 | 299 | // make sure the provided date is correct |
| 292 | - $date = JFactory::getDate($date); | |
| 300 | + $date = JFactory::getDate($date ?: 'now'); | |
| 293 | 301 | } |
| 294 | 302 | |
| 295 | 303 | // convert date object into a string |
| 296 | 304 | $date = $date->toSql(); |
| 305 | + | |
| 306 | + // make sure the specified date is not in the future | |
| 307 | + if ($date > JFactory::getDate()->toSql()) { | |
| 308 | + throw new UnexpectedValueException('Cannot accept a date in the future.', 400); | |
| 309 | + } | |
| 297 | 310 | } catch (Exception $error) { |
| 298 | 311 | // malformed date |
| 299 | 312 | $date = null; |
| 300 | 313 | } |
| @@ -318,8 +331,36 @@ | ||
| 318 | 331 | return $this->createdby; |
| 319 | 332 | } |
| 320 | 333 | |
| 321 | 334 | /** |
| 335 | + * Returns the ID of the external resource this message is linked to. | |
| 336 | + * | |
| 337 | + * @return string|null | |
| 338 | + * | |
| 339 | + * @since 1.8.8 | |
| 340 | + */ | |
| 341 | + public function getReferenceID() | |
| 342 | + { | |
| 343 | + return $this->ref_id; | |
| 344 | + } | |
| 345 | + | |
| 346 | + /** | |
| 347 | + * Sets the ID of the external resource this message is linked to. | |
| 348 | + * | |
| 349 | + * @param string|null $refId | |
| 350 | + * | |
| 351 | + * @return self | |
| 352 | + * | |
| 353 | + * @since 1.8.8 | |
| 354 | + */ | |
| 355 | + public function setReferenceID(?string $refId) | |
| 356 | + { | |
| 357 | + $this->ref_id = $refId; | |
| 358 | + | |
| 359 | + return $this; | |
| 360 | + } | |
| 361 | + | |
| 362 | + /** | |
| 322 | 363 | * Checks whether the message has been read by the current user. |
| 323 | 364 | * |
| 324 | 365 | * @return bool |
| 325 | 366 | */ |
| @@ -346,7 +387,8 @@ | ||
| 346 | 387 | 'attachments' => $this->getAttachments(), |
| 347 | 388 | 'createdon' => $this->getCreationDate(), |
| 348 | 389 | 'createdby' => $this->getAuthor(), |
| 349 | 390 | 'read' => $this->isRead(), |
| 391 | + 'ref_id' => $this->ref_id, | |
| 350 | 392 | ]; |
| 351 | 393 | } |
| 352 | 394 | } |