PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
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 2.31.0 2.31.1 All 253 releases
give / src / TestData / Repositories / DonationFormRepository.php

DonationFormRepository.php in GiveWP – Donation Plugin and Fundraising Platform 4.1.0, at src/TestData/Repositories/DonationFormRepository.php

109 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\TestData\Repositories;
4
5 use Give\TestData\Factories\DonationFormFactory;
6 use Give\TestData\Framework\MetaRepository;
7
8 class DonationFormRepository
9 {
10
11 /**
12 * @var DonationFormFactory
13 */
14 private $donationFormFactory;
15
16 public function __construct(DonationFormFactory $donationFormFactory)
17 {
18 $this->donationFormFactory = $donationFormFactory;
19 }
20
21 /**
22 * @param array $form
23 */
24 public function insertDonationForm($form)
25 {
26 global $wpdb;
27
28 $form = wp_parse_args(
29 apply_filters('give-test-data-form-definition', $form),
30 $this->donationFormFactory->definition()
31 );
32
33 // Insert donation
34 $wpdb->insert(
35 "{$wpdb->prefix}posts",
36 [
37 'post_type' => 'give_forms',
38 'post_title' => $form['post_title'],
39 'post_name' => $form['post_name'],
40 'post_date' => $form['post_date'],
41 'post_author' => $form['post_author'],
42 'post_status' => 'publish',
43 ]
44 );
45
46 $formId = $wpdb->insert_id;
47
48 $metaRepository = new MetaRepository('give_formmeta', 'form_id');
49
50 $formMeta = [
51 '_give_form_status' => 'open',
52 '_give_form_template' => $form['form_template'],
53 '_give_levels_minimum_amount' => '10.000000',
54 '_give_levels_maximum_amount' => '250.000000',
55 '_give_set_price' => $form['random_amount'],
56 "_give_{$form['form_template']}_form_template_settings" => serialize(
57 [
58 'introduction' => [
59 'enabled' => 'enabled',
60 'headline' => $form['post_title'],
61 'description' => 'Help our organization by donating today! All donations go directly to making a difference for our cause.',
62 'image' => '',
63 'primary_color' => '#28C77B',
64 'donate_label' => 'Donate Now',
65 ],
66 'payment_amount' => [
67 'header_label' => 'Choose Amount',
68 'content' => '',
69 'next_label' => 'Continue',
70 ],
71 'payment_information' => [
72 'header_label' => 'Add Your Information',
73 'headline' => "Who's giving today?",
74 'description' => 'We’ll never share this information with anyone.',
75 'checkout_label' => 'Donate Now',
76 ],
77 'thank-you' => [
78 'image' => '',
79 'headline' => 'A great big thank you!',
80 'description' => '{name}, your contribution means a lot and will be put to good use in making a difference. We’ve sent your donation receipt to {donor_email}.',
81 'sharing' => 'enabled',
82 'sharing_instruction' => 'Help spread the word by sharing your support with your friends and followers!',
83 'twitter_message' => "I just gave to this cause . Who's next?",
84 ],
85 ]
86 ),
87 ];
88
89 // Generate terms and conditions
90 if ( ! empty($form['donation_terms'])) {
91 $formMeta['_give_terms_option'] = 'enabled';
92 $formMeta['_give_agree_label'] = $form['donation_terms']['label'];
93 $formMeta['_give_agree_text'] = $form['donation_terms']['text'];
94 }
95
96 // Set donation goal
97 if ($form['donation_goal']) {
98 $formMeta['_give_goal_option'] = 'enabled';
99 $formMeta['_give_goal_format'] = 'amount';
100 $formMeta['_give_set_goal'] = $form['donation_goal'];
101 }
102
103 // Insert meta
104 $metaRepository->persist($formId, $formMeta);
105
106 do_action('give-test-data-insert-donation-form', $formId, $form);
107 }
108 }
109