protected function addProperty($data) { $userId = Yii::app()->user->getState('id'); $propertyModel = new Properties(); $user2PropertyModel = new User2property(); $userModel = new \User(); $propertyModel->unsetAttributes(); $data['edt'] = new CDbExpression('NOW()'); $propertyModel->setAttributes($data); $result = $propertyModel->save(); if (!$result) { return false; } $userName = Yii::app()->user->getState('firstname') . ' ' . Yii::app()->user->getState('lastname'); $user2PropertyModel->unsetAttributes(); $user2PropertyModel->setAttributes(array('userId' => $userId, 'propertyId' => $propertyModel->getAttribute('id'), 'access' => UserAccessTable::OWNER, 'status' => UserAccessTable::STATUS_ACTIVE, 'color' => 'type1', 'bookingName' => $userName)); $result = $user2PropertyModel->save(); if (!$result) { return false; } $userModel->unsetAttributes(); $oldId = $userModel->findByPk($userId); $oldId = $oldId->attributes['property_id']; $result = $userModel->updateByPk($userId, array('property_id' => $propertyModel->getAttribute('id'))); if (!$result) { return false; } $userControl = new \userControl(); $userControl->update(); $outputArray = array('oldId' => $oldId, 'newId' => $propertyModel->getAttribute('id')); return $outputArray; }
/** * * @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); }