Easy Digital Downloads
  • Package
  • Class
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Classes

  • EDD_API_Request_Log_Table
  • EDD_Customer_Reports_Table
  • EDD_Customers_Export
  • EDD_Download_History_Export
  • EDD_Download_Reports_Table
  • EDD_Export
  • EDD_File_Downloads_Log_Table
  • EDD_Gateway_Error_Log_Table
  • EDD_Payments_Export
  • EDD_Sales_Log_Table

Functions

  • edd_draw_chart_image
  • edd_estimated_monthly_stats
  • edd_generate_pdf
  • edd_get_report_dates
  • edd_log_default_views
  • edd_log_views
  • edd_logs_view_api_requests
  • edd_logs_view_file_downloads
  • edd_logs_view_gateway_errors
  • edd_logs_view_sales
  • edd_parse_report_dates
  • edd_report_views
  • edd_reporting_contextual_help
  • edd_reports_customers_table
  • edd_reports_default_views
  • edd_reports_downloads_table
  • edd_reports_earnings
  • edd_reports_graph
  • edd_reports_graph_controls
  • edd_reports_page
  • edd_reports_tab_export
  • edd_reports_tab_logs
  • edd_reports_tab_reports
  • edd_reports_taxes
  1 <?php
  2 /**
  3  * Download Reports Table Class
  4  *
  5  * @package     EDD
  6  * @subpackage  Admin/Reports
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.5
 10  */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 // Load WP_List_Table if not loaded
 16 if ( ! class_exists( 'WP_List_Table' ) ) {
 17     require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
 18 }
 19 
 20 /**
 21  * EDD_Download_Reports_Table Class
 22  *
 23  * Renders the Download Reports table
 24  *
 25  * @since 1.5
 26  */
 27 class EDD_Download_Reports_Table extends WP_List_Table {
 28     /**
 29      * @var int Number of items per page
 30      * @since 1.5
 31      */
 32     public $per_page = 30;
 33 
 34     /**
 35      * Get things started
 36      *
 37      * @access public
 38      * @since 1.5
 39      * @see WP_List_Table::__construct()
 40      * @return void
 41      */
 42     public function __construct() {
 43         global $status, $page;
 44 
 45         // Set parent defaults
 46         parent::__construct( array(
 47             'singular'  => edd_get_label_singular(),    // Singular name of the listed records
 48             'plural'    => edd_get_label_plural(),      // Plural name of the listed records
 49             'ajax'      => false                        // Does this table support ajax?
 50         ) );
 51     }
 52 
 53     /**
 54      * This function renders most of the columns in the list table.
 55      *
 56      * @access public
 57      * @since 1.5
 58      *
 59      * @param array $item Contains all the data of the downloads
 60      * @param string $column_name The name of the column
 61      *
 62      * @return string Column Name
 63      */
 64     public function column_default( $item, $column_name ) {
 65         switch( $column_name ){
 66             case 'earnings' :
 67                 return edd_currency_filter( edd_format_amount( $item[ $column_name ] ) );
 68             case 'average_sales' :
 69                 return round( $item[ $column_name ] );
 70             case 'average_earnings' :
 71                 return edd_currency_filter( edd_format_amount( $item[ $column_name ] ) );
 72             default:
 73                 return $item[ $column_name ];
 74         }
 75     }
 76 
 77     /**
 78      * Retrieve the table columns
 79      *
 80      * @access public
 81      * @since 1.5
 82      * @return array $columns Array of all the list table columns
 83      */
 84     public function get_columns() {
 85         $columns = array(
 86             'title'             => edd_get_label_singular(),
 87             'sales'             => __( 'Sales', 'edd' ),
 88             'earnings'          => __( 'Earnings', 'edd' ),
 89             'average_sales'     => __( 'Monthly Average Sales', 'edd' ),
 90             'average_earnings'  => __( 'Monthly Average Earnings', 'edd' )
 91         );
 92 
 93         return $columns;
 94     }
 95 
 96     /**
 97      * Retrieve the table's sortable columns
 98      *
 99      * @access public
100      * @since 1.4
101      * @return array Array of all the sortable columns
102      */
103     public function get_sortable_columns() {
104         return array(
105             'title'     => array( 'title', true ),
106             'sales'     => array( 'sales', false ),
107             'earnings'  => array( 'earnings', false ),
108         );
109     }
110 
111     /**
112      * Retrieve the current page number
113      *
114      * @access public
115      * @since 1.5
116      * @return int Current page number
117      */
118     public function get_paged() {
119         return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
120     }
121 
122     /**
123      * Retrieve the total number of downloads
124      *
125      * @access public
126      * @since 1.5
127      * @return int $total Total number of downloads
128      */
129     public function get_total_downloads() {
130         $counts = wp_count_posts( 'download' );
131         $total  = 0;
132         foreach ( $counts as $count )
133             $total += $count;
134         return $total;
135     }
136 
137     /**
138      * Outputs the reporting views
139      *
140      * @access public
141      * @since 1.5
142      * @return void
143      */
144     function bulk_actions() {
145         // These aren't really bulk actions but this outputs the markup in the right place
146         edd_report_views();
147     }
148 
149     /**
150      * Build all the reports data
151      *
152      * @access public
153      * @since 1.5
154      * @return array $reports_data All the data for customer reports
155      */
156     function reports_data() {
157         $reports_data = array();
158 
159         $orderby = isset( $_GET['orderby'] ) ? $_GET['orderby'] : 'title';
160         $order   = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC';
161 
162         $report_args = array(
163             'post_type'     => 'download',
164             'post_status'   => 'publish',
165             'order'         => $order,
166             'posts_per_page'=> $this->per_page,
167             'paged'         => $this->get_paged()
168         );
169 
170         switch ( $orderby ) :
171             case 'title' :
172                 $report_args['orderby'] = 'title';
173                 break;
174 
175             case 'sales' :
176                 $report_args['orderby'] = 'meta_value_num';
177                 $report_args['meta_key'] = '_edd_download_sales';
178                 break;
179 
180             case 'earnings' :
181                 $report_args['orderby'] = 'meta_value_num';
182                 $report_args['meta_key'] = '_edd_download_earnings';
183                 break;
184         endswitch;
185 
186         $downloads = get_posts( $report_args );
187         if ( $downloads ) {
188             foreach ( $downloads as $download ) {
189                 $reports_data[] = array(
190                     'ID'                => $download->ID,
191                     'title'             => get_the_title( $download->ID ),
192                     'sales'             => edd_get_download_sales_stats( $download->ID ),
193                     'earnings'          => edd_get_download_earnings_stats( $download->ID ),
194                     'average_sales'     => edd_get_average_monthly_download_sales( $download->ID ),
195                     'average_earnings'  => edd_get_average_monthly_download_earnings( $download->ID )
196                 );
197             }
198         }
199 
200         return $reports_data;
201     }
202 
203 
204     /**
205      * Setup the final data for the table
206      *
207      * @access public
208      * @since 1.5
209      * @uses EDD_Download_Reports_Table::get_columns()
210      * @uses EDD_Download_Reports_Table::get_sortable_columns()
211      * @uses EDD_Download_Reports_Table::reports_data()
212      * @uses EDD_Download_Reports_Table::get_pagenum()
213      * @uses EDD_Download_Reports_Table::get_total_downloads()
214      * @return void
215      */
216     function prepare_items() {
217         $columns = $this->get_columns();
218 
219         $hidden = array(); // No hidden columns
220 
221         $sortable = $this->get_sortable_columns();
222 
223         $this->_column_headers = array( $columns, $hidden, $sortable );
224 
225         $data = $this->reports_data();
226 
227         $current_page = $this->get_pagenum();
228 
229         $total_items = $this->get_total_downloads();
230 
231         $this->items = $data;
232 
233         $this->set_pagination_args( array(
234                 'total_items' => $total_items,
235                 'per_page'    => $this->per_page,
236                 'total_pages' => ceil( $total_items / $this->per_page )
237             )
238         );
239     }
240 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0