public function actionNew($eid) { $eid = (int) $eid; $id = EnrolledForm::findOne($eid); if ($id !== null) { $model = new AssessmentForm(); $student_id = (int) $id->student_id; $grade_level_id = (int) $id->grade_level_id; $student = StudentForm::findOne($id->student_id); $tuition = Tuition::find()->where(['grade_level_id' => $grade_level_id])->orderBy(['id' => SORT_DESC])->all(); $model->enrolled_id = $eid; $tid = (int) $tuition[0]['id']; $model->tuition_id = $tid; $model->has_sibling_discount = (int) $model->has_sibling_discount; $model->has_book_discount = (int) $model->has_book_discount; $model->has_honor_discount = (int) $model->has_honor_discount; if (!empty($tuition)) { $array = $tuition; } else { throw new NotFoundHttpException('Oops, Something went wrong.'); } //$tuition_detail = Tuition::find()->where(['grade_level_id' => $grade_level_id])->orderBy(['id' => SORT_DESC])->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('new', ['model' => $model, 'student' => $student, 'tid' => $tid, 'array' => $array]); } } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getStudentDetails($data) { if (empty($data)) { return ''; } $student = StudentForm::findOne($data); return implode(' ', [$student->first_name, $student->middle_name, $student->last_name . ',', 'ID#' . $student->id]); }
/** * Finds the StudentForm model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return StudentForm the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = StudentForm::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }