/**
  * Return the number of people who have donated to the campaign.
  *
  * @return  int
  * @since   1.0.0
  */
 public function get_donor_count()
 {
     return charitable_get_table('campaign_donations')->count_campaign_donors($this->ID);
 }
示例#2
0
 * @since   1.0.0
 */
$widget_title = apply_filters('widget_title', $view_args['title']);
$campaigns_count = Charitable_Campaigns::query(array('posts_per_page' => -1, 'fields' => 'ids'))->found_posts;
$campaigns_text = $campaigns_count == 1 ? __('Campaign', 'charitable') : __('Campaigns', 'charitable');
echo $view_args['before_widget'];
if (!empty($widget_title)) {
    echo $view_args['before_title'] . $widget_title . $view_args['after_title'];
}
?>
<ul class="donation-stats">
    <li>
        <?php 
printf('<span class="figure">%d</span> %s', $campaigns_count, $campaigns_text);
?>
    </li>
    <li>                
        <?php 
printf('<span class="figure">%s</span> %s', charitable_get_currency_helper()->get_monetary_amount(charitable_get_table('campaign_donations')->get_total(), 0), __('Donated', 'charitable'));
?>
    </li>
    <li>
        <?php 
printf('<span class="figure">%d</span> %s', charitable_get_table('donors')->count_all(), __('Donors', 'charitable'));
?>
        
    </li>
</ul>

<?php 
echo $view_args['after_widget'];
 /**
  * Create class object.
  * 
  * @param 	mixed 	$benefactor
  * @access 	public
  * @since	1.0.0
  */
 public function __construct($benefactor)
 {
     if (!is_object($benefactor)) {
         $this->benefactor = charitable_get_table('benefactors')->get($benefactor);
     }
 }
示例#4
0
 /** 
  * @depends test_is_donor
  */
 public function test_is_donor_with_non_wpuser()
 {
     $donor_id = charitable_get_table('donors')->insert(array('email' => '*****@*****.**', 'first_name' => 'Fish', 'last_name' => 'Mooney'));
     $user = Charitable_User::init_with_donor($donor_id);
     $this->assertTrue($user->is_donor());
 }
示例#5
0
 function test_get_donations_db_call()
 {
     $this->assertCount(3, charitable_get_table('campaign_donations')->get_donations_on_campaign($this->campaign_1->ID), 'Testing call to campaign_donations table to retrieve campaign donations.');
     $this->assertCount(1, charitable_get_table('campaign_donations')->get_donations_on_campaign($this->campaign_2->ID), 'Testing call to campaign_donations table to retrieve campaign donations.');
 }
示例#6
0
<?php

/**
 * Display the donations widget on the dashboard. 
 *
 * @author  Studio 164a
 * @package Charitable/Admin View/Dashboard Widgets
 * @since   1.2.0
 */
$statuses = Charitable_Donation::get_valid_donation_statuses();
$donations = get_posts(array('post_type' => Charitable::DONATION_POST_TYPE, 'posts_per_page' => 5, 'post_status' => array_keys($statuses), 'fields' => 'ids'));
$table = charitable_get_table('campaign_donations');
$today = $table->get_donations_summary_by_period(date('Y-m-d%'));
$this_month = $table->get_donations_summary_by_period(date('Y-m%'));
$last_month = $table->get_donations_summary_by_period(date('Y-m%', strtotime('-1 month')));
$this_year = $table->get_donations_summary_by_period(date('Y-%'));
?>
<div class="charitable-donation-statistics">
    <div class="cell">
        <h3 class="amount"><?php 
echo charitable_format_money($today->amount);
?>
</h3>
        <p class="summary"><?php 
printf(_n('%d donation %stoday%s', '%d donations %stoday%s', $today->count, 'charitable'), $today->count, '<span class="time-period">', '</span>');
?>
</p>
    </div>
    <div class="cell">
        <h3 class="amount"><?php 
echo charitable_format_money($this_month->amount);
/**
 * Renders a benefactors addon metabox. Used by any plugin that utilizes the Benefactors Addon.
 *
 * @since       1.0.0
 * @author      Eric Daams
 * @package     Charitable/Admin Views/Metaboxes
 * @copyright   Copyright (c) 2015, Studio 164a 
 */
global $post;
if (!isset($view_args['extension'])) {
    _doing_it_wrong('charitable_campaign_meta_boxes', 'Campaign benefactors metabox requires an extension argument.', '1.0.0');
    return;
}
$extension = $view_args['extension'];
$benefactors = charitable_get_table('benefactors')->get_campaign_benefactors_by_extension($post->ID, $extension);
$ended = charitable_get_campaign($post->ID)->has_ended();
?>
<div class="charitable-metabox charitable-metabox-wrap">
    <?php 
if (empty($benefactors)) {
    if ($ended) {
        ?>

            <p><?php 
        _e('You did not add any contribution rules.', 'charitable');
        ?>
</p>

        <?php 
    } else {
 * @since   1.0.0
 */
$widget_title = apply_filters('widget_title', $view_args['title']);
$campaigns_count = Charitable_Campaigns::query(array('posts_per_page' => -1, 'fields' => 'ids'))->found_posts;
$campaigns_text = $campaigns_count == 1 ? __('Campaign', 'charitable') : __('Campaigns', 'charitable');
echo $view_args['before_widget'];
if (!empty($widget_title)) {
    echo $view_args['before_title'] . $widget_title . $view_args['after_title'];
}
?>
<ul class="donation-stats">
    <li>
        <?php 
printf('<span class="figure">%d</span> %s', $campaigns_count, $campaigns_text);
?>
    </li>
    <li>                
        <?php 
printf('<span class="figure">%s</span> %s', charitable_format_money(charitable_get_table('campaign_donations')->get_total(), 0), __('Donated', 'charitable'));
?>
    </li>
    <li>
        <?php 
printf('<span class="figure">%d</span> %s', charitable_get_table('donors')->count_donors_with_donations(), __('Donors', 'charitable'));
?>
        
    </li>
</ul>

<?php 
echo $view_args['after_widget'];
 /**
  * Get the data to be exported.
  *
  * @return  array
  * @access  protected
  * @since   1.0.0
  */
 protected function get_data()
 {
     $query_args = array();
     if (strlen($this->args['start_date'])) {
         $query_args['start_date'] = date('Y-m-d 00:00:00', strtotime($this->args['start_date']));
     }
     if (strlen($this->args['end_date'])) {
         $query_args['end_date'] = date('Y-m-d 00:00:00', strtotime($this->args['end_date']));
     }
     if ('all' != $this->args['campaign_id']) {
         $query_args['campaign_id'] = $this->args['campaign_id'];
     }
     if ('all' != $this->args['status']) {
         $query_args['status'] = $this->args['status'];
     }
     /** @deprecated filter name with misspelling */
     $query_args = apply_filters('chairtable_export_donations_query_args', $query_args, $this->args);
     $query_args = apply_filters('charitable_export_donations_query_args', $query_args, $this->args);
     return charitable_get_table('campaign_donations')->get_donations_report($query_args);
 }
 public function test_count_all()
 {
     $this->assertEquals(4, charitable_get_table('campaign_donations')->count_all());
 }
/**
 * Flush the donations cache for every campaign receiving a donation.
 *
 * @param   int $donation_id
 * @return  void
 * @since   1.0.0
 */
function charitable_flush_campaigns_donation_cache($donation_id)
{
    $campaign_donations = charitable_get_table('campaign_donations')->get_donation_records($donation_id);
    foreach ($campaign_donations as $campaign_donation) {
        Charitable_Campaign::flush_donations_cache($campaign_donation->campaign_id);
    }
    wp_cache_delete($donation_id, 'charitable_donation');
}
 /**
  * Return the amount of the donation.
  *
  * @param   int $campaign_id Optional. If set, returns the amount donated to the campaign.
  * @return  decimal
  * @access  public
  * @since   1.2.0
  */
 public function get_donation_amount($campaign_id = '')
 {
     return charitable_get_table('campaign_donations')->get_donation_amount($this->donation_id, $campaign_id);
 }
 /**
  * Get the data to be exported.
  *
  * @return  array
  * @access  protected
  * @since   1.0.0
  */
 protected function get_data()
 {
     $query_args = array();
     if (isset($this->args['campaign_id'])) {
         $query_args['campaign_id'] = $this->args['campaign_id'];
     }
     return charitable_get_table('campaign_donations')->get_donations_report($query_args);
 }
 /**
  * Deactivate a benefactor.
  *
  * @return  boolean 
  * @access  public
  * @since   1.0.0
  */
 public function delete_benefactor()
 {
     /* Run a security check first to ensure we initiated this action. */
     check_ajax_referer('charitable-deactivate-benefactor', 'nonce');
     $benefactor_id = isset($_POST['benefactor_id']) ? $_POST['benefactor_id'] : 0;
     if (!$benefactor_id) {
         $return = array('error' => __('No benefactor ID provided.', 'charitable'));
     } else {
         $deleted = charitable_get_table('benefactors')->delete($benefactor_id);
         $return = array('deleted' => $deleted);
     }
     echo json_encode($return);
     wp_die();
 }
 /**
  * Add custom filters to the query that returns the donations to be displayed.
  *
  * @param   array $vars
  * @return  array
  * @access 	public
  * @since   1.4.0
  */
 public function request_query($vars)
 {
     global $typenow;
     if (Charitable::DONATION_POST_TYPE != $typenow) {
         return $vars;
     }
     /* No Status: fix WP's crappy handling of "all" post status. */
     if (!isset($vars['post_status'])) {
         $vars['post_status'] = array_keys(charitable_get_valid_donation_statuses());
     }
     /* Set up date query */
     if (isset($_GET['start_date']) && !empty($_GET['start_date'])) {
         $start_date = $this->get_parsed_date($_GET['start_date']);
         $vars['date_query']['after'] = array('year' => $start_date['year'], 'month' => $start_date['month'], 'day' => $start_date['day']);
     }
     if (isset($_GET['end_date']) && !empty($_GET['end_date'])) {
         $end_date = $this->get_parsed_date($_GET['end_date']);
         $vars['date_query']['before'] = array('year' => $end_date['year'], 'month' => $end_date['month'], 'day' => $end_date['day']);
     }
     /* Filter by campaign. */
     if (isset($_GET['campaign_id']) && 'all' != $_GET['campaign_id']) {
         $donations = charitable_get_table('campaign_donations')->get_donation_ids_for_campaign($_GET['campaign_id']);
         $vars['post__in'] = $donations;
     }
     return $vars;
 }
 /**
  * Add a new donor. This may also create a user account for them.
  *
  * @param   array   $submitted
  * @return  int     $donor_id
  * @access  public
  * @since   1.0.0
  */
 public function add_donor($submitted = array())
 {
     $email = false;
     if (isset($submitted['email'])) {
         $email = $submitted['email'];
     }
     if (!$email && $this->is_logged_in()) {
         $email = $this->user_email;
     }
     /**
      * Still no email? We're going to have to call an end
      * to this party right now then.
      */
     if (!$email) {
         charitable_get_deprecated()->doing_it_wrong(__METHOD__, __('Unable to add donor. Email not set for logged out user.', 'charitable'), '1.0.0');
         return 0;
     }
     $donor_values = apply_filters('charitable_donor_values', array('user_id' => $this->ID, 'email' => $email, 'first_name' => isset($submitted['first_name']) ? $submitted['first_name'] : $this->first_name, 'last_name' => isset($submitted['last_name']) ? $submitted['last_name'] : $this->last_name), $this, $submitted);
     $donor_id = charitable_get_table('donors')->insert($donor_values);
     do_action('charitable_after_insert_donor', $donor_id, $this);
     return $donor_id;
 }
 /**
  * Returns the donor_id for the current donation. 
  *
  * @return  int
  * @access  public
  * @since   1.0.0
  */
 public function get_donor_id()
 {
     if (!isset($this->donor_id)) {
         $this->donor_id = $this->get_donation_data_value('donor_id', 0);
         if ($this->donor_id) {
             return $this->donor_id;
         }
         $user_id = $this->get_donation_data_value('user_id', get_current_user_id());
         $user_data = $this->get_donation_data_value('user', array());
         if ($user_id) {
             $this->donor_id = charitable_get_table('donors')->get_donor_id($user_id);
         } elseif (isset($user_data['email'])) {
             $this->donor_id = charitable_get_table('donors')->get_donor_id_by_email($user_data['email']);
         }
         /* If we still do not have a donor ID, it means that this is a first-time donor */
         if (0 == $this->donor_id) {
             $user = new Charitable_User($user_id);
             $this->donor_id = $user->add_donor($user_data);
         }
     }
     return $this->donor_id;
 }
 /**
  * Delete all campaign donation records for a given donation.
  *
  * @param   int $donation_id
  * @access  public
  * @static
  * @since   1.2.0
  * @return  bool
  */
 public static function delete_donation_records($donation_id)
 {
     $table = charitable_get_table('campaign_donations');
     foreach ($table->get_campaigns_for_donation($donation_id) as $campaign_id) {
         Charitable_Campaign::flush_donations_cache($campaign_id);
     }
     return $table->delete_by('donation_id', $donation_id);
 }
 /**
  * Flush the donations cache for every campaign receiving a donation. 
  *
  * @param   int $donation_id
  * @return  void
  * @access  public
  * @static
  * @since   1.0.0
  */
 public static function flush_campaigns_donation_cache($donation_id)
 {
     $campaign_donations = charitable_get_table('campaign_donations')->get_donation_records($donation_id);
     foreach ($campaign_donations as $campaign_donation) {
         Charitable_Campaign::flush_donations_cache($campaign_donation->campaign_id);
     }
 }