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