PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 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 All 257 releases
give / src / DonationForms / V2 / Repositories / DonationFormsRepository.php

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

61 lines 1.7 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 4.18.0 Alias the posts table so grouped queries can qualify columns (e.g. GROUP BY forms.ID).
34 * @since 2.24.0
35 *
36 * @return ModelQueryBuilder<Donation>
37 */
38 public function prepareQuery(): ModelQueryBuilder
39 {
40 $builder = new ModelQueryBuilder(DonationForm::class);
41
42 return $builder->from('posts', 'forms')
43 ->select(
44 ['ID', 'id'],
45 ['post_title', 'title'],
46 ['post_date', 'createdAt'],
47 ['post_modified', 'updatedAt'],
48 ['post_status', 'status']
49 )
50 ->attachMeta(
51 'give_formmeta',
52 'ID',
53 'form_id',
54 ...DonationFormMetaKeys::getColumnsForAttachMetaQuery(),
55 ...LegacyDonationFormMetaKeys::getColumnsForAttachMetaQuery()
56 )
57 ->where('post_type', 'give_forms')
58 ->whereIn('post_status', DonationFormStatus::toArray());
59 }
60 }
61