public function CheckFaculty($rule, $action) { /* @var $model StudentEducation */ switch ($action->id) { case 'index': $model = StudentEducation::find()->where(['id_student' => Yii::$app->request->get('id'), 'year' => YearHelper::getYear()])->one(); $id_faculty = $model ? $model->idProgram->id_faculty : null; break; case 'update': $model = StudentEducation::findOne(Yii::$app->request->get('id_student')); $id_faculty = $model->idProgram->id_faculty; break; case 'delete': $id = Yii::$app->request->get('id'); if ($id) { /* @var $result StudentResult */ $result = StudentResult::findOne($id); $model = StudentEducation::findOne($result->id_student_education); $id_faculty = $model->idProgram->id_faculty; } else { $id_faculty = null; } break; default: $id_faculty = null; } return Yii::$app->user->can('updateFaculty', ['id_faculty' => $id_faculty]); }
public function actionResult($id) { $result = StudentResult::findOne($id); if (Yii::$app->user->identity->role == User::ROLE_STUDENT) { $allowed = Yii::$app->user->can('updateStudent', ['id_student' => $result->idStudentEducation->idStudent->id]); } else { $allowed = Yii::$app->user->can('viewProgramFiles', ['id_program' => $result->idDisciplineSemester->idDiscipline->id_program]); } return $this->renderFiles('common\\models\\StudentResult', $id, $allowed); }
protected function getIdFaculty($id, $parent = false) { if ($parent) { if ($id == null) { return null; } $model = StudentResult::findOne($id); return $model->idStudentEducation->idProgram->id_faculty; } else { $model = StudentResultFile::find()->where(['id_file' => $id])->one(); return $this->getIdFaculty($model->id_student_result, true); } }
public static function newExamList($id_student, $id_semester) { $currentStudent = StudentEducation::findOne($id_student); $studentResults = StudentResult::find()->innerJoinWith(['idStudentEducation' => function ($query) use($currentStudent) { $query->where(['year' => $currentStudent->year, 'group' => $currentStudent->group]); }])->where(['id_discipline_semester' => $id_semester])->select('id_student'); $students = StudentEducation::find()->joinWith(['idStudent' => function ($query) { $query->orderBy('name'); }])->where(['year' => $currentStudent->year, 'id_program' => $currentStudent->id_program, 'course' => $currentStudent->course, 'group' => $currentStudent->group])->andWhere(['not in', 'id_student', $studentResults])->all(); $results = []; foreach ($students as $student) { $result = new StudentResult(); $result->id_student_education = $student->id; $result->id_discipline_semester = $id_semester; $results[] = $result; } return $results; }
/** * @return \yii\db\ActiveQuery */ public function getStudentResults() { return $this->hasMany(StudentResult::className(), ['id_discipline_semester' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getIdStudentResult() { return $this->hasOne(StudentResult::className(), ['id' => 'id_student_result']); }
<?php use common\models\Program; use common\models\StudentEducation; use common\models\StudentResult; /* @var $this yii\web\View */ /* @var $provider yii\data\ActiveDataProvider */ /* @var $program Program */ /* @var $idParent integer */ /* @var $student StudentEducation */ /* @var $result StudentResult */ $result = StudentResult::findOne($idParent); $student = StudentEducation::findOne($result->id_student_education); $program = Program::findOne($student->id_program); $this->title = 'Файлы'; $this->params['breadcrumbs'][] = ['label' => 'Образовательные программы', 'url' => ['/program', 'idParent' => $program->id_faculty]]; $this->params['breadcrumbs'][] = ['label' => 'Студенты', 'url' => ['/student', 'idParent' => $student->id_program, 'page' => Yii::$app->session->get('studentPage')]]; $this->params['breadcrumbs'][] = ['label' => 'Результаты', 'url' => ['/student/result/index', 'id' => $student->id_student]]; $this->params['breadcrumbs'][] = $this->title; ?> <h2>Файлы</h2> <h3> Студент: <?php echo $student->studentName; ?> Дисциплина: <?php echo $result->idDisciplineSemester->idDiscipline->fullName; ?> </h3> <?php
public function actionViewDiscipline($id) { // $id - StudentResult $model = StudentResult::findOne($id); return $this->render('viewDiscipline', ['model' => $model]); }
/** * @return \yii\db\ActiveQuery */ public function getStudentResults() { return $this->hasMany(StudentResult::className(), ['id_student_education' => 'id']); }