| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Export Settings UI. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Export_Settings |
| 6 |
* @author David Bisset |
| 7 |
* @copyright Copyright (c) 2022, WP Charitable LLC |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 1.7.0.7 |
| 10 |
* @version 1.6.0 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
if ( ! class_exists( 'Charitable_Export_Settings' ) ) : |
| 19 |
|
| 20 |
/** |
| 21 |
* Charitable_Export_Settings |
| 22 |
* |
| 23 |
* @since 1.6.0 |
| 24 |
*/ |
| 25 |
final class Charitable_Export_Settings { |
| 26 |
|
| 27 |
/** |
| 28 |
* The single instance of this class. |
| 29 |
* |
| 30 |
* @since 1.6.0 |
| 31 |
* |
| 32 |
* @var Charitable_Export_Settings|null |
| 33 |
*/ |
| 34 |
private static $instance = null; |
| 35 |
|
| 36 |
/** |
| 37 |
* Create object instance. |
| 38 |
* |
| 39 |
* @since 1.6.0 |
| 40 |
*/ |
| 41 |
private function __construct() { |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Returns and/or create the single instance of this class. |
| 46 |
* |
| 47 |
* @since 1.6.0 |
| 48 |
* |
| 49 |
* @return Charitable_Export_Settings |
| 50 |
*/ |
| 51 |
public static function get_instance() { |
| 52 |
if ( is_null( self::$instance ) ) { |
| 53 |
self::$instance = new self(); |
| 54 |
} |
| 55 |
|
| 56 |
return self::$instance; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Return the list of user donation field options. |
| 61 |
* |
| 62 |
* @since 1.6.0 |
| 63 |
* |
| 64 |
* @return string[] |
| 65 |
*/ |
| 66 |
protected function get_user_donation_field_options() { |
| 67 |
$fields = charitable()->donation_fields()->get_data_type_fields( 'user' ); |
| 68 |
|
| 69 |
return array_combine( |
| 70 |
array_keys( $fields ), |
| 71 |
wp_list_pluck( $fields, 'label' ) |
| 72 |
); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Return the list of user donation field options. |
| 77 |
* |
| 78 |
* @since 1.7.0.7 |
| 79 |
* |
| 80 |
* @return string[] |
| 81 |
*/ |
| 82 |
protected function get_campaigns_to_export( $include_donations = false ) { |
| 83 |
|
| 84 |
$campaigns = array(); |
| 85 |
|
| 86 |
$args = array( |
| 87 |
'posts_per_page' => -1, |
| 88 |
'orderby' => 'post_title', |
| 89 |
'order' => 'ASC', |
| 90 |
'fields' => array('post_title', 'ID') |
| 91 |
); |
| 92 |
|
| 93 |
$results = Charitable_Campaigns::query( $args ); |
| 94 |
|
| 95 |
if ( empty( $results->posts ) ) { |
| 96 |
return array(); |
| 97 |
} |
| 98 |
|
| 99 |
foreach ( $results->posts as $index => $post ) : |
| 100 |
$campaigns[ $post->ID ] = $post->post_title; |
| 101 |
if ( $include_donations ) { |
| 102 |
$donations = charitable_get_table( 'campaign_donations' )->get_donations_on_campaign( $post->ID ); |
| 103 |
$donation_count = count( $donations ); |
| 104 |
$plural = ( ( $donation_count ) > 1 ) ? 's' : ''; |
| 105 |
$campaigns[ $post->ID ] = $post->post_title . ' (' . count( $donations ) . ' donation' . $plural . ') '; |
| 106 |
} |
| 107 |
endforeach; |
| 108 |
|
| 109 |
return( $campaigns ); |
| 110 |
|
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
endif; |
| 115 |
|