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