PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / DonationForms / V2 / Repositories / DonationFormsRepository.php

DonationFormsRepository.php in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/DonationForms/V2/Repositories/DonationFormsRepository.php

60 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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