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