예제 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Tutorial();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Tutorial'])) {
         $model->attributes = $_POST['Tutorial'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 /**
  *
  * @param usersData $data
  * @return type 
  */
 public function createSignUp($data)
 {
     $format = $data->format;
     if ($format == 'doc') {
         $body = $this->renderPartial('auth/doc', array(), true);
         return $this->response->type('json')->goodResponse($body);
     }
     $tutModel = new Tutorial();
     $propModel = new Properties();
     $userModel = new Users();
     $user2PropertyModel = new \User2property();
     $transaction = $propModel->dbConnection->beginTransaction();
     $propertie = $propModel->createNewProperie($data->propertie, $data->PP_TRIAL);
     $tutModel->save();
     $tutorial = $tutModel->id;
     if ($propertie !== false || $tutorial !== false) {
         $data->property_id = $propertie;
         $data->tutorial_id = $tutorial;
         $user = $userModel->createNewUser((array) $data);
         if ($user !== false) {
             $color = 'type1';
             $bName = $data->firstname . ' ' . $data->lastname;
             $user2PropertyModel->unsetAttributes();
             $user2PropertyModel->setAttributes(array('userId' => $user, 'propertyId' => $propertie, 'access' => self::OWNER, 'status' => self::STATUS_ACTIVE, 'color' => 'type1', 'bookingName' => $bName));
             if ($user2PropertyModel->save()) {
                 $transaction->commit();
                 $result = true;
             } else {
                 $transaction->rollback();
                 $result = false;
             }
         } else {
             $transaction->rollback();
             $result = false;
         }
     } else {
         $transaction->rollback();
         $result = false;
     }
     $view = !$result ? 'signup/error' : 'signup/done';
     $body = $this->renderPartial($view, array('format' => $format), true);
     return $this->response->type('json')->goodResponse($body);
 }