AuthenticationData.php
2 years ago
DonateControllerData.php
2 years ago
DonateFormRouteData.php
1 year ago
DonateRouteData.php
2 years ago
DonationConfirmationReceiptViewRouteData.php
2 years ago
DonationFormGoalData.php
2 years ago
DonationFormPreviewRouteData.php
2 years ago
DonationFormQueryData.php
2 years ago
DonationFormViewRouteData.php
2 years ago
LegacyPurchaseFormData.php
2 years ago
UserData.php
2 years ago
ValidationRouteData.php
2 years ago
DonationFormQueryData.php
84 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonationForms\DataTransferObjects; |
| 4 | |
| 5 | use DateTimeInterface; |
| 6 | use Give\DonationForms\Models\DonationForm; |
| 7 | use Give\DonationForms\ValueObjects\DonationFormMetaKeys; |
| 8 | use Give\DonationForms\ValueObjects\DonationFormStatus; |
| 9 | use Give\Framework\Blocks\BlockCollection; |
| 10 | use Give\Framework\Support\Facades\DateTime\Temporal; |
| 11 | |
| 12 | class DonationFormQueryData |
| 13 | { |
| 14 | /** |
| 15 | * @var int |
| 16 | */ |
| 17 | public $id; |
| 18 | |
| 19 | /** |
| 20 | * @var string |
| 21 | */ |
| 22 | public $title; |
| 23 | |
| 24 | /** |
| 25 | * @var array |
| 26 | */ |
| 27 | public $settings; |
| 28 | |
| 29 | /** |
| 30 | * @var DateTimeInterface |
| 31 | */ |
| 32 | public $createdAt; |
| 33 | |
| 34 | /** |
| 35 | * @var DateTimeInterface |
| 36 | */ |
| 37 | public $updatedAt; |
| 38 | |
| 39 | /** |
| 40 | * @var DonationFormStatus |
| 41 | */ |
| 42 | public $status; |
| 43 | |
| 44 | /** |
| 45 | * @var BlockCollection |
| 46 | */ |
| 47 | public $blocks; |
| 48 | |
| 49 | /** |
| 50 | * Convert data from object to Donation Form |
| 51 | * |
| 52 | * @since 3.0.0 |
| 53 | * |
| 54 | * @param object $queryObject |
| 55 | * |
| 56 | * @return DonationFormQueryData |
| 57 | */ |
| 58 | public static function fromObject($queryObject): self |
| 59 | { |
| 60 | $self = new self(); |
| 61 | $self->id = (int)$queryObject->id; |
| 62 | $self->title = $queryObject->title; |
| 63 | $self->createdAt = Temporal::toDateTime($queryObject->createdAt); |
| 64 | $self->updatedAt = Temporal::toDateTime($queryObject->updatedAt); |
| 65 | $self->status = new DonationFormStatus($queryObject->status); |
| 66 | $self->settings = json_decode($queryObject->{DonationFormMetaKeys::SETTINGS()->getKeyAsCamelCase()}, true); |
| 67 | $self->blocks = BlockCollection::fromJson($queryObject->blocks); |
| 68 | |
| 69 | return $self; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Convert DTO to Donation Form |
| 74 | * |
| 75 | * @return DonationForm |
| 76 | */ |
| 77 | public function toDonationForm(): DonationForm |
| 78 | { |
| 79 | $attributes = get_object_vars($this); |
| 80 | |
| 81 | return new DonationForm($attributes); |
| 82 | } |
| 83 | } |
| 84 |