/** * Finds the StudentEvidence model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $taskId * @param integer $projectId * @param integer $evidenceId * @param integer $studentId * @return StudentEvidence the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($taskId, $projectId, $evidenceId, $studentId) { if (($model = StudentEvidence::findOne(['taskId' => $taskId, 'projectId' => $projectId, 'evidenceId' => $evidenceId, 'studentId' => $studentId])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Saves feedback given by the project manager * Sends a notification for the student * @param $id * @param $evidenceId * @return \yii\web\Response * @throws NotFoundHttpException * @throws \Exception * @throws \yii\base\InvalidConfigException * @throws \yii\db\Exception */ public function actionGiveFeedback($id, $evidenceId) { $task = $this->findModel($id); $comment = $_POST['feedback']; $accepted = $_POST['aceptado']; $studentEvidence = StudentEvidence::findOne(['task_id' => $task->id]); $studentId = $studentEvidence->student_id; if ($accepted == 1) { Yii::$app->db->createCommand('UPDATE student_evidence SET comment="' . $comment . '" WHERE task_id=' . $task->id . ' AND evidence_id=' . $evidenceId)->execute(); $task->status = Task::ACCEPTED; Yii::$app->db->createCommand('UPDATE student_evidence SET status="' . Task::ACCEPTED . '" WHERE task_id=' . $task->id . ' AND evidence_id=' . $evidenceId)->execute(); $task->update(); $evidence = Evidence::find()->where("id=" . $evidenceId)->one(); $evidence->accepted_date = Yii::$app->formatter->asDate('now', 'yyyy-MM-dd'); $evidence->update(); $this->setNotification($studentId, $task->id, $studentEvidence->project_id, Notification::ACCEPTED_TASK); Yii::$app->getSession()->setFlash('success', 'Sus cambios se han guardado exitosamente'); } else { Yii::$app->db->createCommand('UPDATE student_evidence SET comment="' . $comment . '" WHERE task_id=' . $task->id . ' AND evidence_id=' . $evidenceId)->execute(); $this->setNotification($studentId, $task->id, $studentEvidence->project_id, Notification::REJECTED_TASK); Yii::$app->getSession()->setFlash('success', 'Sus cambios se han guardado exitosamente'); } return $this->redirect(['student-evidence/index']); }
/** * @param $evidence_id * @return null|static * @throws NotFoundHttpException */ protected function findModelByEvidence($evidence_id) { if (($model = StudentEvidence::findOne(['evidence_id' => $evidence_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }