Actions
5 months ago
DataTransferObjects
2 years ago
Factories
1 year ago
Fields
1 year ago
ListTable
1 year ago
Migrations
1 year ago
Models
11 months ago
Repositories
11 months ago
Routes
5 months ago
ViewModels
2 years ago
resources
1 year ago
ServiceProvider.php
1 year ago
ServiceProvider.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\EventTickets; |
| 4 | |
| 5 | use Give\BetaFeatures\Facades\FeatureFlag; |
| 6 | use Give\EventTickets\Actions\AddEventTicketsToDonationConfirmationPageDonationTotal; |
| 7 | use Give\EventTickets\Actions\AddEventTicketsToDonationConfirmationPageEventTicketDetails; |
| 8 | use Give\EventTickets\Actions\RegisterEventsMenuItem; |
| 9 | use Give\EventTickets\Actions\RenderDonationFormBlock; |
| 10 | use Give\EventTickets\Actions\UpdateDonationConfirmationPageReceiptDonationAmount; |
| 11 | use Give\EventTickets\Repositories\EventRepository; |
| 12 | use Give\EventTickets\Repositories\EventTicketRepository; |
| 13 | use Give\EventTickets\Repositories\EventTicketTypeRepository; |
| 14 | use Give\Framework\Migrations\MigrationsRegister; |
| 15 | use Give\Helpers\Hooks; |
| 16 | use Give\ServiceProviders\ServiceProvider as ServiceProviderInterface; |
| 17 | |
| 18 | /** |
| 19 | * @since 3.6.0 |
| 20 | */ |
| 21 | class ServiceProvider implements ServiceProviderInterface |
| 22 | { |
| 23 | /** |
| 24 | * @inheritDoc |
| 25 | * |
| 26 | * @since 3.6.0 |
| 27 | */ |
| 28 | public function register(): void |
| 29 | { |
| 30 | if (!FeatureFlag::eventTickets()) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | global $wpdb; |
| 35 | $wpdb->give_events = "{$wpdb->prefix}give_events"; |
| 36 | $wpdb->give_event_tickets = "{$wpdb->prefix}give_event_tickets"; |
| 37 | $wpdb->give_event_ticket_types = "{$wpdb->prefix}give_event_ticket_types"; |
| 38 | |
| 39 | give()->singleton('events', EventRepository::class); |
| 40 | give()->singleton('eventTickets', EventTicketRepository::class); |
| 41 | give()->singleton('eventTicketTypes', EventTicketTypeRepository::class); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @inheritDoc |
| 46 | * |
| 47 | * @since 3.6.0 |
| 48 | */ |
| 49 | public function boot(): void |
| 50 | { |
| 51 | if (!FeatureFlag::eventTickets()) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | $this->registerMigrations(); |
| 56 | $this->registerRoutes(); |
| 57 | $this->registerMenus(); |
| 58 | $this->registerFormExtension(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @since 3.6.0 |
| 63 | */ |
| 64 | private function registerMigrations(): void |
| 65 | { |
| 66 | give(MigrationsRegister::class)->addMigrations([ |
| 67 | Migrations\CreateEventsTable::class, |
| 68 | Migrations\CreateEventTicketTypesTable::class, |
| 69 | Migrations\CreateEventTicketsTable::class, |
| 70 | Migrations\AddAmountColumnToEventTicketsTable::class, |
| 71 | ]); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @since 3.6.0 |
| 76 | */ |
| 77 | private function registerRoutes(): void |
| 78 | { |
| 79 | Hooks::addAction('rest_api_init', Routes\CreateEvent::class, 'registerRoute'); |
| 80 | Hooks::addAction('rest_api_init', Routes\CreateEventTicketType::class, 'registerRoute'); |
| 81 | Hooks::addAction('rest_api_init', Routes\DeleteEventsListTable::class, 'registerRoute'); |
| 82 | Hooks::addAction('rest_api_init', Routes\DeleteEventTicketType::class, 'registerRoute'); |
| 83 | Hooks::addAction('rest_api_init', Routes\GetEvents::class, 'registerRoute'); |
| 84 | Hooks::addAction('rest_api_init', Routes\GetEventsListTable::class, 'registerRoute'); |
| 85 | Hooks::addAction('rest_api_init', Routes\GetEventForms::class, 'registerRoute'); |
| 86 | Hooks::addAction('rest_api_init', Routes\GetEventTickets::class, 'registerRoute'); |
| 87 | Hooks::addAction('rest_api_init', Routes\GetEventTicketTypes::class, 'registerRoute'); |
| 88 | Hooks::addAction('rest_api_init', Routes\GetEventTicketTypeTickets::class, 'registerRoute'); |
| 89 | Hooks::addAction('rest_api_init', Routes\UpdateEvent::class, 'registerRoute'); |
| 90 | Hooks::addAction('rest_api_init', Routes\UpdateEventTicketType::class, 'registerRoute'); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @since 3.6.0 |
| 95 | */ |
| 96 | private function registerMenus(): void |
| 97 | { |
| 98 | Hooks::addAction('admin_menu', RegisterEventsMenuItem::class, '__invoke', 15); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @since 3.6.0 |
| 103 | */ |
| 104 | private function registerFormExtension() |
| 105 | { |
| 106 | Hooks::addAction('givewp_form_builder_enqueue_scripts', Actions\EnqueueFormBuilderScripts::class); |
| 107 | Hooks::addAction('givewp_donation_form_enqueue_scripts', Actions\EnqueueDonationFormScripts::class); |
| 108 | Hooks::addFilter( |
| 109 | 'givewp_donation_form_block_render_givewp/event-tickets', |
| 110 | RenderDonationFormBlock::class, |
| 111 | '__invoke', |
| 112 | 10, |
| 113 | 4 |
| 114 | ); |
| 115 | |
| 116 | //TODO: write unit tests for these actions |
| 117 | Hooks::addAction('givewp_generate_confirmation_page_receipt_before_donation_total', AddEventTicketsToDonationConfirmationPageDonationTotal::class); |
| 118 | Hooks::addAction('givewp_generate_confirmation_page_receipt_fill_event_ticket_details', AddEventTicketsToDonationConfirmationPageEventTicketDetails::class); |
| 119 | Hooks::addFilter('givewp_generate_confirmation_page_receipt_detail_donation_amount', UpdateDonationConfirmationPageReceiptDonationAmount::class, '__invoke', 10, 2); |
| 120 | } |
| 121 | } |
| 122 |