/** * Creates a new Orders model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $industry = Yii::$app->request->get('industry'); $process = Yii::$app->request->get('process'); if (Yii::$app->session['cart'] != null && ($industry != null || $process != null)) { foreach (Yii::$app->session['cart']['industry'] as $key => $ind) { if ($key == $industry) { $cart[$key] = $ind; } } $service = \common\models\CsServices::findOne($cart[$industry]['data'][1]['service']); $objects = $this->getObjectModels($cart[$industry]['data'][1]['object_models']); $user = !Yii::$app->user->isGuest ? \common\models\User::findOne(Yii::$app->user->id) : null; // orderer $model = new Orders(); $model->service = $service; // skill model $model_skill = $this->loadServiceSkills($service); $location = new Locations(); $location->control = $service->location; $location->userControl = Yii::$app->user->isGuest ? 0 : 1; $location_end = new Locations(); $new_user = $user == null ? Yii::createObject(RegistrationProviderForm::className()) : null; // register provider $returning_user = $user == null ? Yii::createObject(LoginForm::className()) : null; // login existing user if ($model->load(Yii::$app->request->post())) { if (Yii::$app->user->isGuest) { // register $ login user if ($new_user->load(Yii::$app->request->post())) { if ($user = $new_user->signup()) { if (!Yii::$app->getUser()->login($user)) { return $this->goBack(); } } } // login user if ($returning_user->load(Yii::$app->request->post())) { if (!$returning_user->login()) { return $this->goBack(); } } } // continue $activity = Activities::loadActivity(Yii::$app->user->id); if ($activity->save()) { // new activity saved $model->activity_id = $activity->id; $this->saveOrderLocation($model, $location, $service); $this->saveOrderEndLocation($model, $location_end, $service); if ($model->save()) { $this->saveOrderSkills($model, $cart, $service); $this->saveOrderServices($model, $activity, $cart, $service); $this->eraseSessionData($industry); // izbaci snimljene usluge iz korpe return $this->redirect('/order/' . $model->id); } } else { return $this->redirect('/services'); } return $this->redirect('/services'); } else { return $this->render('create', ['service' => $service, 'model' => $model, 'model_skills' => $model_skill, 'location' => $location, 'location_end' => $location_end, 'objects' => $objects, 'new_user' => $new_user, 'returning_user' => $returning_user]); } } else { return $this->redirect('/services'); } }
/** * Creates a new Presentations model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $this->layout = '/user_presentation'; if ($ps = Yii::$app->request->get('ProviderServices')) { if ($service = $this->findService($ps['service_id'])) { // service //print_r($service); die(); $object_model = []; if (!empty($ps['object_model'])) { foreach ($ps['object_model'] as $pso) { $object_model[] = $this->findObjectModel($pso); } } $user = !Yii::$app->user->isGuest ? \common\models\User::findOne(Yii::$app->user->id) : null; // presenter $model = new PresentationData(); // new presentation $model->service = $service; $model->object_models = $object_model; $model->location_control = $service->location; $model->location_userControl = Yii::$app->user->isGuest ? 0 : 1; $model_action_properties = $model->loadPresentationActionProperties($service); // array of new presentationMethods $model_object_properties = $model->loadPresentationObjectProperties($service, $object_model); // array of new presentationSpecs $locationHQ = $model->hasProviderLocation() ? $model->hasProviderLocation() : new Locations(); $locationPresentation = new LocationPresentation(); $locationPresentationTo = new LocationPresentationTo(); $model_timetable = new PresentationTimetables(); $provider_openingHours = ($user and $provider = $user->provider and $provider->openingHours) ? $provider->openingHours : new ProviderOpeningHours(); $model_notifications = new PresentationNotifications(); $model_terms = new PresentationTerms(); $model_termexpenses = new PresentationTermExpenses(); $model_termmilestones = new PresentationTermMilestones(); $model_termclauses = new PresentationTermClauses(); $new_provider = $user == null ? Yii::createObject(RegistrationProviderForm::className()) : null; // register provider if ($new_provider) { $new_provider->scenario = 'presentation'; } $returning_user = $user == null ? Yii::createObject(LoginForm::className()) : null; // login existing user if ($returning_user) { $returning_user->scenario = 'presentation'; } if ($user == null) { $this->performAjaxValidation($new_provider); $this->performAjaxValidation($returning_user); } if ($model->load(Yii::$app->request->post())) { $newUser = $user == null ? true : false; // check if new user if ($user = $user == null ? $this->saveUser($new_provider, $returning_user) : $user) { // load user(presenter) if ($newProvider = $user->is_provider == 0 ? true : false) { if ($proserv = $this->saveProvider($user, $service)) { if ($this->savePresentation($model, $user, $service, $object_model, $locationHQ, $locationPresentation, $locationPresentationTo, $proserv, $newUser, $newProvider, $model_object_properties, $model_action_properties, $model_terms, $model_timetable, $model_notifications, $provider_openingHours, $model_termexpenses, $model_termmilestones, $model_termclauses)) { return $this->redirect(['/presentation/' . $model->id]); } } } if ($proserv = $ps['id'] == null ? $this->saveProviderService($user, $service, $newProvider) : $this->findProviderService($ps['id'])) { if ($this->savePresentation($model, $user, $service, $object_model, $locationHQ, $locationPresentation, $locationPresentationTo, $proserv, $newUser, $newProvider, $model_object_properties, $model_action_properties, $model_terms, $model_timetable, $model_notifications, $provider_openingHours, $model_termexpenses, $model_termmilestones, $model_termclauses)) { return $newUser ? $this->redirect(['/blank']) : $this->redirect(['/presentation/' . $model->id]); } } } } else { return $this->render('create', ['service' => $service, 'model' => $model, 'model_action_properties' => $model_action_properties, 'model_object_properties' => $model_object_properties, 'object_model' => $object_model, 'new_provider' => $new_provider, 'returning_user' => $returning_user, 'locationHQ' => $locationHQ, 'locationPresentation' => $locationPresentation, 'locationPresentationTo' => $locationPresentationTo, 'user' => $user, 'model_timetable' => $model_timetable, 'provider_openingHours' => $provider_openingHours, 'model_notifications' => $model_notifications, 'model_terms' => $model_terms, 'model_termexpenses' => $model_termexpenses, 'model_termmilestones' => $model_termmilestones, 'model_termclauses' => $model_termclauses]); } } else { return $this->goBack(); } } else { return $this->goBack(); } }
<?php use yii\helpers\Html; use yii\helpers\Url; use kartik\widgets\ActiveForm; use kartik\widgets\Select2; use yii\helpers\ArrayHelper; use dektrium\user\models\RegistrationProviderForm; use common\models\Locations; $model = Yii::createObject(RegistrationProviderForm::className()); $location = new Locations(); ?> <div class="container-fluid"> <div class="row"> <div class="col-md-5"> <h4><i class="fa fa-sign-in"></i> Registracija provajdera</h4> <div class="margin-top-20" onclick="initialize_reg_pro_loc();"> <?php $form = ActiveForm::begin(['id' => 'signupprovider-form-vertical', 'type' => ActiveForm::TYPE_VERTICAL, 'action' => Url::to('/user/registration/register-provider')]); ?> <?php echo $form->field($model, 'username', ['enableAjaxValidation' => true, 'feedbackIcon' => ['default' => 'user', 'success' => 'ok', 'error' => 'exclamation-sign', 'defaultOptions' => ['class' => 'text-primary']]])->input('text'); ?> <?php echo $form->field($model, 'password', ['feedbackIcon' => ['default' => 'lock', 'success' => 'ok', 'error' => 'exclamation-sign', 'defaultOptions' => ['class' => 'text-primary']]])->passwordInput(); ?> <?php echo $form->field($model, 'password_repeat', ['feedbackIcon' => ['default' => 'lock', 'success' => 'ok', 'error' => 'exclamation-sign', 'defaultOptions' => ['class' => 'text-primary']]])->passwordInput(); ?> <?php echo $form->field($model, 'email', ['enableAjaxValidation' => true, 'feedbackIcon' => ['default' => 'envelope', 'success' => 'ok', 'error' => 'exclamation-sign', 'defaultOptions' => ['class' => 'text-primary']]])->input('email');