Пример #1
0
 public function actionBeginGraduate()
 {
     if (Yii::$app->request->isAjax) {
         $workModel = new Work();
         $workModel->scenario = Work::SCENARIO_GRADUATE;
         if (Yii::$app->request->post()) {
             $nowDate = date("U");
             $workHistory = new \common\models\WorkHistory();
             if (isset(Yii::$app->request->post()['newWorkCheckbox']) && Yii::$app->request->post()['newWorkCheckbox'] == true) {
                 $teacher = Yii::$app->request->post()['newWorkTeacher'];
                 $stringName = Yii::$app->request->post()['newWorkName'];
                 $work_list_id = null;
             } else {
                 $workFromList = \common\models\WorkList::findOne(Yii::$app->request->post()['workList']);
                 $teacher = $workFromList->teacher_id;
                 $stringName = $workFromList->name;
                 $work_list_id = $workFromList->id;
                 $workModel->reserved_id = $workFromList->id;
             }
             $workModel->work_type_id = 1;
             $workModel->teacher_id = $teacher;
             $workModel->student_id = Yii::$app->user->identity->student->id;
             $workModel->date = $nowDate;
             if ($workModel->validate()) {
                 $workModel->save();
                 $workHistory->work_id = $workModel->getPrimaryKey();
                 $workHistory->name = $stringName;
                 $workHistory->creation_date = $nowDate;
                 if ($workHistory->save()) {
                     $workModel->name = $workHistory->getPrimaryKey();
                     $iterator = $workModel->name;
                     $workModel->save();
                     if (isset($workFromList)) {
                         $workFromList->save();
                     }
                     return $this->redirect(['graduate']);
                 }
             }
         }
         $workList = \common\models\WorkList::find()->all();
         $teachers = \common\models\Teacher::find()->all();
         return $this->renderAjax('begin_graduate', ['workModel' => $workModel, 'workList' => $workList, 'teachers' => $teachers]);
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #2
0
 public function beginGraduate($request)
 {
     $this->scenario = 'graduate';
     $nowDate = date("U");
     $workHistory = new \common\models\WorkHistory();
     if (isset(Yii::$app->request->post()['newWorkCheckbox']) && Yii::$app->request->post()['newWorkCheckbox'] == true) {
         $teacher = Yii::$app->request->post()['newWorkTeacher'];
         $stringName = Yii::$app->request->post()['newWorkName'];
         $work_list_id = null;
     } else {
         $workFromList = \common\models\WorkList::findOne(Yii::$app->request->post()['workList']);
         $teacher = $workFromList->teacher_id;
         $stringName = $workFromList->name;
         $work_list_id = $workFromList->id;
     }
     $workModel->work_type_id = 1;
     $workModel->teacher_id = $teacher;
     $workModel->student_id = Yii::$app->user->identity->student->id;
     $workModel->date = $nowDate;
     $workModel->reserved_id = $workFromList->id;
     if ($workModel->save()) {
         $workHistory->work_id = $workModel->getPrimaryKey();
         $workHistory->name = $stringName;
         $workHistory->creation_date = $nowDate;
         if ($workHistory->save()) {
             $workModel->name = $workHistory->getPrimaryKey();
             $iterator = $workModel->name;
             $workModel->save();
             if (isset($workFromList)) {
                 $workFromList->save();
             }
             return $this->renderAjax('complete_begin_graduate', ['iterator' => $iterator]);
         }
     }
 }