get('user_id'); if ($parentId <= 0) { return redirect()->to('/login'); } $schoolYear = (string) ((new ConfigurationModel())->getConfig('school_year') ?? ''); $model = new FinancialAidRequestModel(); $requests = $model ->where('parent_id', $parentId) ->where('school_year', $schoolYear) ->orderBy('id', 'DESC') ->findAll(); $students = (new StudentModel()) ->where('parent_id', $parentId) ->orderBy('lastname', 'ASC') ->orderBy('firstname', 'ASC') ->findAll(); return view('parent/financial_aid', [ 'schoolYear' => $schoolYear, 'students' => $students, 'requests' => $requests, 'openRequest' => $model->openRequestForParent($parentId, $schoolYear), ]); } public function submit() { $parentId = (int) session()->get('user_id'); if ($parentId <= 0) { return redirect()->to('/login'); } $schoolYear = (string) ((new ConfigurationModel())->getConfig('school_year') ?? ''); $model = new FinancialAidRequestModel(); if ($model->openRequestForParent($parentId, $schoolYear) !== null) { return redirect()->back()->with('error', 'You already have an open financial aid request for this school year.'); } $studentIds = array_values(array_unique(array_filter(array_map('intval', (array) $this->request->getPost('student_ids'))))); $linkedIds = array_map('intval', array_column( (new StudentModel())->select('id')->where('parent_id', $parentId)->findAll(), 'id' )); $studentIds = array_values(array_intersect($studentIds, $linkedIds)); if ($studentIds === []) { return redirect()->back()->withInput()->with('error', 'Select at least one of your students.'); } $needStatement = trim((string) $this->request->getPost('need_statement')); if ($needStatement === '') { return redirect()->back()->withInput()->with('error', 'Please describe why you are requesting financial aid.'); } $householdSize = (int) $this->request->getPost('household_size'); $requestedAmount = trim((string) $this->request->getPost('requested_amount')); $model->insert([ 'parent_id' => $parentId, 'school_year' => $schoolYear, 'student_ids_json' => json_encode($studentIds), 'household_size' => $householdSize > 0 ? $householdSize : null, 'need_statement' => $needStatement, 'requested_amount' => $requestedAmount !== '' ? (float) $requestedAmount : null, 'status' => 'submitted', ]); return redirect()->to('/parent/financial-aid')->with('success', 'Your financial aid request was submitted.'); } }