| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Donations; |
| 4 |
|
| 5 |
use Give\Donations\Actions\LoadDonationDetailsAssets; |
| 6 |
use Give\Donations\Actions\LoadDonationsListTableAssets; |
| 7 |
use Give\Donations\Models\Donation; |
| 8 |
use Give\Framework\Permissions\Facades\UserPermissions; |
| 9 |
|
| 10 |
class DonationsAdminPage |
| 11 |
{ |
| 12 |
|
| 13 |
/** |
| 14 |
* @since 4.14.0 update permission capability to use facade |
| 15 |
* @since 2.20.0 |
| 16 |
*/ |
| 17 |
public function registerMenuItem() |
| 18 |
{ |
| 19 |
remove_submenu_page( |
| 20 |
'edit.php?post_type=give_forms', |
| 21 |
'give-payment-history' |
| 22 |
); |
| 23 |
|
| 24 |
remove_action( |
| 25 |
'give_forms_page_give-payment-history', |
| 26 |
'give_payment_history_page' |
| 27 |
); |
| 28 |
|
| 29 |
add_submenu_page( |
| 30 |
'edit.php?post_type=give_forms', |
| 31 |
esc_html__('Donations', 'give'), |
| 32 |
esc_html__('Donations', 'give'), |
| 33 |
UserPermissions::donations()->viewCap(), |
| 34 |
'give-payment-history', |
| 35 |
[$this, 'render'] |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* @since 2.27.1 Add dismissed recommendations |
| 41 |
* @since 2.27.0 Adds "addonsBulkActions" to the GiveDonations object |
| 42 |
* @since 2.24.0 Add ListTable columns |
| 43 |
* @since 2.20.0 |
| 44 |
* @since 2.21.2 Localized the admin URL as a base for URL concatenation. |
| 45 |
*/ |
| 46 |
public function loadScripts() |
| 47 |
{ |
| 48 |
give(LoadDonationsListTableAssets::class)(); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Render admin page container |
| 53 |
* |
| 54 |
* @since 4.6.0 Add new details page view |
| 55 |
* @since 2.20.0 |
| 56 |
*/ |
| 57 |
public function render() |
| 58 |
{ |
| 59 |
if (isset($_GET['view']) && 'view-payment-details' === $_GET['view']) { |
| 60 |
include GIVE_PLUGIN_DIR . 'includes/admin/payments/view-payment-details.php'; |
| 61 |
} else { |
| 62 |
if (self::isShowingDetailsPage()) { |
| 63 |
$donation = Donation::find(absint($_GET['id'])); |
| 64 |
|
| 65 |
if ( ! $donation) { |
| 66 |
wp_die(__('Donation not found', 'give'), 404); |
| 67 |
} |
| 68 |
|
| 69 |
give(LoadDonationDetailsAssets::class)(); |
| 70 |
} else { |
| 71 |
// TODO: Remove this once the new view is fully launched |
| 72 |
if (self::isShowing()) { |
| 73 |
give(LoadDonationsListTableAssets::class)(); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
echo '<div id="give-admin-donations-root"></div>'; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Helper function to determine if current page is Give Donations admin page |
| 83 |
* @since 2.20.0 |
| 84 |
* |
| 85 |
* @return bool |
| 86 |
*/ |
| 87 |
public static function isShowing() |
| 88 |
{ |
| 89 |
return isset($_GET['page']) && $_GET['page'] === 'give-payment-history' && ! isset($_GET['id']); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* @since 4.6.0 |
| 94 |
*/ |
| 95 |
public static function isShowingDetailsPage(): bool |
| 96 |
{ |
| 97 |
return isset($_GET['id'], $_GET['page']) && 'give-payment-history' === $_GET['page']; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
} |
| 102 |
|