function test_ordered_by_ending_soon()
 {
     $query = Charitable_Campaigns::ordered_by_ending_soon();
     $this->assertEquals(3, $query->found_posts);
     $i = 0;
     while ($query->have_posts()) {
         $query->the_post();
         $this->assertEquals($this->campaigns_ordered_by_ending_soon[$i], get_the_ID(), sprintf('Index %d for campaigns orderd by date ending', $i));
         $i++;
     }
     $query_2 = Charitable_Campaigns::ordered_by_ending_soon(array('posts_per_page' => 1));
     $this->assertEquals(1, count($query_2->posts));
 }
 /**
  * Returns a WP_Query that will return campaigns, ordered by the amount they raised.
  *
  * @global 	$wpdb
  * @param 	array $args 	Additional arguments to pass to WP_Query 
  * @return 	WP_Query
  * @static
  * @since 	1.0.0
  * @todo
  */
 public static function ordered_by_amount($args = array())
 {
     global $wpdb;
     /* Set up filters to order by amount */
     add_filter('posts_join_paged', array('Charitable_Campaigns', 'join_campaign_donations_table'));
     add_filter('posts_groupby', array('Charitable_Campaigns', 'groupby_campaign_id'));
     add_filter('posts_orderby', array('Charitable_Campaigns', 'orderby_campaign_donation_amount'));
     $query = Charitable_Campaigns::query($args);
     /* Clean up filters */
     remove_filter('posts_join_paged', array('Charitable_Campaigns', 'join_campaign_donations_table'));
     remove_filter('posts_groupby', array('Charitable_Campaigns', 'groupby_campaign_id'));
     remove_filter('posts_orderby', array('Charitable_Campaigns', 'orderby_campaign_donation_amount'));
     return $query;
 }
<?php

/**
 * Partial template displaying the author's activity summary in the banner.
 *
 * @package     Reach
 */
if (!reach_has_charitable()) {
    return;
}
$user = charitable_get_user(reach_get_current_author()->ID);
$campaigns = Charitable_Campaigns::query(array('author' => $user->ID));
?>
<div class="author-activity-summary">
	<span class="number"><?php 
echo $user->count_campaigns_supported();
?>
</span>&nbsp;<?php 
_e('Campaigns Backed', 'reach');
?>
&nbsp;<span class='separator'>/</span>&nbsp;<span class="number"><?php 
echo $campaigns->post_count;
?>
</span>&nbsp;<?php 
_e('Campaigns Created', 'reach');
?>
</div><!-- .author-activity-summary -->
<?php

/**
 * Display a widget with donation stats.
 *
 * Override this template by copying it to yourtheme/charitable/widgets/donation-stats.php
 *
 * @author  Studio 164a
 * @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 
 /**
  * Return campaigns to display in the widget. 
  *
  * @param 	array 	$instance
  * @return  WP_Query
  * @access  protected
  * @since   1.0.0
  */
 protected function get_widget_campaigns($instance)
 {
     $number = isset($instance['number']) ? absint($instance['number']) : 5;
     $args = array('posts_per_page' => $number);
     if (isset($instance['order']) && 'recent' == $instance['order']) {
         $args['orderby'] = 'date';
         $args['order'] = 'DESC';
         return Charitable_Campaigns::query($args);
     }
     return Charitable_Campaigns::ordered_by_ending_soon($args);
 }
 /**
  * Checks whether the user has any current campaigns (i.e. non-expired).
  *
  * @return  WP_Query
  * @access  public
  * @since   1.0.0
  */
 public function get_current_campaigns($args = array())
 {
     $defaults = array('author' => $this->ID, 'meta_query' => array('relation' => 'OR', array('key' => '_campaign_end_date', 'value' => date('Y-m-d H:i:s'), 'compare' => '>=', 'type' => 'datetime'), array('key' => '_campaign_end_date', 'value' => '0')));
     $args = wp_parse_args($args, $defaults);
     return Charitable_Campaigns::query($args);
 }
        /**
         * Displays the widget form. 
         *
         * @param   array       $instance
         * @return  void
         * @access  public
         * @since   1.0.0
         */
        public function form($instance)
        {
            $defaults = array('title' => '', 'campaign_id' => '');
            $instance = wp_parse_args((array) $instance, $defaults);
            $title = $instance['title'];
            $campaign_id = $instance['campaign_id'];
            $campaigns = Charitable_Campaigns::query(array('posts_per_page' => -1));
            ?>
        <p>
            <label for="<?php 
            echo $this->get_field_id('title');
            ?>
"><?php 
            _e('Title:', 'charitable');
            ?>
                <input class="widefat" id="<?php 
            echo $this->get_field_id('title');
            ?>
" name="<?php 
            echo $this->get_field_name('title');
            ?>
" type="text" value="<?php 
            echo esc_attr($title);
            ?>
" />
            </label>
        </p> 
        <p>
            <label for="<?php 
            echo $this->get_field_id('campaign_id');
            ?>
"><?php 
            _e('Campaign:', 'charitable');
            ?>
        
                <select name="<?php 
            echo $this->get_field_name('campaign_id');
            ?>
">
                    <option value="current"><?php 
            _e('Campaign currently viewed', 'charitable');
            ?>
</option>
                    <optgroup label="<?php 
            _e('Specific campaigns', 'charitable');
            ?>
">
                        <?php 
            foreach ($campaigns->posts as $campaign) {
                ?>
                            <option value="<?php 
                echo $campaign->ID;
                ?>
" <?php 
                selected($campaign->ID, $campaign_id);
                ?>
><?php 
                echo $campaign->post_title;
                ?>
</option>
                        <?php 
            }
            ?>
                    </optgroup>
                </select>    
            </label>      
        </p>       
        <?php 
        }
        /**
         * Display the widget form in the admin.
         *
         * @param   array $instance The current settings for the widget options.
         * @return  void
         * @access  public
         * @since   1.0.0
         */
        public function form($instance)
        {
            $args = $this->get_parsed_args($instance);
            ?>
			<p>
				<label for="<?php 
            echo esc_attr($this->get_field_id('title'));
            ?>
"><?php 
            _e('Title', 'charitable');
            ?>
:</label>
				<input type="text" name="<?php 
            echo esc_attr($this->get_field_name('title'));
            ?>
" id="<?php 
            echo esc_attr($this->get_field_id('title'));
            ?>
" value="<?php 
            echo esc_attr($args['title']);
            ?>
" class="widefat" />
			</p>
			<p>
				<label for="<?php 
            echo esc_attr($this->get_field_id('number'));
            ?>
"><?php 
            _e('Number of donors to display', 'charitable');
            ?>
:</label>
				<input type="number" name="<?php 
            echo esc_attr($this->get_field_name('number'));
            ?>
" id="<?php 
            echo esc_attr($this->get_field_id('number'));
            ?>
" value="<?php 
            echo intval($args['number']);
            ?>
" min="1" size="3" />
			</p>
			<p>
				<label for="<?php 
            echo esc_attr($this->get_field_id('order'));
            ?>
"><?php 
            _e('Order by', 'charitable');
            ?>
:</label>
				<select name="<?php 
            echo esc_attr($this->get_field_name('order'));
            ?>
" id="<?php 
            echo esc_attr($this->get_field_id('order'));
            ?>
">
					<option value="recent" <?php 
            selected('recent', $args['order']);
            ?>
><?php 
            _e('Most recent', 'charitable');
            ?>
</option>
					<option value="amount" <?php 
            selected('amount', $args['order']);
            ?>
><?php 
            _e('Amount donated', 'charitable');
            ?>
</option>
				</select>
			</p>
			<p>
				<label for="<?php 
            echo esc_attr($this->get_field_id('campaign_id'));
            ?>
"><?php 
            _e('Show donors by campaign', 'charitable');
            ?>
:</label>
				<select name="<?php 
            echo esc_attr($this->get_field_name('campaign_id'));
            ?>
">
					<option value="all" <?php 
            selected('all', $args['campaign_id']);
            ?>
><?php 
            _e('Include all campaigns');
            ?>
</option>
					<option value="current" <?php 
            selected('current', $args['campaign_id']);
            ?>
><?php 
            _e('Campaign currently viewed', 'charitable');
            ?>
</option>
					<optgroup label="<?php 
            _e('Specific campaign', 'charitable');
            ?>
">
						<?php 
            foreach (Charitable_Campaigns::query()->posts as $campaign) {
                ?>
							<option value="<?php 
                echo intval($campaign->ID);
                ?>
" <?php 
                selected($campaign->ID, $args['campaign_id']);
                ?>
><?php 
                echo $campaign->post_title;
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>
				</select>                
			</p>
			<p>
				<input id="<?php 
            echo esc_attr($this->get_field_id('show_distinct'));
            ?>
" type="checkbox" name="<?php 
            echo esc_attr($this->get_field_name('show_distinct'));
            ?>
" <?php 
            checked($args['show_distinct']);
            ?>
>
				<label for="<?php 
            echo esc_attr($this->get_field_id('show_distinct'));
            ?>
"><?php 
            _e('Group donations by the same person', 'charitable');
            ?>
</label>        
			</p>
			<p>
				<input id="<?php 
            echo esc_attr($this->get_field_id('show_name'));
            ?>
" type="checkbox" name="<?php 
            echo esc_attr($this->get_field_name('show_name'));
            ?>
" <?php 
            checked($args['show_name']);
            ?>
>
				<label for="<?php 
            echo esc_attr($this->get_field_id('show_name'));
            ?>
"><?php 
            _e('Show donor\'s name', 'charitable');
            ?>
</label>            
			</p>
			<p>
				<input id="<?php 
            echo esc_attr($this->get_field_id('show_amount'));
            ?>
" type="checkbox" name="<?php 
            echo esc_attr($this->get_field_name('show_amount'));
            ?>
" <?php 
            checked($args['show_amount']);
            ?>
>
				<label for="<?php 
            echo esc_attr($this->get_field_id('show_amount'));
            ?>
"><?php 
            _e('Show donor\'s donation amount', 'charitable');
            ?>
</label>            
			</p>
			<p>            
				<input id="<?php 
            echo esc_attr($this->get_field_id('show_location'));
            ?>
" type="checkbox" name="<?php 
            echo esc_attr($this->get_field_name('show_location'));
            ?>
" <?php 
            checked($args['show_location']);
            ?>
>
				<label for="<?php 
            echo esc_attr($this->get_field_id('show_location'));
            ?>
"><?php 
            _e('Show donor\'s location', 'charitable');
            ?>
</label>
			</p>
			<p>            
				<input id="<?php 
            echo esc_attr($this->get_field_id('hide_if_no_donors'));
            ?>
" type="checkbox" name="<?php 
            echo esc_attr($this->get_field_name('hide_if_no_donors'));
            ?>
" <?php 
            checked($args['hide_if_no_donors']);
            ?>
>
				<label for="<?php 
            echo esc_attr($this->get_field_id('hide_if_no_donors'));
            ?>
"><?php 
            _e('Hide if there are no donors', 'charitable');
            ?>
</label>
			</p>
			<?php 
            do_action('charitable_donor_widget_settings_bottom', $args, $this);
        }
Esempio n. 9
0
 * This template is used to display a grid of Charitable campaigns. It will
 * not be used if Charitable is not active.
 *
 * @package Reach
 */
if (!reach_has_charitable()) {
    return;
}
?>
<div class="campaigns-grid-wrapper">
	<h3 class="section-title"><?php 
_e('Latest Projects', 'reach');
?>
</h3>
	<?php 
$campaigns = Charitable_Campaigns::query();
charitable_template_campaign_loop($campaigns, 3);
wp_reset_postdata();
if ($campaigns->max_num_pages > 1) {
    ?>

		<p class="center">
			<a class="button button-alt" href="<?php 
    echo esc_url(home_url(apply_filters('reach_previous_campaigns_link', '/campaigns/page/2/')));
    ?>
">
				<?php 
    echo apply_filters('reach_previous_campaigns_text', __('Previous Campaigns', 'reach'));
    ?>
			</a>
		</p>
 /**
  * Return campaigns to display in the campaigns shortcode. 
  *
  * @param   array   $args
  * @return  WP_Query
  * @access  public
  * @static
  * @since   1.0.0
  */
 public static function get_campaigns($args)
 {
     $query_args = array('posts_per_page' => $args['number']);
     /* Pagination */
     if (!empty($args['paged'])) {
         $query_args['paged'] = $args['paged'];
     }
     /* Set category constraint */
     if (!empty($args['category'])) {
         $query_args['tax_query'] = array(array('taxonomy' => 'campaign_category', 'field' => 'slug', 'terms' => $args['category']));
     }
     /* Set author constraint */
     if (!empty($args['creator'])) {
         $query_args['author'] = $args['creator'];
     }
     /* Only include active campaigns if flag is set */
     if (!$args['include_inactive']) {
         $query_args['meta_query'] = array('relation' => 'OR', array('key' => '_campaign_end_date', 'value' => date('Y-m-d H:i:s'), 'compare' => '>=', 'type' => 'datetime'), array('key' => '_campaign_end_date', 'value' => 0, 'compare' => '='));
     }
     if (!empty($args['exclude'])) {
         $query_args['post__not_in'] = explode(',', $args['exclude']);
     }
     /* Return campaigns, ordered by date of creation. */
     if ('post_date' == $args['orderby']) {
         $query_args['orderby'] = 'date';
         $query_args['order'] = 'DESC';
         return Charitable_Campaigns::query($query_args);
     }
     /* Return campaigns, ordered by how much money has been raised. */
     if ('popular' == $args['orderby']) {
         return Charitable_Campaigns::ordered_by_amount($query_args);
     }
     /* Return campaigns, ordered by how soon they are ending. */
     return Charitable_Campaigns::ordered_by_ending_soon($query_args);
 }