public function execute($user, $item, $params) { if (Yii::$app->user->isGuest) { return false; } $role = Yii::$app->user->identity->role; if ($role == User::ROLE_ADMIN) { return true; } elseif (!isset($params['id_program'])) { return false; } elseif ($role == User::ROLE_STUDENT) { $model = StudentEducation::find()->where(['id_student' => Yii::$app->user->identity->id_student, 'year' => YearHelper::getYear()])->one(); if (!$model) { return false; } else { return $params['id_program'] == $model->id_program; } } elseif ($role == User::ROLE_LOCAL_ADMIN || $role == User::ROLE_INSPECTOR) { $model = Program::findOne($params['id_program']); if (!$model) { return false; } else { return Yii::$app->user->identity->id_faculty == $model->id_faculty; } } else { return false; } }
protected function getIdFaculty($id, $parent = false) { if ($parent) { $model = StudentEducation::find()->where(['id_student' => $id, 'year' => YearHelper::getYear()])->one(); return $model->idProgram->id_faculty; } else { $model = StudentEducation::findOne($id); return $model->idProgram->id_faculty; } }
public function checkFaculty($rule, $action) { /* @var $model StudentEducation */ $id_student = Yii::$app->request->get('id'); $model = StudentEducation::find()->where(['id_student' => $id_student, 'year' => YearHelper::getYear()])->one(); if ($model) { return Yii::$app->user->can('viewFaculty', ['id_faculty' => $model->idProgram->id_faculty]); } else { return false; } }
public function actionIndex($id) { // $id - in Student /* @var $student StudentEducation */ $student = StudentEducation::find()->where(['id_student' => $id, 'year' => YearHelper::getYear()])->one(); if (!$student) { $this->redirect($this->goHome()); } $provider = new ActiveDataProvider(['query' => ResultHelper::StudentResults($student->id), 'pagination' => false]); return $this->render('index', ['provider' => $provider, 'student' => $student]); }
protected function getIdFaculty($id, $parent = false) { $year = YearHelper::getYear(); if ($parent) { $id_student = $id; } else { $model = User::findOne($id); $id_student = $model->id_student; } $student = StudentEducation::find()->where(['year' => $year, 'id_student' => $id_student])->one(); return $student->idProgram->id_faculty; }
public function actionIndex($id) { // $id - Student /* @var $student StudentEducation */ $student = StudentEducation::find()->where(['id_student' => $id, 'year' => YearHelper::getYear()])->one(); if (!$student) { $this->redirect($this->goHome()); } $provider = new ActiveDataProvider(['query' => ResultHelper::StudentResults($student->id), 'pagination' => ['pageSize' => 10, 'pageSizeParam' => false]]); Yii::$app->session->set('studentResultPage', Yii::$app->request->get('page')); return $this->render('student', ['provider' => $provider, 'student' => $student]); }
private function checkAccess($id_student) { if (Yii::$app->user->can('updateStudent', ['id_student' => $id_student])) { return true; } else { /* @var $student StudentEducation */ $student = StudentEducation::find()->where(['id_student' => $id_student, 'year' => YearHelper::getYear()])->one(); if (Yii::$app->user->can('updateFaculty', ['id_faculty' => $student->idProgram->id_faculty])) { return true; } } return false; }
private function allowed() { if (Yii::$app->user->can('viewFaculty', ['id_faculty' => $this->model->id_faculty])) { return true; } elseif (Yii::$app->user->can('updateStudent')) { $student = StudentEducation::find()->where(['id_student' => Yii::$app->user->identity->id_student, 'year' => YearHelper::getYear()])->one(); if (!$student) { return false; } else { return $student->id_program == $this->model->id; } } else { return false; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($id_program, $id_student, $params) { $query = StudentEducation::find()->where(['id_program' => $id_program, 'year' => YearHelper::getYear()]); $query->andFilterWhere(['id_student' => $id_student]); $provider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10, 'pageSizeParam' => false]]); $provider->setSort(['attributes' => ['studentName' => ['asc' => ['student.name' => SORT_ASC], 'desc' => ['student.name' => SORT_DESC], 'label' => 'StudentName'], 'course', 'group'], 'defaultOrder' => ['course' => SORT_DESC, 'studentName' => SORT_ASC]]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['idStudent']); return $provider; } $query->andFilterWhere(['course' => $this->course]); $query->andFilterWhere(['like', 'group', $this->group]); $query->joinWith(['idStudent' => function ($q) { /* @var $q \yii\db\ActiveQuery */ $q->andWhere('student.name LIKE "%' . $this->studentName . '%" '); }]); return $provider; }
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; }
public function checkProgram($rule, $action) { $id_program = Yii::$app->request->get('id_program'); $id_faculty = Program::findOne($id_program)->id_faculty; if (Yii::$app->user->can('viewFaculty', ['id_faculty' => $id_faculty])) { return true; } else { $id_student = Yii::$app->user->identity->id_student; if (!$id_student) { return false; } else { $student = StudentEducation::find()->where(['id_student' => $id_student, 'year' => YearHelper::getYear()])->one(); if (!$student) { return false; } else { return $student->id_program == $id_program; } } } }
private function checkPortfolioAccess($model) { $id_student = $model->id_student; if (!Yii::$app->user->can('updateStudent', ['id_student' => $id_student])) { $student = StudentEducation::find()->where(['id_student' => $id_student, 'year' => YearHelper::getYear()])->one(); if ($student) { return Yii::$app->user->can('viewFaculty', ['id_faculty' => $student->idProgram->id_faculty]); } else { return false; } } else { return true; } }
<?php /* @var $this yii\web\View */ /* @var $id integer */ /* @var $beginNodeId integer */ use kartik\tree\TreeView; use common\models\StudentPortfolio; use kartik\tree\Module; use common\models\StudentEducation; use common\helpers\YearHelper; use common\models\User; $this->registerCss("#idPortfolio-detail h3 { display: none }"); /* @var $student StudentEducation */ $student = StudentEducation::find()->where(['id_student' => $id, 'year' => YearHelper::getYear()])->one(); $this->title = 'Портфолио'; if (Yii::$app->user->identity->role != User::ROLE_STUDENT) { $this->params['breadcrumbs'][] = ['label' => 'Образовательные программы', 'url' => ['/program', 'idParent' => $student->idProgram->id_faculty]]; $this->params['breadcrumbs'][] = ['label' => 'Студенты', 'url' => ['main/index', 'idParent' => $student->id_program, 'page' => Yii::$app->session->get('studentPage')]]; } $this->params['breadcrumbs'][] = $this->title; ?> <h2>Портфолио</h2> <h3> Студент: <?php echo $student->studentName; ?> Курс: <?php echo $student->course; ?> Программа: <?php
/** * Задание номера группы для выбранного списка студентов */ public function actionGroupSet($idParent) { $id_students = Yii::$app->request->post('listChosen'); $group = Yii::$app->request->post('group'); $students = StudentEducation::find()->where(['id' => $id_students])->all(); foreach ($students as $student) { /* @var $student StudentEducation */ $student->group = $group; $student->save(false); } Yii::$app->session->setFlash('success', "Задана группа списку студентов"); $this->redirect(['index', 'idParent' => $idParent]); }