Skip to content

Commit 9943ec5

Browse files
andrestejerina97matiasperrone-exo
authored andcommitted
Feature:add new formatters for Tickets (#494)
* feat: add new formatters for Tickets * fix: change in ticket formatters * fix: remove operation for description * feat: add new fields on PrePaidSummitRegistrationDiscountCodeAuditLogFormatter * chore: Add requested changes --------- Co-authored-by: matiasperrone-exo <matias.perrone@exomindset.co>
1 parent 41104e5 commit 9943ec5

9 files changed

Lines changed: 1006 additions & 0 deletions
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
26+
private function buildDiscountDetails(PrePaidSummitRegistrationDiscountCode $subject): string
27+
{
28+
$details = [];
29+
30+
$rate = $subject->getRate();
31+
$amount = $subject->getAmount();
32+
$quantity_available = $subject->getQuantityAvailable();
33+
34+
if ($rate > 0) {
35+
$details[] = sprintf("rate: %.2f%%", $rate);
36+
}
37+
38+
if ($amount > 0) {
39+
$details[] = sprintf("amount: $%.2f", $amount);
40+
}
41+
42+
if ($quantity_available > 0) {
43+
$details[] = sprintf("quantity: %d", $quantity_available);
44+
}
45+
46+
return implode(", ", $details);
47+
}
48+
49+
public function format($subject, array $change_set): ?string
50+
{
51+
if (!$subject instanceof PrePaidSummitRegistrationDiscountCode) {
52+
return null;
53+
}
54+
55+
try {
56+
$code = $subject->getCode() ?? 'Unknown';
57+
$id = $subject->getId() ?? 'unknown';
58+
$summit = $subject->getSummit();
59+
$summit_name = $summit ? ($summit->getName() ?? 'Unknown Summit') : 'Unknown Summit';
60+
$discount_details = $this->buildDiscountDetails($subject);
61+
62+
switch ($this->event_type) {
63+
case IAuditStrategy::EVENT_ENTITY_CREATION:
64+
return sprintf(
65+
"Pre-Paid Discount Code '%s' (%d) created for Summit '%s' with %s by user %s",
66+
$code,
67+
$id,
68+
$summit_name,
69+
$discount_details,
70+
$this->getUserInfo()
71+
);
72+
73+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
74+
$change_details = $this->buildChangeDetails($change_set);
75+
return sprintf(
76+
"Pre-Paid Discount Code '%s' (%d) for Summit '%s' updated: %s (current: %s) by user %s",
77+
$code,
78+
$id,
79+
$summit_name,
80+
$change_details,
81+
$discount_details,
82+
$this->getUserInfo()
83+
);
84+
85+
case IAuditStrategy::EVENT_ENTITY_DELETION:
86+
return sprintf(
87+
"Pre-Paid Discount Code '%s' (%d) for Summit '%s' with %s was deleted by user %s",
88+
$code,
89+
$id,
90+
$summit_name,
91+
$discount_details,
92+
$this->getUserInfo()
93+
);
94+
}
95+
} catch (\Exception $ex) {
96+
Log::warning("PrePaidSummitRegistrationDiscountCodeAuditLogFormatter error: " . $ex->getMessage());
97+
}
98+
99+
return null;
100+
}
101+
}
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();
37+
$refund_rate = $subject->getRefundRate();
38+
39+
switch ($this->event_type) {
40+
case IAuditStrategy::EVENT_ENTITY_CREATION:
41+
return sprintf(
42+
"Refund Policy '%s' (%d) created for Summit '%s': %s%% refund if cancelled %s days before event by user %s",
43+
$name,
44+
$id,
45+
$summit_name,
46+
($refund_rate !== null ? sprintf("%.0f", $refund_rate) : 'N/A'),
47+
($days_before !== null ? $days_before : 'N/A'),
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' (%s%% refund, %s days before) was deleted by user %s",
65+
$name,
66+
$id,
67+
$summit_name,
68+
($refund_rate !== null ? sprintf("%.0f", $refund_rate) : 'N/A'),
69+
($days_before !== null ? $days_before : 'N/A'),
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: 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\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();
38+
39+
switch ($this->event_type) {
40+
case IAuditStrategy::EVENT_ENTITY_CREATION:
41+
return sprintf(
42+
"Tax Type '%s' (%d) created for Summit '%s': Tax ID %s, rate %s by user %s",
43+
$name,
44+
$id,
45+
$summit_name,
46+
$tax_id,
47+
($rate !== null ? sprintf("%.2f%%", $rate) : 'N/A'),
48+
$this->getUserInfo()
49+
);
50+
51+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
52+
$change_details = $this->buildChangeDetails($change_set);
53+
return sprintf(
54+
"Tax Type '%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+
"Tax Type '%s' (%d) for Summit '%s' (Tax ID: %s, rate: %s) was deleted by user %s",
65+
$name,
66+
$id,
67+
$summit_name,
68+
$tax_id,
69+
($rate !== null ? sprintf("%.2f%%", $rate) : 'N/A'),
70+
$this->getUserInfo()
71+
);
72+
}
73+
} catch (\Exception $ex) {
74+
Log::warning("SummitTaxTypeAuditLogFormatter error: " . $ex->getMessage());
75+
}
76+
77+
return null;
78+
}
79+
}
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();
37+
$currency = $subject->getCurrency() ?? 'USD';
38+
$quantity_available = $subject->getQuantity2Sell();
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, %s 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();
68+
return sprintf(
69+
"Ticket Type '%s' (%d) for Summit '%s' with price %s %s (%s sold, %s 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+
}

‎config/audit_log.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,5 +256,21 @@
256256
'enabled' => true,
257257
'strategy' => \App\Audit\ConcreteFormatters\ExtraQuestionTypeValueAuditLogFormatter::class,
258258
],
259+
\models\summit\SummitTaxType::class => [
260+
'enabled' => true,
261+
'strategy' => \App\Audit\ConcreteFormatters\SummitTaxTypeAuditLogFormatter::class,
262+
],
263+
\models\summit\SummitRefundPolicyType::class => [
264+
'enabled' => true,
265+
'strategy' => \App\Audit\ConcreteFormatters\SummitRefundPolicyTypeAuditLogFormatter::class,
266+
],
267+
\models\summit\SummitTicketType::class => [
268+
'enabled' => true,
269+
'strategy' => \App\Audit\ConcreteFormatters\SummitTicketTypeAuditLogFormatter::class,
270+
],
271+
\models\summit\PrePaidSummitRegistrationDiscountCode::class => [
272+
'enabled' => true,
273+
'strategy' => \App\Audit\ConcreteFormatters\PrePaidSummitRegistrationDiscountCodeAuditLogFormatter::class,
274+
],
259275
]
260276
];

0 commit comments

Comments
 (0)