Skip to content

Commit 4b7ad9c

Browse files
feat: add new formatters for Tickets
1 parent a87252f commit 4b7ad9c

8 files changed

Lines changed: 920 additions & 0 deletions
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2026 OpenStack Foundation
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
use App\Audit\AbstractAuditLogFormatter;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\PrePaidSummitRegistrationDiscountCode;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class PrePaidSummitRegistrationDiscountCodeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof PrePaidSummitRegistrationDiscountCode) {
28+
return null;
29+
}
30+
31+
try {
32+
$code = $subject->getCode() ?? 'Unknown';
33+
$id = $subject->getId() ?? 'unknown';
34+
$summit = $subject->getSummit();
35+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
36+
37+
$rate = ($subject->getRate() ?? 0) * 100;
38+
$amount = $subject->getAmount() ?? 0;
39+
$discount_display = $rate > 0 ? sprintf("%.2f%%", $rate) : sprintf("$%.2f", $amount);
40+
41+
$quantity_available = $subject->getQuantityAvailable() ?? 0;
42+
$is_active = $subject->isLive() ? 'active' : 'inactive';
43+
44+
switch ($this->event_type) {
45+
case IAuditStrategy::EVENT_ENTITY_CREATION:
46+
return sprintf(
47+
"Pre-Paid Discount Code '%s' (%d) created for Summit '%s': discount %s, %d uses, status: %s by user %s",
48+
$code,
49+
$id,
50+
$summit_name,
51+
$discount_display,
52+
$quantity_available,
53+
$is_active,
54+
$this->getUserInfo()
55+
);
56+
57+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
58+
$change_details = $this->buildChangeDetails($change_set);
59+
return sprintf(
60+
"Pre-Paid Discount Code '%s' (%d) for Summit '%s' updated: %s by user %s",
61+
$code,
62+
$id,
63+
$summit_name,
64+
$change_details,
65+
$this->getUserInfo()
66+
);
67+
68+
case IAuditStrategy::EVENT_ENTITY_DELETION:
69+
$quantity_used = ($subject->getQuantityAvailable() ?? 0) - ($quantity_available ?? 0);
70+
return sprintf(
71+
"Pre-Paid Discount Code '%s' (%d) for Summit '%s' (discount: %s, %d used of %d, status: %s) was deleted by user %s",
72+
$code,
73+
$id,
74+
$summit_name,
75+
$discount_display,
76+
abs($quantity_used),
77+
$quantity_available,
78+
$is_active,
79+
$this->getUserInfo()
80+
);
81+
}
82+
} catch (\Exception $ex) {
83+
Log::warning("PrePaidSummitRegistrationDiscountCodeAuditLogFormatter error: " . $ex->getMessage());
84+
}
85+
86+
return null;
87+
}
88+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2026 OpenStack Foundation
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
use App\Audit\AbstractAuditLogFormatter;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\SummitRefundPolicyType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitRefundPolicyTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitRefundPolicyType) {
28+
return null;
29+
}
30+
31+
try {
32+
$name = $subject->getName() ?? 'Unknown';
33+
$id = $subject->getId() ?? 'unknown';
34+
$summit = $subject->getSummit();
35+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
36+
$days_before = $subject->getUntilXDaysBeforeEventStarts() ?? 0;
37+
$refund_rate = ($subject->getRefundRate() ?? 0) * 100;
38+
39+
switch ($this->event_type) {
40+
case IAuditStrategy::EVENT_ENTITY_CREATION:
41+
return sprintf(
42+
"Refund Policy '%s' (%d) created for Summit '%s': %d%% refund if cancelled %d days before event by user %s",
43+
$name,
44+
$id,
45+
$summit_name,
46+
$refund_rate,
47+
$days_before,
48+
$this->getUserInfo()
49+
);
50+
51+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
52+
$change_details = $this->buildChangeDetails($change_set);
53+
return sprintf(
54+
"Refund Policy '%s' (%d) for Summit '%s' updated: %s by user %s",
55+
$name,
56+
$id,
57+
$summit_name,
58+
$change_details,
59+
$this->getUserInfo()
60+
);
61+
62+
case IAuditStrategy::EVENT_ENTITY_DELETION:
63+
return sprintf(
64+
"Refund Policy '%s' (%d) for Summit '%s' (%d%% refund, %d days before) was deleted by user %s",
65+
$name,
66+
$id,
67+
$summit_name,
68+
$refund_rate,
69+
$days_before,
70+
$this->getUserInfo()
71+
);
72+
}
73+
} catch (\Exception $ex) {
74+
Log::warning("SummitRefundPolicyTypeAuditLogFormatter error: " . $ex->getMessage());
75+
}
76+
77+
return null;
78+
}
79+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2026 OpenStack Foundation
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
use App\Audit\AbstractAuditLogFormatter;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\SummitTaxType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitTaxTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitTaxType) {
28+
return null;
29+
}
30+
31+
try {
32+
$name = $subject->getName() ?? 'Unknown';
33+
$id = $subject->getId() ?? 'unknown';
34+
$summit = $subject->getSummit();
35+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
36+
$tax_id = $subject->getTaxId() ?? 'Not set';
37+
$rate = ($subject->getRate() ?? 0) * 100;
38+
39+
switch ($this->event_type) {
40+
case IAuditStrategy::EVENT_ENTITY_CREATION:
41+
$ticket_types_count = $subject->getTicketTypes()->count();
42+
return sprintf(
43+
"Tax Type '%s' (%d) created for Summit '%s': Tax ID %s, rate %.2f%%, applied to %d ticket types by user %s",
44+
$name,
45+
$id,
46+
$summit_name,
47+
$tax_id,
48+
$rate,
49+
$ticket_types_count,
50+
$this->getUserInfo()
51+
);
52+
53+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
54+
$change_details = $this->buildChangeDetails($change_set);
55+
return sprintf(
56+
"Tax Type '%s' (%d) for Summit '%s' updated: %s by user %s",
57+
$name,
58+
$id,
59+
$summit_name,
60+
$change_details,
61+
$this->getUserInfo()
62+
);
63+
64+
case IAuditStrategy::EVENT_ENTITY_DELETION:
65+
$ticket_types_count = $subject->getTicketTypes()->count();
66+
return sprintf(
67+
"Tax Type '%s' (%d) for Summit '%s' (Tax ID: %s, rate: %.2f%%, applied to %d ticket types) was deleted by user %s",
68+
$name,
69+
$id,
70+
$summit_name,
71+
$tax_id,
72+
$rate,
73+
$ticket_types_count,
74+
$this->getUserInfo()
75+
);
76+
}
77+
} catch (\Exception $ex) {
78+
Log::warning("SummitTaxTypeAuditLogFormatter error: " . $ex->getMessage());
79+
}
80+
81+
return null;
82+
}
83+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace App\Audit\ConcreteFormatters;
4+
5+
/**
6+
* Copyright 2026 OpenStack Foundation
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
18+
use App\Audit\AbstractAuditLogFormatter;
19+
use App\Audit\Interfaces\IAuditStrategy;
20+
use models\summit\SummitTicketType;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SummitTicketTypeAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SummitTicketType) {
28+
return null;
29+
}
30+
31+
try {
32+
$name = $subject->getName() ?? 'Unknown';
33+
$id = $subject->getId() ?? 'unknown';
34+
$summit = $subject->getSummit();
35+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
36+
$cost = $subject->getCost() ?? 0;
37+
$currency = $subject->getCurrency() ?? 'USD';
38+
$quantity_available = $subject->getQuantity2Sell() ?? 0;
39+
$audience = $subject->getAudience() ?? 'All';
40+
41+
switch ($this->event_type) {
42+
case IAuditStrategy::EVENT_ENTITY_CREATION:
43+
return sprintf(
44+
"Ticket Type '%s' (%d) created for Summit '%s': price %s %s, %d available, audience: %s by user %s",
45+
$name,
46+
$id,
47+
$summit_name,
48+
$cost,
49+
$currency,
50+
$quantity_available,
51+
$audience,
52+
$this->getUserInfo()
53+
);
54+
55+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
56+
$change_details = $this->buildChangeDetails($change_set);
57+
return sprintf(
58+
"Ticket Type '%s' (%d) for Summit '%s' updated: %s by user %s",
59+
$name,
60+
$id,
61+
$summit_name,
62+
$change_details,
63+
$this->getUserInfo()
64+
);
65+
66+
case IAuditStrategy::EVENT_ENTITY_DELETION:
67+
$quantity_sold = $subject->getQuantitySold() ?? 0;
68+
return sprintf(
69+
"Ticket Type '%s' (%d) for Summit '%s' with price %s %s (%d sold, %d available) was deleted by user %s",
70+
$name,
71+
$id,
72+
$summit_name,
73+
$cost,
74+
$currency,
75+
$quantity_sold,
76+
$quantity_available,
77+
$this->getUserInfo()
78+
);
79+
}
80+
} catch (\Exception $ex) {
81+
Log::warning("SummitTicketTypeAuditLogFormatter error: " . $ex->getMessage());
82+
}
83+
84+
return null;
85+
}
86+
}

0 commit comments

Comments
 (0)