PluginProbe
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management / 1.5.0
SureDonation – Donation Forms, Fundraising Campaigns & Donor Management v1.5.0
1.6.0 1.5.1 1.5.0 1.4.0 1.3.0 trunk 0.0.1 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0
suredonation / inc / page-builders / bricks / elements / campaign-stats.php

campaign-stats.php in SureDonation – Donation Forms, Fundraising Campaigns & Donor Management 1.5.0, at inc/page-builders/bricks/elements/campaign-stats.php

109 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Bricks element: Campaign Statistic.
4 *
5 * @package SureDonation
6 * @since 1.2.0
7 */
8
9 namespace SureDonation\Inc\Page_Builders\Bricks\Elements;
10
11 use SureDonation\Inc\Page_Builders\Bricks\Base_Element;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 /**
18 * Campaign_Stats class.
19 *
20 * @since 1.2.0
21 */
22 class Campaign_Stats extends Base_Element {
23 /**
24 * Valid statistic values (must match the block's get_statistic_config()).
25 *
26 * @since 1.2.0
27 */
28 private const STATISTICS = [ 'average-donation', 'top-donation', 'total-raised', 'donor-count', 'donation-count' ];
29
30 /**
31 * Element name.
32 *
33 * @since 1.2.0
34 * @var string
35 */
36 public $name = 'suredonation-campaign-stats';
37
38 /**
39 * Element icon.
40 *
41 * @since 1.2.0
42 * @var string
43 */
44 public $icon = 'ti-bar-chart';
45
46 /**
47 * Element label shown in the builder panel.
48 *
49 * @since 1.2.0
50 * @return string
51 */
52 public function get_label() {
53 return esc_html__( 'Campaign Statistic', 'suredonation' );
54 }
55
56 /**
57 * {@inheritDoc}
58 */
59 public function get_keywords() {
60 return array_merge( parent::get_keywords(), [ 'statistic', 'stats', 'raised' ] );
61 }
62
63 /**
64 * Register the element controls.
65 *
66 * @since 1.2.0
67 * @return void
68 */
69 public function set_controls() {
70 $this->add_campaign_control();
71
72 $this->controls['statistic'] = [
73 'tab' => 'content',
74 'label' => esc_html__( 'Statistic to display', 'suredonation' ),
75 'type' => 'select',
76 'default' => 'average-donation',
77 'options' => [
78 'average-donation' => esc_html__( 'Average Donation', 'suredonation' ),
79 'top-donation' => esc_html__( 'Top Donation', 'suredonation' ),
80 'total-raised' => esc_html__( 'Total Raised', 'suredonation' ),
81 'donor-count' => esc_html__( 'Donors', 'suredonation' ),
82 'donation-count' => esc_html__( 'Donations', 'suredonation' ),
83 ],
84 ];
85 }
86
87 /**
88 * {@inheritDoc}
89 */
90 protected function block_name() {
91 return 'suredonation/campaign-stats';
92 }
93
94 /**
95 * Map the element settings to the block attributes.
96 *
97 * @since 1.2.0
98 * @param array<string, mixed> $settings Element settings.
99 * @return array<string, mixed>
100 */
101 protected function get_block_attrs( $settings ) {
102 $statistic = $this->setting_string( $settings, 'statistic', 'average-donation' );
103
104 return [
105 'statistic' => in_array( $statistic, self::STATISTICS, true ) ? $statistic : 'average-donation',
106 ];
107 }
108 }
109