fix gitlab tests
This commit is contained in:
@@ -11,7 +11,9 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CurrentIncidentService
|
||||
{
|
||||
public function __construct(private IncidentLookupService $lookup) {}
|
||||
public function __construct(private IncidentLookupService $lookup)
|
||||
{
|
||||
}
|
||||
|
||||
public function listCurrent(): array
|
||||
{
|
||||
@@ -21,7 +23,7 @@ class CurrentIncidentService
|
||||
$updaterIds = [];
|
||||
foreach ($incidents as $incident) {
|
||||
foreach (['updated_by_open', 'updated_by_closed', 'updated_by_canceled'] as $key) {
|
||||
if (! empty($incident[$key])) {
|
||||
if (!empty($incident[$key])) {
|
||||
$updaterIds[] = (int) $incident[$key];
|
||||
}
|
||||
}
|
||||
@@ -31,7 +33,7 @@ class CurrentIncidentService
|
||||
foreach ($incidents as &$incident) {
|
||||
foreach (['updated_by_open', 'updated_by_closed', 'updated_by_canceled'] as $key) {
|
||||
$id = (int) ($incident[$key] ?? 0);
|
||||
$incident[$key.'_name'] = $id > 0 ? ($updaterMap[$id] ?? null) : null;
|
||||
$incident[$key . '_name'] = $id > 0 ? ($updaterMap[$id] ?? null) : null;
|
||||
}
|
||||
}
|
||||
unset($incident);
|
||||
@@ -60,7 +62,7 @@ class CurrentIncidentService
|
||||
->get()
|
||||
->map(fn ($student) => [
|
||||
'id' => (int) $student->id,
|
||||
'name' => trim((string) $student->firstname.' '.(string) $student->lastname),
|
||||
'name' => trim((string) $student->firstname . ' ' . (string) $student->lastname),
|
||||
])
|
||||
->all();
|
||||
}
|
||||
@@ -75,7 +77,7 @@ class CurrentIncidentService
|
||||
$grade = (string) $payload['grade'];
|
||||
|
||||
$student = Student::query()->find($studentId);
|
||||
if (! $student) {
|
||||
if (!$student) {
|
||||
return [
|
||||
'ok' => false,
|
||||
'message' => 'Student not found.',
|
||||
@@ -119,7 +121,7 @@ class CurrentIncidentService
|
||||
|
||||
$incident = CurrentIncident::query()->create([
|
||||
'student_id' => $student->id,
|
||||
'student_name' => trim((string) $student->firstname.' '.(string) $student->lastname),
|
||||
'student_name' => trim((string) $student->firstname . ' ' . (string) $student->lastname),
|
||||
'grade' => $grade,
|
||||
'incident' => $incidentType,
|
||||
'incident_datetime' => $currentDateTime,
|
||||
@@ -147,7 +149,7 @@ class CurrentIncidentService
|
||||
public function closeIncident(int $incidentId, string $closeDescription, ?string $actionTaken, int $userId): array
|
||||
{
|
||||
$incident = CurrentIncident::query()->find($incidentId);
|
||||
if (! $incident) {
|
||||
if (!$incident) {
|
||||
return ['ok' => false, 'message' => 'Incident not found.'];
|
||||
}
|
||||
|
||||
@@ -169,7 +171,7 @@ class CurrentIncidentService
|
||||
public function cancelIncident(int $incidentId, ?string $cancelDescription, ?string $actionTaken, int $userId): array
|
||||
{
|
||||
$incident = CurrentIncident::query()->find($incidentId);
|
||||
if (! $incident) {
|
||||
if (!$incident) {
|
||||
return ['ok' => false, 'message' => 'Incident not found.'];
|
||||
}
|
||||
|
||||
@@ -226,6 +228,6 @@ class CurrentIncidentService
|
||||
return $append;
|
||||
}
|
||||
|
||||
return $existing.PHP_EOL.$append;
|
||||
return $existing . PHP_EOL . $append;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ use App\Models\Incident;
|
||||
|
||||
class IncidentAnalysisService
|
||||
{
|
||||
public function __construct(private IncidentLookupService $lookup) {}
|
||||
public function __construct(private IncidentLookupService $lookup)
|
||||
{
|
||||
}
|
||||
|
||||
public function analyze(?string $schoolYear, ?string $semester): array
|
||||
{
|
||||
@@ -29,7 +31,7 @@ class IncidentAnalysisService
|
||||
foreach ($incidents as $incident) {
|
||||
$studentId = (string) ($incident['student_id'] ?? '');
|
||||
$studentName = (string) ($incident['student_name'] ?? '');
|
||||
$studentKey = $studentId !== '' ? 'id:'.$studentId : 'name:'.strtolower(trim($studentName));
|
||||
$studentKey = $studentId !== '' ? 'id:' . $studentId : 'name:' . strtolower(trim($studentName));
|
||||
|
||||
$gradeValue = $incident['grade'] ?? '';
|
||||
$gradeLabel = $gradeValue;
|
||||
@@ -37,7 +39,7 @@ class IncidentAnalysisService
|
||||
$gradeLabel = $gradeMap[(int) $gradeValue] ?? (string) $gradeValue;
|
||||
}
|
||||
|
||||
if (! isset($students[$studentKey])) {
|
||||
if (!isset($students[$studentKey])) {
|
||||
$students[$studentKey] = [
|
||||
'student_id' => $studentId,
|
||||
'student_name' => $studentName,
|
||||
@@ -82,7 +84,6 @@ class IncidentAnalysisService
|
||||
if ($a['total'] === $b['total']) {
|
||||
return strcasecmp($a['student_name'], $b['student_name']);
|
||||
}
|
||||
|
||||
return $b['total'] <=> $a['total'];
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ use App\Models\Incident;
|
||||
|
||||
class IncidentHistoryService
|
||||
{
|
||||
public function __construct(private IncidentLookupService $lookup) {}
|
||||
public function __construct(private IncidentLookupService $lookup)
|
||||
{
|
||||
}
|
||||
|
||||
public function history(?string $schoolYear, ?string $semester): array
|
||||
{
|
||||
@@ -33,7 +35,7 @@ class IncidentHistoryService
|
||||
$updaterIds = [];
|
||||
foreach ($incidents as $incident) {
|
||||
foreach (['updated_by_open', 'updated_by_closed', 'updated_by_canceled'] as $key) {
|
||||
if (! empty($incident[$key])) {
|
||||
if (!empty($incident[$key])) {
|
||||
$updaterIds[] = (int) $incident[$key];
|
||||
}
|
||||
}
|
||||
@@ -44,7 +46,7 @@ class IncidentHistoryService
|
||||
foreach ($incidents as &$incident) {
|
||||
foreach (['updated_by_open', 'updated_by_closed', 'updated_by_canceled'] as $key) {
|
||||
$id = (int) ($incident[$key] ?? 0);
|
||||
$incident[$key.'_name'] = $id > 0 ? ($updaterMap[$id] ?? null) : null;
|
||||
$incident[$key . '_name'] = $id > 0 ? ($updaterMap[$id] ?? null) : null;
|
||||
}
|
||||
|
||||
$gradeValue = $incident['grade'] ?? '';
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Services\Incidents;
|
||||
|
||||
use App\Models\ClassSection;
|
||||
use App\Models\StudentClass;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class IncidentLookupService
|
||||
@@ -73,7 +72,7 @@ class IncidentLookupService
|
||||
->select('id', 'firstname', 'lastname')
|
||||
->whereIn('id', $userIds)
|
||||
->get()
|
||||
->map(fn ($row) => $row instanceof Arrayable ? $row->toArray() : (array) $row)
|
||||
->map(fn ($row) => $row instanceof \Illuminate\Contracts\Support\Arrayable ? $row->toArray() : (array) $row)
|
||||
->all();
|
||||
|
||||
$map = [];
|
||||
@@ -82,8 +81,8 @@ class IncidentLookupService
|
||||
if ($id === null) {
|
||||
continue;
|
||||
}
|
||||
$name = trim((string) ($row['firstname'] ?? '').' '.(string) ($row['lastname'] ?? ''));
|
||||
$map[(int) $id] = $name !== '' ? $name : ('User #'.$id);
|
||||
$name = trim((string) ($row['firstname'] ?? '') . ' ' . (string) ($row['lastname'] ?? ''));
|
||||
$map[(int) $id] = $name !== '' ? $name : ('User #' . $id);
|
||||
}
|
||||
|
||||
return $map;
|
||||
|
||||
Reference in New Issue
Block a user