args = $this->parse_args( $atts ); $this->type = $this->args['display']; $this->report = $this->get_report(); } /** * Create class object. * * @since 1.6.0 * * @param array $atts User-defined attributes. * @return string */ public static function display( $atts ) { $object = new Charitable_Stat_Shortcode( $atts ); return $object->get_query_result(); } /** * Return the query result. * * @since 1.6.0 * * @return string */ public function get_query_result() { switch ( $this->type ) { case 'progress': $total = $this->report->get_report( 'amount' ); if ( ! $this->args['goal'] ) { return charitable_format_money( $total ); } $goal = charitable_sanitize_amount( $this->args['goal'], false ); $total = charitable_sanitize_amount( $total, true ); $percent = ( $total / $goal ) * 100; return '
'; case 'total': return charitable_format_money( $this->report->get_report( 'amount' ) ); case 'donors': case 'donations': return (string) $this->report->get_report( $this->type ); } } /** * Parse shortcode attributes. * * @since 1.6.0 * * @param array $atts User-defined attributes. * @return array */ private function parse_args( $atts ) { $defaults = array( 'display' => 'total', 'campaigns' => '', 'goal' => false, ); $args = shortcode_atts( $defaults, $atts, 'charitable_stat' ); $args['campaigns'] = strlen( $args['campaigns'] ) ? explode( ',', $args['campaigns'] ) : array(); return $args; } /** * Run the report for the shortcode. * * @since 1.6.0 * * @return Charitable_Donation_Report */ private function get_report() { return new Charitable_Donation_Report( $this->get_report_args() ); } /** * Return the arguments used for generating the report. * * @since 1.6.0 * * @return array */ private function get_report_args() { $args = array(); $args['report_type'] = in_array( $this->type, array( 'progress', 'total' ) ) ? 'amount' : $this->type; $args['campaigns'] = $this->args['campaigns']; return $args; } } endif;