Skip to content

Commit 0065fe8

Browse files
chore: refactor getUserInfo to AbstractAuditLog
1 parent 1d76a6a commit 0065fe8

9 files changed

Lines changed: 32 additions & 121 deletions

app/Audit/AbstractAuditLogFormatter.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,22 @@ final public function setContext(AuditContext $ctx): void
2424
$this->ctx = $ctx;
2525
}
2626

27+
protected function getUserInfo(): string
28+
{
29+
if (!$this->ctx) {
30+
return 'Unknown (unknown)';
31+
}
32+
33+
$user_name = 'Unknown';
34+
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
35+
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
36+
} elseif ($this->ctx->userEmail) {
37+
$user_name = $this->ctx->userEmail;
38+
}
39+
40+
$user_id = $this->ctx->userId ?? 'unknown';
41+
return sprintf("%s (%s)", $user_name, $user_id);
42+
}
43+
2744
abstract public function format($subject, array $change_set): ?string;
2845
}

app/Audit/ConcreteFormatters/FeaturedSpeakerAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof FeaturedSpeaker) {

app/Audit/ConcreteFormatters/PresentationSpeakerAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof PresentationSpeaker) {

app/Audit/ConcreteFormatters/PresentationSubmissionAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof Presentation) {

app/Audit/ConcreteFormatters/SelectionPlanAuditLogFormatter.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
private function formatDate($date): string
5033
{
5134
if ($date instanceof \DateTime) {
@@ -68,20 +51,29 @@ public function format($subject, array $change_set): ?string
6851

6952
switch ($this->event_type) {
7053
case IAuditStrategy::EVENT_ENTITY_CREATION:
71-
$submission_dates = $subject->getSubmissionBeginDate() && $subject->getSubmissionEndDate()
54+
$submission_dates = $subject->hasSubmissionPeriodDefined()
7255
? sprintf(
7356
"[%s - %s]",
7457
$this->formatDate($subject->getSubmissionBeginDate()),
7558
$this->formatDate($subject->getSubmissionEndDate())
7659
)
7760
: 'No dates set';
7861

62+
$selection_dates = $subject->hasSelectionPeriodDefined()
63+
? sprintf(
64+
"[%s - %s]",
65+
$this->formatDate($subject->getSelectionBeginDate()),
66+
$this->formatDate($subject->getSelectionEndDate())
67+
)
68+
: 'No dates set';
69+
7970
return sprintf(
80-
"Selection Plan '%s' (%d) created for Summit '%s' with CFP period: %s by user %s",
71+
"Selection Plan '%s' (%d) created for Summit '%s' with CFP period: %s, selection period: %s by user %s",
8172
$name,
8273
$id,
8374
$summit_name,
8475
$submission_dates,
76+
$selection_dates,
8577
$this->getUserInfo()
8678
);
8779

app/Audit/ConcreteFormatters/SpeakerAssistanceAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof PresentationSpeakerSummitAssistanceConfirmationRequest) {

app/Audit/ConcreteFormatters/SpeakerRegistrationRequestAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof SpeakerRegistrationRequest) {

app/Audit/ConcreteFormatters/SubmissionInvitationAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ public function __construct(string $event_type)
2929
$this->event_type = $event_type;
3030
}
3131

32-
private function getUserInfo(): string
33-
{
34-
if (!$this->ctx) {
35-
return 'Unknown (unknown)';
36-
}
37-
38-
$user_name = 'Unknown';
39-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
40-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
41-
} elseif ($this->ctx->userEmail) {
42-
$user_name = $this->ctx->userEmail;
43-
}
44-
45-
$user_id = $this->ctx->userId ?? 'unknown';
46-
return sprintf("%s (%s)", $user_name, $user_id);
47-
}
48-
4932
public function format($subject, array $change_set): ?string
5033
{
5134
if (!$subject instanceof SummitSubmissionInvitation) {

app/Models/Foundation/Summit/SelectionPlan.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,10 @@ public function hasSelectionPeriodDefined():bool{
743743
return !is_null($this->selection_begin_date) && !is_null($this->selection_end_date);
744744
}
745745

746+
public function hasSubmissionPeriodDefined():bool{
747+
return !is_null($this->submission_begin_date) && !is_null($this->submission_end_date);
748+
}
749+
746750
/**
747751
* @return bool
748752
*/

0 commit comments

Comments
 (0)