/**
  * A method used to join the campaign donations table on the campaigns query. 
  *
  * @param 	string $join_statement
  * @return  string
  * @access  public
  * @static
  * @since   1.0.0
  */
 public static function join_campaign_donations_table($join_statement)
 {
     global $wpdb;
     $statuses = Charitable_Donation::get_approval_statuses();
     $statuses = array_filter($statuses, array('Charitable_Donation', 'is_valid_donation_status'));
     $statuses = "'" . implode("','", $statuses) . "'";
     $join_statement .= " LEFT JOIN ( SELECT cd1.campaign_donation_id, cd1.donation_id, cd1.donor_id, cd1.amount, cd1.campaign_id\r\n\t\t\tFROM {$wpdb->prefix}charitable_campaign_donations cd1 \r\n\t\t\tINNER JOIN {$wpdb->posts} po1 ON cd1.donation_id = po1.ID\r\n\t\t\tWHERE po1.post_status IN ( {$statuses} )\r\n\t\t) cd ON cd.campaign_id = {$wpdb->posts}.ID";
     return $join_statement;
 }
 /**
  * Return the number of users who have donated to the given campaign. 
  *
  * @global wpdb	$wpdb
  * @param 	int 	$campaign_id
  * @param 	boolean $include_all 	If false, only 
  * @return int
  * @since 	1.0.0
  */
 public function count_campaign_donors($campaign_id, $include_all = false)
 {
     global $wpdb;
     $statuses = $include_all ? array() : Charitable_Donation::get_approval_statuses();
     list($status_clause, $parameters) = $this->get_donation_status_clause($statuses);
     array_unshift($parameters, $campaign_id);
     $sql = "SELECT COUNT( DISTINCT cd.donor_id ) \n\t\t\t\tFROM {$this->table_name} cd\n\t\t\t\tINNER JOIN {$wpdb->posts} p ON p.ID = cd.donation_id\n\t\t\t\tWHERE cd.campaign_id = %d\n\t\t\t\t{$status_clause};";
     return $wpdb->get_var($wpdb->prepare($sql, $parameters));
 }