| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Subscriptions\DataTransferObjects; |
| 4 |
|
| 5 |
use DateTime; |
| 6 |
use Give\Framework\Support\Facades\DateTime\Temporal; |
| 7 |
use Give\Subscriptions\Models\SubscriptionNote; |
| 8 |
use Give\Subscriptions\ValueObjects\SubscriptionNoteType; |
| 9 |
|
| 10 |
/** |
| 11 |
* Class SubscriptionNoteQueryData |
| 12 |
* |
| 13 |
* @since 4.8.0 |
| 14 |
*/ |
| 15 |
final class SubscriptionNoteQueryData |
| 16 |
{ |
| 17 |
/** |
| 18 |
* @var int |
| 19 |
*/ |
| 20 |
public $id; |
| 21 |
/** |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
public $content; |
| 25 |
/** |
| 26 |
* @var int |
| 27 |
*/ |
| 28 |
public $subscriptionId; |
| 29 |
/** |
| 30 |
* @var SubscriptionNoteType |
| 31 |
*/ |
| 32 |
public $type; |
| 33 |
/** |
| 34 |
* @var DateTime |
| 35 |
*/ |
| 36 |
public $createdAt; |
| 37 |
|
| 38 |
/** |
| 39 |
* Convert data from Subscription Note Object to Subscription Note Model |
| 40 |
* |
| 41 |
* @since 4.8.0 |
| 42 |
*/ |
| 43 |
public static function fromObject($subscriptionNoteQueryObject): self |
| 44 |
{ |
| 45 |
$self = new static(); |
| 46 |
|
| 47 |
$self->id = (int)$subscriptionNoteQueryObject->id; |
| 48 |
$self->content = $subscriptionNoteQueryObject->content; |
| 49 |
$self->subscriptionId = (int)$subscriptionNoteQueryObject->subscriptionId; |
| 50 |
$self->type = $subscriptionNoteQueryObject->type ? new SubscriptionNoteType($subscriptionNoteQueryObject->type) : SubscriptionNoteType::ADMIN(); |
| 51 |
$self->createdAt = Temporal::toDateTime($subscriptionNoteQueryObject->createdAt); |
| 52 |
|
| 53 |
return $self; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Convert DTO to Subscription Note |
| 58 |
* |
| 59 |
* @since 4.8.0 |
| 60 |
*/ |
| 61 |
public function toSubscriptionNote(): SubscriptionNote |
| 62 |
{ |
| 63 |
$attributes = get_object_vars($this); |
| 64 |
|
| 65 |
return new SubscriptionNote($attributes); |
| 66 |
} |
| 67 |
} |
| 68 |
|