| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\DonationForms\V2\Repositories; |
| 4 |
|
| 5 |
use Give\DonationForms\V2\Models\DonationForm; |
| 6 |
use Give\DonationForms\ValueObjects\DonationFormMetaKeys; |
| 7 |
use Give\DonationForms\V2\ValueObjects\DonationFormMetaKeys as LegacyDonationFormMetaKeys; |
| 8 |
use Give\DonationForms\ValueObjects\DonationFormStatus; |
| 9 |
use Give\Donations\Models\Donation; |
| 10 |
use Give\Framework\Models\ModelQueryBuilder; |
| 11 |
|
| 12 |
/** |
| 13 |
* @since 2.24.0 add support methods for donation form model |
| 14 |
* @since 2.19.0 |
| 15 |
*/ |
| 16 |
class DonationFormsRepository |
| 17 |
{ |
| 18 |
/** |
| 19 |
* Get DonationForm By ID |
| 20 |
* |
| 21 |
* @since 2.24.0 |
| 22 |
* |
| 23 |
* @return DonationForm|null |
| 24 |
*/ |
| 25 |
public function getById(int $donationFormId) |
| 26 |
{ |
| 27 |
return $this->prepareQuery() |
| 28 |
->where('ID', $donationFormId) |
| 29 |
->get(); |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* @since 2.24.0 |
| 34 |
* |
| 35 |
* @return ModelQueryBuilder<Donation> |
| 36 |
*/ |
| 37 |
public function prepareQuery(): ModelQueryBuilder |
| 38 |
{ |
| 39 |
$builder = new ModelQueryBuilder(DonationForm::class); |
| 40 |
|
| 41 |
return $builder->from('posts') |
| 42 |
->select( |
| 43 |
['ID', 'id'], |
| 44 |
['post_title', 'title'], |
| 45 |
['post_date', 'createdAt'], |
| 46 |
['post_modified', 'updatedAt'], |
| 47 |
['post_status', 'status'] |
| 48 |
) |
| 49 |
->attachMeta( |
| 50 |
'give_formmeta', |
| 51 |
'ID', |
| 52 |
'form_id', |
| 53 |
...DonationFormMetaKeys::getColumnsForAttachMetaQuery(), |
| 54 |
...LegacyDonationFormMetaKeys::getColumnsForAttachMetaQuery() |
| 55 |
) |
| 56 |
->where('post_type', 'give_forms') |
| 57 |
->whereIn('post_status', DonationFormStatus::toArray()); |
| 58 |
} |
| 59 |
} |
| 60 |
|