Skip to content

Commit c95cb51

Browse files
Feature: add new formatters for sponsors (#497)
* feat: add new formatters for sponsors Signed-off-by: Jose Andres Tejerina <andres.tejerina@exomindset.co>[C * feat: add new audit log for sponsors * fix: merge conflicts * fix: add new UT and fix for formatters * fix: change the test structure --------- Signed-off-by: Jose Andres Tejerina <andres.tejerina@exomindset.co>[C
1 parent 90e81ab commit c95cb51

21 files changed

Lines changed: 1928 additions & 0 deletions
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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\SponsorAd;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SponsorAdAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SponsorAd) {
28+
return null;
29+
}
30+
31+
try {
32+
$text = $subject->getText() ?? 'No Text';
33+
$sponsor = $subject->getSponsor();
34+
$sponsor_id = $sponsor ? ($sponsor->getId() ?? 'unknown') : 'unknown';
35+
$sponsor_company = $sponsor && $sponsor->getCompany() ? ($sponsor->getCompany()->getName() ?? 'Unknown Company') : 'Unknown Company';
36+
37+
switch ($this->event_type) {
38+
case IAuditStrategy::EVENT_ENTITY_CREATION:
39+
return sprintf(
40+
"Sponsor Ad '%s' for Sponsor %s ('%s') created by user %s",
41+
$text,
42+
$sponsor_id,
43+
$sponsor_company,
44+
$this->getUserInfo()
45+
);
46+
47+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
48+
$details = $this->buildChangeDetails($change_set);
49+
return sprintf(
50+
"Sponsor Ad '%s' for Sponsor %s updated: %s by user %s",
51+
$text,
52+
$sponsor_id,
53+
$details,
54+
$this->getUserInfo()
55+
);
56+
57+
case IAuditStrategy::EVENT_ENTITY_DELETION:
58+
return sprintf(
59+
"Sponsor Ad '%s' for Sponsor %s deleted by user %s",
60+
$text,
61+
$sponsor_id,
62+
$this->getUserInfo()
63+
);
64+
}
65+
} catch (\Exception $ex) {
66+
Log::warning("SponsorAdAuditLogFormatter error: " . $ex->getMessage());
67+
}
68+
69+
return null;
70+
}
71+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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\SponsorBadgeScan;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SponsorBadgeScanAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SponsorBadgeScan) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
$scan_date = $subject->getScanDate();
34+
$scan_date_str = $scan_date ? $scan_date->format('Y-m-d H:i:s') : 'Unknown Date';
35+
$user = $subject->getUser();
36+
$user_email = $user ? ($user->getEmail() ?? 'Unknown User') : 'Unknown User';
37+
$sponsor = $subject->getSponsor();
38+
$sponsor_id = $sponsor ? ($sponsor->getId() ?? 'unknown') : 'unknown';
39+
40+
switch ($this->event_type) {
41+
case IAuditStrategy::EVENT_ENTITY_CREATION:
42+
return sprintf(
43+
"Sponsor Badge Scan (ID: %s) for user '%s' scanned on '%s' by Sponsor %s created by user %s",
44+
$id,
45+
$user_email,
46+
$scan_date_str,
47+
$sponsor_id,
48+
$this->getUserInfo()
49+
);
50+
51+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
52+
$details = $this->buildChangeDetails($change_set);
53+
return sprintf(
54+
"Sponsor Badge Scan (ID: %s) for Sponsor %s updated: %s by user %s",
55+
$id,
56+
$sponsor_id,
57+
$details,
58+
$this->getUserInfo()
59+
);
60+
61+
case IAuditStrategy::EVENT_ENTITY_DELETION:
62+
return sprintf(
63+
"Sponsor Badge Scan (ID: %s) for user '%s' by Sponsor %s deleted by user %s",
64+
$id,
65+
$user_email,
66+
$sponsor_id,
67+
$this->getUserInfo()
68+
);
69+
}
70+
} catch (\Exception $ex) {
71+
Log::warning("SponsorBadgeScanAuditLogFormatter error: " . $ex->getMessage());
72+
}
73+
74+
return null;
75+
}
76+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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\SponsorBadgeScanExtraQuestionAnswer;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SponsorBadgeScanExtraQuestionAnswerAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SponsorBadgeScanExtraQuestionAnswer) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
$value = $subject->getValue() ?? 'No Value';
34+
$question = $subject->getQuestion();
35+
$question_label = $question ? ($question->getLabel() ?? 'Unknown Question') : 'Unknown Question';
36+
$badge_scan = $subject->getBadgeScan();
37+
$sponsor_id = $badge_scan && $badge_scan->getSponsor() ? ($badge_scan->getSponsor()->getId() ?? 'unknown') : 'unknown';
38+
39+
switch ($this->event_type) {
40+
case IAuditStrategy::EVENT_ENTITY_CREATION:
41+
return sprintf(
42+
"Sponsor Badge Scan Extra Question Answer (ID: %s) for question '%s' with value '%s' created for Sponsor %s by user %s",
43+
$id,
44+
$question_label,
45+
$value,
46+
$sponsor_id,
47+
$this->getUserInfo()
48+
);
49+
50+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
51+
$details = $this->buildChangeDetails($change_set);
52+
return sprintf(
53+
"Sponsor Badge Scan Extra Question Answer (ID: %s) for question '%s' updated: %s by user %s",
54+
$id,
55+
$question_label,
56+
$details,
57+
$this->getUserInfo()
58+
);
59+
60+
case IAuditStrategy::EVENT_ENTITY_DELETION:
61+
return sprintf(
62+
"Sponsor Badge Scan Extra Question Answer (ID: %s) for question '%s' deleted by user %s",
63+
$id,
64+
$question_label,
65+
$this->getUserInfo()
66+
);
67+
}
68+
} catch (\Exception $ex) {
69+
Log::warning("SponsorBadgeScanExtraQuestionAnswerAuditLogFormatter error: " . $ex->getMessage());
70+
}
71+
72+
return null;
73+
}
74+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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\SponsorMaterial;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SponsorMaterialAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SponsorMaterial) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
$name = $subject->getName() ?? 'No Name';
34+
$type = $subject->getType() ?? 'Unknown Type';
35+
$order = $subject->getOrder() ? (string)$subject->getOrder() : 'unknown';
36+
$sponsor = $subject->getSponsor();
37+
$sponsor_id = $sponsor ? ($sponsor->getId() ?? 'unknown') : 'unknown';
38+
39+
switch ($this->event_type) {
40+
case IAuditStrategy::EVENT_ENTITY_CREATION:
41+
return sprintf(
42+
"Sponsor Material (ID: %s) '%s' type '%s' (Order: %s) for Sponsor %s created by user %s",
43+
$id,
44+
$name,
45+
$type,
46+
$order,
47+
$sponsor_id,
48+
$this->getUserInfo()
49+
);
50+
51+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
52+
$details = $this->buildChangeDetails($change_set);
53+
return sprintf(
54+
"Sponsor Material (ID: %s) '%s' for Sponsor %s updated: %s by user %s",
55+
$id,
56+
$name,
57+
$sponsor_id,
58+
$details,
59+
$this->getUserInfo()
60+
);
61+
62+
case IAuditStrategy::EVENT_ENTITY_DELETION:
63+
return sprintf(
64+
"Sponsor Material (ID: %s) '%s' type '%s' for Sponsor %s deleted by user %s",
65+
$id,
66+
$name,
67+
$type,
68+
$sponsor_id,
69+
$this->getUserInfo()
70+
);
71+
}
72+
} catch (\Exception $ex) {
73+
Log::warning("SponsorMaterialAuditLogFormatter error: " . $ex->getMessage());
74+
}
75+
76+
return null;
77+
}
78+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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\SponsorSocialNetwork;
21+
use Illuminate\Support\Facades\Log;
22+
23+
class SponsorSocialNetworkAuditLogFormatter extends AbstractAuditLogFormatter
24+
{
25+
public function format($subject, array $change_set): ?string
26+
{
27+
if (!$subject instanceof SponsorSocialNetwork) {
28+
return null;
29+
}
30+
31+
try {
32+
$id = $subject->getId() ?? 'unknown';
33+
$link = $subject->getLink() ?? 'No Link';
34+
$icon = $subject->getIconCSSClass() ?? 'No Icon';
35+
$sponsor = $subject->getSponsor();
36+
$sponsor_id = $sponsor ? ($sponsor->getId() ?? 'unknown') : 'unknown';
37+
38+
switch ($this->event_type) {
39+
case IAuditStrategy::EVENT_ENTITY_CREATION:
40+
return sprintf(
41+
"Sponsor Social Network (ID: %s) '%s' with icon '%s' for Sponsor %s created by user %s",
42+
$id,
43+
$link,
44+
$icon,
45+
$sponsor_id,
46+
$this->getUserInfo()
47+
);
48+
49+
case IAuditStrategy::EVENT_ENTITY_UPDATE:
50+
$details = $this->buildChangeDetails($change_set);
51+
return sprintf(
52+
"Sponsor Social Network (ID: %s) for Sponsor %s updated: %s by user %s",
53+
$id,
54+
$sponsor_id,
55+
$details,
56+
$this->getUserInfo()
57+
);
58+
59+
case IAuditStrategy::EVENT_ENTITY_DELETION:
60+
return sprintf(
61+
"Sponsor Social Network (ID: %s) '%s' for Sponsor %s deleted by user %s",
62+
$id,
63+
$link,
64+
$sponsor_id,
65+
$this->getUserInfo()
66+
);
67+
}
68+
} catch (\Exception $ex) {
69+
Log::warning("SponsorSocialNetworkAuditLogFormatter error: " . $ex->getMessage());
70+
}
71+
72+
return null;
73+
}
74+
}

0 commit comments

Comments
 (0)