Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new BoxomaticUser();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['BoxomaticUser'])) {
         $model->scenario = 'changePassword';
         $model->attributes = $_POST['BoxomaticUser'];
         if (isset($_POST['BoxomaticUser']['password'])) {
             $model->password = $_POST['BoxomaticUser']['password'];
         }
         if ($model->save()) {
             if (isset($_POST['role'])) {
                 $model->setRole($_POST['role']);
             }
             if (isset($_POST['role']) && $_POST['role'] == 'customer') {
                 if (empty($model->user_id)) {
                     $Customer = new Customer();
                 } else {
                     $Customer = Customer::model()->findByPk($model->user_id);
                 }
                 $Customer->attributes = $_POST['Customer'];
                 $Customer->save();
                 $CustLoc = new UserLocation();
                 $CustLoc->user_id = $Customer->user_id;
                 $CustLoc->location_id = $Customer->location_id;
                 $CustLoc->address = $model->user_address;
                 $CustLoc->address2 = $model->user_address2;
                 $CustLoc->suburb = $model->user_suburb;
                 $CustLoc->state = $model->user_state;
                 $CustLoc->postcode = $model->user_postcode;
                 $CustLoc->phone = !empty($model->user_phone) ? $model->user_phone : $model->user_mobile;
                 $CustLoc->save();
                 $model->user_id = $Customer->user_id;
                 $model->update(array('user_id'));
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $custLocDataProvider = new CActiveDataProvider('UserLocation');
     $this->render('create', array('model' => $model, 'custLocDataProvider' => $custLocDataProvider));
 }