$88 GRAYBYTE WORDPRESS FILE MANAGER $61

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 172.67.217.254 | ADMIN IP 216.73.216.23
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/home/bravrvjk/itiministry.org/wp-content/plugins/give/src/Donors/Endpoints/

HOME
Current File : /home/bravrvjk/itiministry.org/wp-content/plugins/give/src/Donors/Endpoints//ListDonorsStats.php
<?php

namespace Give\Donors\Endpoints;

use Give\Framework\Database\DB;
use WP_REST_Request;
use WP_REST_Response;

/**
 * @since 4.11.0
 */
class ListDonorsStats extends Endpoint
{
    /**
     * @var string
     */
    protected $endpoint = 'admin/donors/stats';

    /**
     * @var WP_REST_Request
     */
    protected $request;

    /**
     * @since 4.11.0
     */
    public function registerRoute()
    {
        register_rest_route(
            'give-api/v2',
            $this->endpoint,
            [
                [
                    'methods' => 'GET',
                    'callback' => [$this, 'handleRequest'],
                    'permission_callback' => [$this, 'permissionsCheck'],
                ],
                'args' => [
                ],
            ]
        );
    }

    /**
     * @since 4.11.0
     */
    public function handleRequest(WP_REST_Request $request): WP_REST_Response
    {
        $this->request = $request;

        $statistics = $this->getDonorStatistics();

        return new WP_REST_Response($statistics);
    }

    /**
     * Get all donor statistics in a single optimized query
     *
     * @since 4.11.0
     */
    public function getDonorStatistics(): array
    {
        $query = DB::table('give_donors', 'donors')
            ->leftJoin('give_subscriptions as subscriptions', 'donors.id', 'subscriptions.customer_id')
            ->selectRaw('SELECT
                COUNT(DISTINCT donors.id) as total_donors,
                COUNT(DISTINCT subscriptions.customer_id) as recurring_donors,
                COUNT(DISTINCT donors.id) - COUNT(DISTINCT subscriptions.customer_id) as one_time_donors
            ');

        $result = $query->get();

         // Handle case when no results are found
         if (!$result) {
            return [
                'donorsCount' => 0,
                'oneTimeDonorsCount' => 0,
                'subscribersCount' => 0,
            ];
        }

        return [
            'donorsCount' => (int) $result->total_donors,
            'oneTimeDonorsCount' => (int) $result->one_time_donors,
            'subscribersCount' => (int) $result->recurring_donors,
        ];
    }

}


Current_dir [ WRITEABLE ] Document_root [ NOT WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
4 Apr 2026 1.57 AM
bravrvjk / bravrvjk
0755
DeleteDonor.php
3.935 KB
28 Jan 2026 8.00 PM
bravrvjk / bravrvjk
0644
Endpoint.php
1.234 KB
28 Jan 2026 8.00 PM
bravrvjk / bravrvjk
0644
ListDonors.php
7.395 KB
30 Oct 2025 12.17 AM
bravrvjk / bravrvjk
0644
ListDonorsStats.php
2.131 KB
16 Oct 2025 6.10 PM
bravrvjk / bravrvjk
0644
SwitchDonorView.php
0.287 KB
12 May 2022 3.49 AM
bravrvjk / bravrvjk
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025 CONTACT ME
Static GIF