CalculateProjectedAnnualRevenue.php
9 months ago
GenerateNextRenewalForSubscription.php
3 years ago
LoadSubscriptionAdminOptions.php
9 months ago
LoadSubscriptionDetailsAssets.php
9 months ago
LoadSubscriptionsListTableAssets.php
8 months ago
LoadSubscriptionsListTableAssets.php
92 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Subscriptions\Actions; |
| 4 | |
| 5 | use Give\Framework\Database\DB; |
| 6 | use Give\Framework\Support\Facades\Scripts\ScriptAsset; |
| 7 | use Give\Helpers\Language; |
| 8 | use Give\Subscriptions\ListTable\SubscriptionsListTable; |
| 9 | use Give\Subscriptions\ValueObjects\SubscriptionStatus; |
| 10 | |
| 11 | /** |
| 12 | * @since 4.8.0 |
| 13 | */ |
| 14 | class LoadSubscriptionsListTableAssets |
| 15 | { |
| 16 | /** |
| 17 | * @since 4.12.0 Add "subscriptionStatuses" property to the localize script |
| 18 | * @since 2.27.1 Pass dismissed recommendations to the localize script |
| 19 | * @since 2.20.0 |
| 20 | */ |
| 21 | public function __invoke() |
| 22 | { |
| 23 | $handleName = 'give-admin-subscriptions'; |
| 24 | $asset = ScriptAsset::get(GIVE_PLUGIN_DIR.'build/assets/dist/js/give-admin-subscriptions.asset.php'); |
| 25 | |
| 26 | wp_register_script( |
| 27 | $handleName, |
| 28 | GIVE_PLUGIN_URL.'build/assets/dist/js/give-admin-subscriptions.js', |
| 29 | $asset['dependencies'], |
| 30 | $asset['version'], |
| 31 | true |
| 32 | ); |
| 33 | |
| 34 | wp_localize_script($handleName, 'GiveSubscriptions', [ |
| 35 | 'apiRoot' => esc_url_raw(rest_url('give-api/v2/admin/subscriptions')), |
| 36 | 'apiNonce' => wp_create_nonce('wp_rest'), |
| 37 | 'forms' => $this->getForms(), |
| 38 | 'table' => give(SubscriptionsListTable::class)->toArray(), |
| 39 | 'adminUrl' => admin_url(), |
| 40 | 'paymentMode' => give_is_test_mode(), |
| 41 | 'pluginUrl' => GIVE_PLUGIN_URL, |
| 42 | 'subscriptionStatuses' => SubscriptionStatus::labels(), |
| 43 | ]); |
| 44 | |
| 45 | wp_enqueue_script($handleName); |
| 46 | |
| 47 | Language::setScriptTranslations($handleName); |
| 48 | |
| 49 | wp_enqueue_style( |
| 50 | 'give-admin-ui-font', |
| 51 | 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400..700&display=swap', |
| 52 | [], |
| 53 | null |
| 54 | ); |
| 55 | |
| 56 | wp_enqueue_style('givewp-design-system-foundation'); |
| 57 | |
| 58 | wp_enqueue_style( |
| 59 | $handleName, |
| 60 | GIVE_PLUGIN_URL.'build/assets/dist/js/give-admin-subscriptions.css', |
| 61 | [], |
| 62 | $asset['version'] |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Retrieve a list of donation forms to populate the form filter dropdown |
| 68 | * |
| 69 | * @since 2.24.0 |
| 70 | * |
| 71 | * @return array |
| 72 | */ |
| 73 | private function getForms() |
| 74 | { |
| 75 | $options = DB::table('posts') |
| 76 | ->select( |
| 77 | ['ID', 'value'], |
| 78 | ['post_title', 'text'] |
| 79 | ) |
| 80 | ->where('post_type', 'give_forms') |
| 81 | ->whereIn('post_status', ['publish', 'draft', 'pending', 'private']) |
| 82 | ->getAll(ARRAY_A); |
| 83 | |
| 84 | return array_merge([ |
| 85 | [ |
| 86 | 'value' => '0', |
| 87 | 'text' => __('Any', 'give'), |
| 88 | ], |
| 89 | ], $options); |
| 90 | } |
| 91 | } |
| 92 |