Example #1
0
 public function actionThd()
 {
     $out = [];
     if (isset($_POST['depdrop_parents'])) {
         $parents = $_POST['depdrop_parents'];
         if ($parents != null) {
             $ghd_id = $parents[0];
             $model = GroupHasDiscipline::findOne($ghd_id);
             foreach (\yii\helpers\ArrayHelper::map($model->teacherHasDiscipline, 'id', 'teacher.user.fullname') as $key => $element) {
                 $out[] = ['id' => $key, 'name' => $element];
             }
             // the getSubCatList function will query the database based on the
             // cat_id and return an array like below:
             // [
             //    ['id'=>'<sub-cat-id-1>', 'name'=>'<sub-cat-name1>'],
             //    ['id'=>'<sub-cat_id_2>', 'name'=>'<sub-cat-name2>']
             // ]
             echo Json::encode(['output' => $out, 'selected' => '']);
             return;
         }
     }
     echo Json::encode(['output' => '', 'selected' => '']);
 }
Example #2
0
 public function actionTermCreateGroup($group = null, $discipline = null)
 {
     if ($group && $discipline && Yii::$app->user->can('teacher')) {
         if (Yii::$app->user->identity->teacher->isTeacherHasDiscipline($discipline)) {
             $groupModel = Group::findOne($group);
             $disciplineModel = \common\models\GroupHasDiscipline::findOne($discipline);
             $errors = false;
             foreach ($groupModel->students as $student) {
                 $model = new Work();
                 $model->scenario = Work::SCENARIO_TERM;
                 $model->ghd_id = $disciplineModel->discipline_id;
                 $model->student_id = $student->id;
                 $model->teacher_id = Yii::$app->user->identity->teacher->id;
                 $model->work_type_id = Work::TYPE_TERM;
                 if ($model->validate()) {
                     $model->save();
                     $model->id = $model->getPrimaryKey();
                 } else {
                     $errors = true;
                 }
             }
             if (!$errors) {
                 return 'Создано';
             } else {
                 return 'Произошла ошибка';
             }
         }
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Finds the GroupHasDiscipline model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return GroupHasDiscipline the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GroupHasDiscipline::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }