ravinderk /
Give
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Gateways Reports Table Class |
||
| 4 | * |
||
| 5 | * @package Give |
||
| 6 | * @subpackage Admin/Reports |
||
| 7 | * @copyright Copyright (c) 2016, WordImpress |
||
| 8 | * @license https://opensource.org/licenses/gpl-license GNU Public License |
||
| 9 | * @since 1.0 |
||
| 10 | */ |
||
| 11 | |||
| 12 | // Exit if accessed directly. |
||
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
||
| 14 | exit; |
||
| 15 | } |
||
| 16 | |||
| 17 | // Load WP_List_Table if not loaded |
||
| 18 | if ( ! class_exists( 'WP_List_Table' ) ) { |
||
| 19 | require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
||
| 20 | } |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Give_Gateway_Reports_Table Class |
||
| 24 | * |
||
| 25 | * Renders the Download Reports table |
||
| 26 | * |
||
| 27 | * @since 1.0 |
||
| 28 | */ |
||
| 29 | class Give_Gateway_Reports_Table extends WP_List_Table { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var int Number of items per page |
||
| 33 | * @since 1.0 |
||
| 34 | */ |
||
| 35 | public $per_page = 30; |
||
| 36 | |||
| 37 | |||
| 38 | /** |
||
| 39 | * Get things started |
||
| 40 | * |
||
| 41 | * @since 1.0 |
||
| 42 | * @see WP_List_Table::__construct() |
||
| 43 | */ |
||
| 44 | View Code Duplication | public function __construct() { |
|
|
0 ignored issues
–
show
|
|||
| 45 | global $status, $page; |
||
| 46 | |||
| 47 | // Set parent defaults |
||
| 48 | parent::__construct( array( |
||
| 49 | 'singular' => give_get_forms_label_singular(), // Singular name of the listed records |
||
| 50 | 'plural' => give_get_forms_label_plural(), // Plural name of the listed records |
||
| 51 | 'ajax' => false // Does this table support ajax? |
||
|
0 ignored issues
–
show
|
|||
| 52 | ) ); |
||
| 53 | |||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * This function renders most of the columns in the list table. |
||
| 58 | * |
||
| 59 | * @access public |
||
| 60 | * @since 1.0 |
||
| 61 | * |
||
| 62 | * @param array $item Contains all the data of the form |
||
| 63 | * @param string $column_name The name of the column |
||
| 64 | * |
||
| 65 | * @return string Column Name |
||
| 66 | */ |
||
| 67 | public function column_default( $item, $column_name ) { |
||
| 68 | switch ( $column_name ) { |
||
| 69 | default: |
||
| 70 | return $item[ $column_name ]; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Retrieve the table columns |
||
| 76 | * |
||
| 77 | * @access public |
||
| 78 | * @since 1.0 |
||
| 79 | * @return array $columns Array of all the list table columns |
||
| 80 | */ |
||
| 81 | public function get_columns() { |
||
| 82 | $columns = array( |
||
| 83 | 'label' => esc_attr__( 'Gateway', 'give' ), |
||
| 84 | 'complete_sales' => esc_attr__( 'Complete Payments', 'give' ), |
||
| 85 | 'pending_sales' => esc_attr__( 'Pending / Failed Payments', 'give' ), |
||
| 86 | 'total_sales' => esc_attr__( 'Total Payments', 'give' ), |
||
| 87 | 'total_donations' => esc_attr__( 'Total Donated', 'give' ) |
||
| 88 | ); |
||
| 89 | |||
| 90 | return $columns; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Get the sortable columns |
||
| 95 | * |
||
| 96 | * @access public |
||
| 97 | * @since 1.8.12 |
||
| 98 | * @return array Array of all the sortable columns |
||
| 99 | */ |
||
| 100 | public function get_sortable_columns() { |
||
| 101 | return array( |
||
| 102 | 'total_donations' => array( 'total_donations', false ) |
||
| 103 | ); |
||
| 104 | } |
||
| 105 | |||
| 106 | |||
| 107 | /** |
||
| 108 | * Retrieve the current page number |
||
| 109 | * |
||
| 110 | * @access public |
||
| 111 | * @since 1.0 |
||
| 112 | * @return int Current page number |
||
| 113 | */ |
||
| 114 | public function get_paged() { |
||
| 115 | return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
||
|
0 ignored issues
–
show
|
|||
| 116 | } |
||
| 117 | |||
| 118 | |||
| 119 | /** |
||
| 120 | * Outputs the reporting views |
||
| 121 | * |
||
| 122 | * @access public |
||
| 123 | * @since 1.0 |
||
| 124 | * @return void |
||
| 125 | */ |
||
| 126 | public function bulk_actions( $which = '' ) { |
||
| 127 | |||
| 128 | } |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Generate the table navigation above or below the table |
||
| 132 | * |
||
| 133 | * @since 1.0 |
||
| 134 | * @access protected |
||
| 135 | * |
||
| 136 | * @param string $which |
||
| 137 | */ |
||
| 138 | View Code Duplication | protected function display_tablenav( $which ) { |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 139 | |||
| 140 | if ( 'top' === $which ) { |
||
| 141 | wp_nonce_field( 'bulk-' . $this->_args['plural'] ); |
||
| 142 | } |
||
| 143 | ?> |
||
| 144 | <div class="tablenav gateways-report-tablenav give-clearfix <?php echo esc_attr( $which ); ?>"> |
||
| 145 | |||
| 146 | <?php if ( 'top' === $which ) { ?> |
||
| 147 | <h3 class="alignleft reports-earnings-title"> |
||
| 148 | <span><?php esc_html_e( 'Donation Methods Report', 'give' ); ?></span> |
||
| 149 | </h3> |
||
| 150 | <?php } ?> |
||
| 151 | |||
| 152 | <div class="alignright tablenav-right"> |
||
| 153 | <div class="actions bulkactions"> |
||
| 154 | <?php $this->bulk_actions( $which ); ?> |
||
| 155 | </div> |
||
| 156 | <?php |
||
| 157 | $this->extra_tablenav( $which ); |
||
| 158 | $this->pagination( $which ); |
||
| 159 | ?> |
||
| 160 | </div> |
||
| 161 | |||
| 162 | |||
| 163 | <br class="clear" /> |
||
| 164 | |||
| 165 | </div> |
||
| 166 | <?php |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Reorder User Defined Array |
||
| 171 | * |
||
| 172 | * @param $old_value |
||
| 173 | * @param $new_value |
||
| 174 | * |
||
| 175 | * @access public |
||
| 176 | * @since 1.8.12 |
||
| 177 | * |
||
| 178 | * @return int |
||
| 179 | */ |
||
| 180 | public function give_sort_total_donations( $old_value, $new_value ) { |
||
| 181 | // If no sort, default to label. |
||
| 182 | $orderby = ( ! empty( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : 'label'; |
||
|
0 ignored issues
–
show
|
|||
| 183 | |||
| 184 | //If no order, default to asc. |
||
| 185 | $order = ( ! empty( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : 'asc'; |
||
|
0 ignored issues
–
show
|
|||
| 186 | |||
| 187 | //Determine sort order. |
||
| 188 | $result = strcmp( $old_value[ $orderby ], $new_value[ $orderby ] ); |
||
| 189 | |||
| 190 | return ( $order === 'asc' ) ? $result : -$result; |
||
| 191 | } |
||
| 192 | |||
| 193 | |||
| 194 | /** |
||
| 195 | * Build all the reports data |
||
| 196 | * |
||
| 197 | * @access public |
||
| 198 | * @since 1.0 |
||
| 199 | * @return array $reports_data All the data for donor reports |
||
| 200 | */ |
||
| 201 | public function reports_data() { |
||
| 202 | |||
| 203 | $reports_data = array(); |
||
| 204 | $gateways = give_get_payment_gateways(); |
||
| 205 | $stats = new Give_Payment_Stats(); |
||
| 206 | |||
| 207 | foreach ( $gateways as $gateway_id => $gateway ) { |
||
| 208 | |||
| 209 | $complete_count = give_count_sales_by_gateway( $gateway_id, 'publish' ); |
||
| 210 | $pending_count = give_count_sales_by_gateway( $gateway_id, array( 'pending', 'failed' ) ); |
||
|
0 ignored issues
–
show
array('pending', 'failed') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 211 | |||
| 212 | $reports_data[] = array( |
||
| 213 | 'ID' => $gateway_id, |
||
| 214 | 'label' => $gateway['admin_label'], |
||
| 215 | 'complete_sales' => $complete_count, |
||
| 216 | 'pending_sales' => $pending_count, |
||
| 217 | 'total_sales' => $complete_count + $pending_count, |
||
| 218 | 'total_donations' => give_currency_filter( give_format_amount( $stats->get_earnings( 0, strtotime('04/13/2015' ), current_time('timestamp' ), $gateway_id ), array( 'sanitize' => false ) ) ), |
||
|
0 ignored issues
–
show
strtotime('04/13/2015') is of type integer, but the function expects a boolean.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$gateway_id is of type integer|string, but the function expects a boolean.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 219 | ); |
||
| 220 | } |
||
| 221 | |||
| 222 | return $reports_data; |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Setup the final data for the table |
||
| 227 | * |
||
| 228 | * @access public |
||
| 229 | * @since 1.0 |
||
| 230 | * @uses Give_Gateway_Reports_Table::get_columns() |
||
| 231 | * @uses Give_Gateway_Reports_Table::get_sortable_columns() |
||
| 232 | * @uses Give_Gateway_Reports_Table::reports_data() |
||
| 233 | * @return void |
||
| 234 | */ |
||
| 235 | public function prepare_items() { |
||
| 236 | $columns = $this->get_columns(); |
||
| 237 | $hidden = array(); // No hidden columns |
||
| 238 | $sortable = $this->get_sortable_columns(); |
||
| 239 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
||
| 240 | $this->items = $this->reports_data(); |
||
| 241 | |||
| 242 | // Sort Array when we are sorting data in array. |
||
| 243 | usort( $this->items, array( $this, 'give_sort_total_donations' ) ); |
||
| 244 | |||
| 245 | } |
||
| 246 | } |
||
| 247 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.