start_date = $args['start_date']; $this->end_date = $args['end_date']; $this->types = $args['types']; } // end if; } // end __construct; /** * Runs on singleton instantiation. * * @since 2.0.0 * @return void. */ public function init() {} // end init; /** * Main function to call the get data functions based on the array of types. * * @since 2.0.0 * @return array With all the data requested. */ public function statistics_data() { $data = array(); foreach ($this->types as $key => $type) { $data_function = 'get_data_' . $type; $data[$key] = $this->$data_function(); } // end foreach; return $data; } // end statistics_data; /** * Get data of all completed and refunded payments to show in the main graph. * * @since 2.0.0 * @return array With total gross data. */ public function get_data_mrr_growth() { $payments_per_month = array( 'january' => array( 'total' => 0, 'cancelled' => 0, ), 'february' => array( 'total' => 0, 'cancelled' => 0, ), 'march' => array( 'total' => 0, 'cancelled' => 0, ), 'april' => array( 'total' => 0, 'cancelled' => 0, ), 'may' => array( 'total' => 0, 'cancelled' => 0, ), 'june' => array( 'total' => 0, 'cancelled' => 0, ), 'july' => array( 'total' => 0, 'cancelled' => 0, ), 'august' => array( 'total' => 0, 'cancelled' => 0, ), 'september' => array( 'total' => 0, 'cancelled' => 0, ), 'october' => array( 'total' => 0, 'cancelled' => 0, ), 'november' => array( 'total' => 0, 'cancelled' => 0, ), 'december' => array( 'total' => 0, 'cancelled' => 0, ), ); $memberships = wu_get_memberships(array( 'date_query' => array( 'column' => 'date_created', 'compare' => 'BETWEEN', 'relation' => '', array( 'year' => current_time('Y', true), ), ) )); $mrr_status = array( 'active', 'cancelled', 'expired', ); $churn_status = array( 'cancelled', 'expired', ); foreach ($memberships as $membership) { if (!$membership->is_recurring()) { continue; } // end if; $status = $membership->get_status(); if (in_array($status, $mrr_status, true)) { $data = getdate(strtotime($membership->get_date_created())); $month = strtolower($data['month']); $payments_per_month[$month]['total'] += floatval($membership->get_normalized_amount()); } // end if; if (in_array($status, $churn_status, true)) { $data = getdate(strtotime((string) $membership->get_date_cancellation())); $month = strtolower($data['month']); $payments_per_month[$month]['cancelled'] += floatval($membership->get_normalized_amount()); } // end if; } // end foreach; return $payments_per_month; } // end get_data_mrr_growth; } // end class Dashboard_Statistics;