fix invalid token
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 49s
Tests / PHPUnit (push) Successful in 1m20s

This commit is contained in:
root
2026-08-30 21:10:35 -04:00
parent 140be9922d
commit 332b0d1007
9 changed files with 217 additions and 112 deletions
@@ -47,6 +47,49 @@ class ParentAccountService
return true;
}
public function administratorParentList(): array
{
return $this->userModel->where('role', 'parent')->findAll();
}
public function parentById(int $id): ?array
{
$parent = $this->userModel->find($id);
return is_array($parent) ? $parent : null;
}
public function createAdministratorParent(array $post): bool|int|string
{
return $this->userModel->insert([
'firstname' => $post['firstname'] ?? null,
'lastname' => $post['lastname'] ?? null,
'email' => strtolower((string) ($post['email'] ?? '')),
'password' => password_hash((string) ($post['password'] ?? ''), PASSWORD_DEFAULT),
'role' => 'parent',
]);
}
public function updateAdministratorParent(int $id, array $post): bool
{
$data = [
'firstname' => $post['firstname'] ?? null,
'lastname' => $post['lastname'] ?? null,
'email' => strtolower((string) ($post['email'] ?? '')),
];
if (! empty($post['password'])) {
$data['password'] = password_hash((string) $post['password'], PASSWORD_DEFAULT);
}
return (bool) $this->userModel->update($id, $data);
}
public function deleteParent(int $id): bool
{
return (bool) $this->userModel->delete($id);
}
public function createRelatedUser(array $userData, string $relationToStudent, string $semester, string $schoolYear): int|false
{
$schoolIdService = new SchoolIdService();
@@ -0,0 +1,77 @@
<?php
namespace App\Services\Parents;
use App\Models\StudentModel;
use App\Models\UserModel;
use App\Services\EmailService;
use Throwable;
class ParentRegistrationNotificationService
{
public function __construct(
private readonly UserModel $userModel,
private readonly StudentModel $studentModel,
private readonly EmailService $emailService,
private readonly string $adminEmail = 'registration@alrahmaisgl.org',
) {
}
/**
* @param list<int> $studentIds
*/
public function sendAdminNewStudentEmails(array $studentIds, int $parentId): void
{
$parent = $this->userModel->find($parentId);
if (! is_array($parent)) {
log_message('warning', 'Unable to send admin student registration email: parent not found for ID ' . $parentId);
return;
}
foreach (array_values(array_unique(array_filter(array_map('intval', $studentIds)))) as $studentId) {
$student = $this->studentModel->find($studentId);
if (! is_array($student)) {
log_message('warning', 'Unable to send admin student registration email: student not found for ID ' . $studentId);
continue;
}
$this->sendAdminNewStudentEmail($student, $parent, $parentId);
}
}
/**
* @param array<string, mixed> $student
* @param array<string, mixed> $parent
*/
private function sendAdminNewStudentEmail(array $student, array $parent, int $parentId): void
{
$studentId = (int) ($student['id'] ?? 0);
$studentFullName = trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? ''))
?: 'Student ID ' . $studentId;
$payload = $student;
$payload['parents'] = [
'user_id' => $parentId,
'firstname' => (string) ($parent['firstname'] ?? ''),
'lastname' => (string) ($parent['lastname'] ?? ''),
'email' => (string) ($parent['email'] ?? ''),
];
$adminMessage = view('emails/admin_student_registered', ['student' => $payload], ['saveData' => true]);
try {
$sent = $this->emailService->send(
$this->adminEmail,
'New Student Registered: ' . $studentFullName,
$adminMessage,
'notifications'
);
if (! $sent) {
log_message('error', 'Admin student registration email failed for student ID ' . $studentId);
}
} catch (Throwable $e) {
log_message('error', 'Admin student registration email failed for student ID ' . $studentId . ': ' . $e->getMessage());
}
}
}