-
Notifications
You must be signed in to change notification settings - Fork 1
/
Actions.php
86 lines (76 loc) · 2.65 KB
/
Actions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace TheBooking;
use TheBooking\Bus\Commands\DeleteCustomer;
use TheBooking\Bus\Commands\DeleteReservation;
use TheBooking\Bus\Commands\DeleteService;
defined('ABSPATH') || exit;
/**
* Class Actions
*
* @package TheBooking
* @author VonStroheim
*/
final class Actions
{
public static function load_actions()
{
tbkg()->loader->add_action('tbk_dispatched_DeleteService', self::class, 'delete_reservations_after_service');
tbkg()->loader->add_action('tbk_dispatched_DeleteService', self::class, 'delete_interactions_with_service');
tbkg()->loader->add_action('tbk_dispatched_DeleteCustomer', self::class, 'delete_reservations_after_customer');
tbkg()->loader->add_action('updated_option', self::class, 'updatedTimezone', 10, 3);
}
/**
* @param string $option_name
* @param string $old
* @param string $new
*/
public static function updatedTimezone($option_name, $old, $new)
{
if ($option_name === 'timezone_string') {
// It could be useful in the future.
}
}
/**
* Removes interactions with a service after it is removed.
*
* @param DeleteService $command
*/
public static function delete_interactions_with_service(DeleteService $command)
{
$serviceFactory = tbkg()->services;
foreach ($serviceFactory->all() as $service) {
$blocksList = $service->getMeta('blocksOtherList');
if (is_array($blocksList) && ($key = array_search($command->getUid(), $blocksList, TRUE)) !== FALSE) {
unset($blocksList[ $key ]);
}
$service->addMeta('blocksOtherList', $blocksList);
$serviceFactory::update($service);
}
}
/**
* Ensures that reservations are removed after a service is removed.
*
* @param DeleteService $command
*/
public static function delete_reservations_after_service(DeleteService $command)
{
foreach (tbkg()->reservations->all() as $reservation) {
if ($reservation->service_id() === $command->getUid()) {
tbkg()->bus->dispatch(new DeleteReservation($reservation->id()));
}
}
}
/**
* Ensures that reservations are removed after a customer is removed.
*
* @param DeleteCustomer $command
*/
public static function delete_reservations_after_customer(DeleteCustomer $command)
{
foreach (tbkg()->reservations->all() as $reservation) {
if ($reservation->customer_id() === $command->getId()) {
tbkg()->bus->dispatch(new DeleteReservation($reservation->id()));
}
}
}
}