PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / Booking / Event / GenerateEventWpaCustomPostCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Event Last commit date
Tag 3 months ago AddEventCommand.php 1 year ago AddEventCommandHandler.php 1 week ago DeleteEventBookingCommand.php 7 years ago DeleteEventBookingCommandHandler.php 1 week ago DeleteEventCommand.php 1 year ago DeleteEventCommandHandler.php 7 months ago DeleteEventsCommand.php 7 months ago DeleteEventsCommandHandler.php 4 months ago GenerateEventWpaCustomPostCommand.php 4 weeks ago GenerateEventWpaCustomPostCommandHandler.php 4 weeks ago GetCalendarEventsCommand.php 1 year ago GetCalendarEventsCommandHandler.php 1 week ago GetEventBookingCommand.php 7 months ago GetEventBookingCommandHandler.php 1 week ago GetEventBookingsCommand.php 1 year ago GetEventBookingsCommandHandler.php 1 week ago GetEventCommand.php 7 years ago GetEventCommandHandler.php 1 week ago GetEventsCommand.php 1 year ago GetEventsCommandHandler.php 1 week ago UpdateEventBookingCommand.php 7 years ago UpdateEventBookingCommandHandler.php 7 months ago UpdateEventCommand.php 1 year ago UpdateEventCommandHandler.php 1 week ago UpdateEventStatusCommand.php 1 year ago UpdateEventStatusCommandHandler.php 7 months ago UpdateEventVisibilityCommand.php 7 months ago UpdateEventVisibilityCommandHandler.php 7 months ago
GenerateEventWpaCustomPostCommandHandler.php
113 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Application\Commands\Booking\Event;
9
10 use AmeliaBooking\Application\Commands\CommandHandler;
11 use AmeliaBooking\Application\Commands\CommandResult;
12 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
13 use AmeliaBooking\Application\Services\Booking\EventApplicationService;
14 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
15 use AmeliaBooking\Domain\Entity\Entities;
16 use AmeliaBooking\Infrastructure\WP\CustomPostTypes\Events\WpaEventsSync;
17
18 /**
19 * Creates the WordPress wpa-events custom post for an event when missing (admin action).
20 *
21 * @package AmeliaBooking\Application\Commands\Booking\Event
22 */
23 class GenerateEventWpaCustomPostCommandHandler extends CommandHandler
24 {
25 /**
26 * @param GenerateEventWpaCustomPostCommand $command
27 *
28 * @return CommandResult
29 */
30 public function handle(GenerateEventWpaCustomPostCommand $command)
31 {
32 $result = new CommandResult();
33
34 /** @var EventApplicationService $eventApplicationService */
35 $eventApplicationService = $this->container->get('application.booking.event.service');
36
37 if (!$command->getPermissionService()->currentUserCanWrite(Entities::EVENTS)) {
38 throw new AccessDeniedException('You are not allowed to manage events');
39 }
40
41 $eventId = (int)$command->getField('id');
42 if ($eventId <= 0) {
43 $result->setResult(CommandResult::RESULT_CONFLICT);
44 $result->setMessage(__('Invalid event.', 'wpamelia'));
45
46 return $result;
47 }
48
49 /** @var Event|null $event */
50 $event = $eventApplicationService->getEventById(
51 $eventId,
52 [
53 'fetchEventsPeriods' => false,
54 'fetchEventsTickets' => false,
55 'fetchEventsTags' => false,
56 'fetchEventsProviders' => false,
57 'fetchEventsImages' => false,
58 'fetchBookings' => false,
59 'fetchBookingsTickets' => false,
60 'fetchBookingsUsers' => false,
61 'fetchBookingsPayments' => false,
62 'fetchBookingsCoupons' => false,
63 'fetchEventsOrganizer' => false,
64 'fetchEventsLocation' => false,
65 ]
66 );
67
68 if (!$event) {
69 $result->setResult(CommandResult::RESULT_CONFLICT);
70 $result->setMessage(__('Event not found.', 'wpamelia'));
71
72 return $result;
73 }
74
75 $eventArray = $event->toArray();
76
77 $postId = WpaEventsSync::findPostIdByAmeliaEventId($eventId);
78 $alreadyExisted = $postId > 0;
79
80 if (!$postId) {
81 WpaEventsSync::createCptIfMissing($eventArray);
82 $postId = WpaEventsSync::findPostIdByAmeliaEventId($eventId);
83 }
84
85 if (!$postId) {
86 $result->setResult(CommandResult::RESULT_ERROR);
87 $result->setMessage(__('Could not create the WordPress custom post for this event.', 'wpamelia'));
88
89 return $result;
90 }
91
92 $permalink = get_permalink($postId);
93 $editLink = admin_url('post.php?post=' . $postId . '&action=edit');
94
95 $result->setResult(CommandResult::RESULT_SUCCESS);
96 $result->setMessage(
97 $alreadyExisted
98 ? __('Custom post already exists for this event.', 'wpamelia')
99 : __('Custom post created.', 'wpamelia')
100 );
101 $result->setData(
102 [
103 'postId' => $postId,
104 'permalink' => $permalink ?: '',
105 'editLink' => $editLink,
106 'alreadyExisted' => $alreadyExisted,
107 ]
108 );
109
110 return $result;
111 }
112 }
113