예제 #1
0
 function actionAddWorker()
 {
     $model = new Worker();
     $user = new User();
     $u_transaction = $user->dbConnection->beginTransaction();
     $this->performAjaxValidation($user);
     if (isset($_POST['Worker'])) {
         if (isset($_POST['User'])) {
             $user->login = $_POST['User']['login'];
             $user->password = $_POST['User']['password'];
             $user->role = 'worker';
             if ($user->save()) {
                 $model->attributes = $_POST['Worker'];
                 $model->user_id = $user->id;
                 $timestamp = CDateTimeParser::parse($model->birthdate, 'dd-MM-yyyy');
                 $model->birthdate = date('Y-m-d', $timestamp);
                 if ($model->save()) {
                     $u_transaction->commit();
                     $this->redirect(array('view', 'id' => $model->user_id));
                 } else {
                     $u_transaction->rollback();
                     //откатываем данные по юзеру, в случае если данные по работнику не сохранились
                     throw new CHttpException(901, 'Ошибка сохранения данных работника.');
                 }
             } else {
                 throw new CHttpException(902, "Ошибка сохранения данных авторизации");
             }
         } else {
             throw new CHttpException(903, 'Ошибка передачи данных авторизации.');
         }
     } else {
         $this->render('add_worker', array('model' => $model, 'user' => $user));
     }
 }
예제 #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Worker();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Worker'])) {
         $model->attributes = $_POST['Worker'];
         if ($model->save()) {
             $this->redirect(array('admin'));
         }
     }
     $this->render('create', array('model' => $model));
 }