/** * Lists all Grades models. * @return mixed */ public function actionIndex() { $username = Yii::$app->user->identity->username; $users = User::find()->all(); $scholars = Scholar::find()->all(); foreach ($users as $user) { foreach ($scholars as $scholar) { if ($user->username == $username && $user->id == $scholar->scholar_user_id) { $searchModel = new GradeSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); if (Yii::$app->request->post('hasEditable')) { $gradeId = Yii::$app->request->post('editableKey'); $grade = Grade::findOne($gradeId); $out = Json::encode(['output' => '', 'message' => '']); $post = []; $posted = current($_POST['Grade']); $post['Grade'] = $posted; if ($grade->load($post)) { if ($grade->grade_approval_status == 'Approved') { $grade->grade_approved_by = Yii::$app->user->identity->username; } else { $grade->grade_approved_by = null; } $subject = Subject::findOne($grade->subject_subject_id); // $subjectTakenStatus = ArrayHelper::map(Subject::find() // ->where(['subject_id'=>$grade->subject_subject_id]) // ->all(),'subject_id','subject_taken_status'); $subject->subject_taken_status = $grade->takenStatus; $subject->save(); $grade->save(); } echo $out; return; } return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); } } } }
/** * Finds the Grade model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $grade_id * @param integer $subject_subject_id * @param integer $subject_scholar_scholar_id * @param integer $subject_scholar_school_school_id * @return Grade the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Grade::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }