fix invalid token
This commit is contained in:
@@ -26,6 +26,7 @@ use App\Services\Parents\ParentAttendanceService;
|
||||
use App\Services\Parents\ParentEnrollmentService;
|
||||
use App\Services\Parents\ParentEventParticipationService;
|
||||
use App\Services\Parents\ParentPaymentService;
|
||||
use App\Services\Parents\ParentRegistrationNotificationService;
|
||||
use App\Services\Parents\ParentRegistrationService;
|
||||
use App\Support\Enrollment\DeliberationDecision;
|
||||
use App\Support\Enrollment\EnrollmentEligibility;
|
||||
@@ -71,6 +72,7 @@ class ParentController extends BaseController
|
||||
protected ?ParentEnrollmentService $parentEnrollmentService = null;
|
||||
protected ParentEventParticipationService $parentEventParticipationService;
|
||||
protected ParentPaymentService $parentPaymentService;
|
||||
protected ParentRegistrationNotificationService $parentRegistrationNotificationService;
|
||||
protected ?ParentRegistrationService $parentRegistrationService = null;
|
||||
|
||||
|
||||
@@ -95,6 +97,11 @@ class ParentController extends BaseController
|
||||
$this->parentAccountService = new ParentAccountService($this->db, $this->userModel, $this->authorizedUsersModel);
|
||||
$this->parentAttendanceService = new ParentAttendanceService($this->db);
|
||||
$this->parentPaymentService = new ParentPaymentService($this->db);
|
||||
$this->parentRegistrationNotificationService = new ParentRegistrationNotificationService(
|
||||
$this->userModel,
|
||||
$this->studentModel,
|
||||
service('emailService')
|
||||
);
|
||||
$this->parentEnrollmentService = new ParentEnrollmentService(
|
||||
$this->db,
|
||||
$this->userModel,
|
||||
@@ -180,10 +187,9 @@ class ParentController extends BaseController
|
||||
|
||||
public function index()
|
||||
{
|
||||
// Retrieve all parents from the database where role is parent
|
||||
$parents = $this->userModel->where('role', 'parent')->findAll();
|
||||
// Pass the parents to the view
|
||||
return view('administrator/parent', ['parents' => $parents]);
|
||||
return view('administrator/parent', [
|
||||
'parents' => $this->parentAccountService->administratorParentList(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
@@ -194,44 +200,29 @@ class ParentController extends BaseController
|
||||
|
||||
public function store()
|
||||
{
|
||||
// Handle the form submission to create a new parent
|
||||
$data = [
|
||||
'firstname' => $this->request->getPost('firstname'),
|
||||
'lastname' => $this->request->getPost('lastname'),
|
||||
'email' => strtolower($this->request->getPost('email')),
|
||||
'password' => password_hash($this->request->getPost('password'), PASSWORD_DEFAULT),
|
||||
'role' => 'parent',
|
||||
];
|
||||
$this->userModel->insert($data);
|
||||
$this->parentAccountService->createAdministratorParent((array) $this->request->getPost());
|
||||
|
||||
return redirect()->to('/administrator/parent');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
// Retrieve the parent details to edit
|
||||
$parent = $this->userModel->find($id);
|
||||
return view('administrator/edit_parent', ['parent' => $parent]);
|
||||
return view('administrator/edit_parent', [
|
||||
'parent' => $this->parentAccountService->parentById((int) $id),
|
||||
]);
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
// Handle the form submission to update an existing parent
|
||||
$data = [
|
||||
'firstname' => $this->request->getPost('firstname'),
|
||||
'lastname' => $this->request->getPost('lastname'),
|
||||
'email' => strtolower($this->request->getPost('email')),
|
||||
];
|
||||
if ($this->request->getPost('password')) {
|
||||
$data['password'] = password_hash($this->request->getPost('password'), PASSWORD_DEFAULT);
|
||||
}
|
||||
$this->userModel->update($id, $data);
|
||||
$this->parentAccountService->updateAdministratorParent((int) $id, (array) $this->request->getPost());
|
||||
|
||||
return redirect()->to('/administrator/parent');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
// Delete the parent
|
||||
$this->userModel->delete($id);
|
||||
$this->parentAccountService->deleteParent((int) $id);
|
||||
|
||||
return redirect()->to('/administrator/parent');
|
||||
}
|
||||
|
||||
@@ -2192,7 +2183,7 @@ class ParentController extends BaseController
|
||||
}
|
||||
|
||||
if ($registeredStudentIds !== []) {
|
||||
$this->notifyAdminsAboutRegisteredStudents($registeredStudentIds, (int) $parentId);
|
||||
$this->parentRegistrationNotificationService->sendAdminNewStudentEmails($registeredStudentIds, (int) $parentId);
|
||||
}
|
||||
|
||||
if ($studentAdded) {
|
||||
@@ -2208,55 +2199,6 @@ class ParentController extends BaseController
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send admin registration emails after commit so only saved students are reported.
|
||||
*
|
||||
* @param list<int> $studentIds
|
||||
*/
|
||||
private function notifyAdminsAboutRegisteredStudents(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;
|
||||
}
|
||||
|
||||
$payload = $student;
|
||||
$payload['parents'] = [
|
||||
'user_id' => $parentId,
|
||||
'firstname' => (string) ($parent['firstname'] ?? ''),
|
||||
'lastname' => (string) ($parent['lastname'] ?? ''),
|
||||
'email' => (string) ($parent['email'] ?? ''),
|
||||
];
|
||||
|
||||
$studentFullName = trim((string) ($student['firstname'] ?? '') . ' ' . (string) ($student['lastname'] ?? '')) ?: 'Student ID ' . $studentId;
|
||||
$adminMessage = view('emails/admin_student_registered', ['student' => $payload], ['saveData' => true]);
|
||||
|
||||
try {
|
||||
$sent = service('emailService')->send(
|
||||
'registration@alrahmaisgl.org',
|
||||
'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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Function to check if the parent has registered kids and redirect accordingly
|
||||
public function registerKidCheck()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user