Example #1
0
function seamless_donations_create_donation_from_transaction_audit_table($transaction_form_data)
{
    // Create a new donation record
    $donation_id = dgx_donate_create_empty_donation_record();
    $meta_map = dgx_donate_get_meta_map();
    foreach ((array) $meta_map as $transaction_form_data_key => $postmeta_key) {
        if ($transaction_form_data[$transaction_form_data_key] != '') {
            // using switch so new special cases are easier to add
            switch ($postmeta_key) {
                case '_dgx_donate_designated_fund':
                    // save fund data from transaction into the donation record
                    if ($transaction_form_data[$transaction_form_data_key] != 0) {
                        $fund_id = $transaction_form_data[$transaction_form_data_key];
                        // lookup the fund name from the id and save into the post meta data
                        $fund_name = get_the_title($fund_id);
                        update_post_meta($donation_id, '_dgx_donate_designated_fund', $fund_name);
                        // update the donation record with the fund id -- also link the funds to the donations
                        update_post_meta($donation_id, '_dgx_donate_designated_fund_id', $fund_id);
                        // update the donations list to point to this donation id
                        seamless_donations_add_donation_id_to_fund($fund_id, $donation_id);
                        // update the donation total for the fund
                        seamless_donations_add_donation_amount_to_fund_total($donation_id, $fund_id);
                    }
                    break;
                default:
                    update_post_meta($donation_id, $postmeta_key, $transaction_form_data[$transaction_form_data_key]);
            }
        }
    }
    $donor_id = seamless_donations_update_donor_data($donation_id);
    $email = get_post_meta($donation_id, '_dgx_donate_donor_email', true);
    if ($email !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_email', $email);
    }
    $employer = get_post_meta($donation_id, '_dgx_donate_employer_name', true);
    if ($employer !== false) {
        update_post_meta($donor_id, '_dgx_donate_employer_name', $employer);
    }
    $occupation = get_post_meta($donation_id, '_dgx_donate_occupation', true);
    if ($occupation !== false) {
        update_post_meta($donor_id, '_dgx_donate_occupation', $occupation);
    }
    $phone = get_post_meta($donation_id, '_dgx_donate_donor_phone', true);
    if ($phone !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_phone', $phone);
    }
    $address = get_post_meta($donation_id, '_dgx_donate_donor_address', true);
    if ($address !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_address', $address);
    }
    $address2 = get_post_meta($donation_id, '_dgx_donate_donor_address2', true);
    if ($address2 !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_address2', $address2);
    }
    $city = get_post_meta($donation_id, '_dgx_donate_donor_city', true);
    if ($city !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_city', $city);
    }
    $state = get_post_meta($donation_id, '_dgx_donate_donor_state', true);
    if ($state !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_state', $state);
    }
    $province = get_post_meta($donation_id, '_dgx_donate_donor_province', true);
    if ($province !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_province', $province);
    }
    $country = get_post_meta($donation_id, '_dgx_donate_donor_country', true);
    if ($country !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_country', $country);
    }
    $zip = get_post_meta($donation_id, '_dgx_donate_donor_zip', true);
    if ($zip !== false) {
        update_post_meta($donor_id, '_dgx_donate_donor_zip', $zip);
    }
    $anon = get_post_meta($donation_id, '_dgx_donate_anonymous', true);
    if ($anon == 'on') {
        update_post_meta($donor_id, '_dgx_donate_anonymous', 'yes');
    }
    return $donation_id;
}
Example #2
0
function seamless_donations_rebuild_funds_index()
{
    // first clear out the donations meta items
    $args = array('post_type' => 'funds', 'post_status' => 'publish', 'nopaging' => 'true');
    $posts_array = get_posts($args);
    // loop through a list of funds
    for ($i = 0; $i < count($posts_array); ++$i) {
        // extract the fund id from the donation and fund records
        $fund_id = $posts_array[$i]->ID;
        delete_post_meta($fund_id, '_dgx_donate_donor_donations');
        delete_post_meta($fund_id, '_dgx_donate_fund_total');
    }
    // then loop through the donations
    $args = array('post_type' => 'donation', 'post_status' => 'publish', 'nopaging' => 'true');
    $posts_array = get_posts($args);
    // loop through a list of donations with funds attached
    for ($i = 0; $i < count($posts_array); ++$i) {
        // extract the fund id from the donation and fund records
        $donation_id = $posts_array[$i]->ID;
        $fund_name = get_post_meta($donation_id, '_dgx_donate_designated_fund', true);
        if ($fund_name != '') {
            // todo need additional code to go in and reconstruct ids based on possible new names
            $fund = get_page_by_title($fund_name, 'OBJECT', 'funds');
            $fund_id = $fund->ID;
            // update the donation record with the fund id -- also link the funds to the donations
            update_post_meta($donation_id, '_dgx_donate_designated_fund_id', $fund_id);
            // update the donations list to point to this donation id
            seamless_donations_add_donation_id_to_fund($fund_id, $donation_id);
            // update the donation total for the fund
            seamless_donations_add_donation_amount_to_fund_total($donation_id, $fund_id);
        }
    }
}