/** * @return \yii\db\ActiveQuery */ public function getFieldsTypes() { return $this->hasMany(FieldsTypes::className(), ['id' => 'type_id']); }
public function actionMapping_old_171115() { if (!Yii::$app->user->isGuest) { $user = Yii::$app->getUser()->getIdentity(); //@TODO new logic to find out if there are answers /*$answers = MembersQuestionsAnswers::find(['member_id' => $user->id])->count(); if ($answers > 0) { $user->status = User::STATUS_ACTIVE; if ($user->save()) { return Yii::$app->response->redirect(array('members/index')); } else { Yii::$app->getSession()->setFlash('warning', Yii::t('errors', 'Can not update user status. Please contact system administrator')); } }*/ $settingsModel = GeneralSettings::findOne(['name' => 'mapping_page_id']); $pageModel = CmsPages::findOne(['id' => $settingsModel->value]); $categoryModel = MappingCategories::findOne(['id' => $pageModel->mapping_id]); $attributesModel = MembersAttributes::findAll(['id' => $categoryModel->attributes_id]); $questionsModel = MappingQuestions::find(['category_id' => $categoryModel->id])->with('fieldsTypes')->all(); $questionsAnswers = new MembersQuestionsAnswers($pageModel->category_id); $attributesAnswers = new MembersAttributesAnswers($categoryModel->attributes_id); if (Yii::$app->request->post()) { $mappingQuestionsSaved = false; $mappingAttributesSaved = false; if ($questionsAnswers->load(Yii::$app->request->post()) && $questionsAnswers->validate()) { foreach ($questionsAnswers->attributes as $attribute_id => $attribute) { $attributesArray = explode('_', $attribute_id); if (count($attributesArray) > 1) { list($name, $id) = $attributesArray; if (!($model = MembersQuestionsAnswers::findOne(['question_id' => $id, 'member_id' => Yii::$app->getUser()->id]))) { $model = new MembersQuestionsAnswers(); } $has_option = false; if ($questionsModel = MappingQuestions::findOne($id)) { $type_id = $questionsModel->type_id; $has_option = FieldsTypes::findOne($type_id)->has_options; } if ($has_option) { $model->value = ''; $model->option_id = ''; if ($optionsModel = MappingQuestionsToOptions::findOne($questionsAnswers->{$attribute_id})) { $model->value = $optionsModel->title; $model->option_id = $optionsModel->id; } } else { $model->value = $questionsAnswers->{$attribute_id}; } $model->question_id = $id; $model->member_id = Yii::$app->getUser()->id; $model->save(); } } $mappingQuestionsSaved = true; } if ($attributesAnswers->load(Yii::$app->request->post()) && $attributesAnswers->validate()) { foreach ($attributesAnswers->attributes as $attribute_id => $attribute) { $attributesArray = explode('_', $attribute_id); if (count($attributesArray) > 1) { list($name, $id) = $attributesArray; if (!($model = MembersAttributesAnswers::findOne(['attribute_id' => $id, 'member_id' => Yii::$app->getUser()->id]))) { $model = new MembersAttributesAnswers(); } $has_option = false; if ($questionsModel = MembersAttributes::findOne($id)) { $type_id = $questionsModel->type_id; $has_option = FieldsTypes::findOne($type_id)->has_options; $filedTypeTitle = FieldsTypes::findOne($type_id)->title; } if ($has_option) { $model->value = ''; $model->option_id = ''; if ($optionsModel = MembersAttributesToOptions::findOne($attributesAnswers->{$attribute_id})) { $model->value = $optionsModel->title; $model->option_id = $optionsModel->id; } } else { $model->value = $attributesAnswers->{$attribute_id}; if (isset($filedTypeTitle) && $filedTypeTitle == 'Date Picker') { //@TODO replace datepicker with some database constatnt value; $model->value = strtotime($attributesAnswers->{$attribute_id}); } } $model->attribute_id = $id; $model->member_id = Yii::$app->getUser()->id; $model->save(); } } $mappingAttributesSaved = true; } if ($mappingQuestionsSaved && $mappingAttributesSaved) { $user = Yii::$app->getUser()->getIdentity(); $user->status = User::STATUS_ACTIVE; if ($user->save()) { return Yii::$app->response->redirect(array('members')); } else { Yii::$app->getSession()->setFlash('warning', Yii::t('errors', 'Can not save mapping data. Please contact system administrator')); } } else { $categoryModel = MappingCategories::findOne(['id' => $pageModel->category_id]); $attributesModel = MembersAttributes::find(['id in ' => $categoryModel->attributes_id])->with('fieldsTypes')->all(); $questionsModel = MappingQuestions::find(['category_id' => $categoryModel->id])->with('fieldsTypes')->all(); return $this->render('mapping', ['questionsAnswers' => $questionsAnswers, 'attributesAnswers' => $attributesAnswers, 'pageModel' => $pageModel, 'categoryModel' => $categoryModel, 'questionsModel' => $questionsModel, 'attributesModel' => $attributesModel]); } } else { return $this->render('mapping', ['questionsAnswers' => $questionsAnswers, 'attributesAnswers' => $attributesAnswers, 'pageModel' => $pageModel, 'categoryModel' => $categoryModel, 'questionsModel' => $questionsModel, 'attributesModel' => $attributesModel]); } } else { return Yii::$app->response->redirect(array('site/login')); } }
private function _hasTypeOptions($type_id) { $typeModel = FieldsTypes::findOne($type_id); if ($typeModel->has_options) { return true; } return false; }
public function processQuestions($questionsAnswers) { if ($questionsAnswers->load(Yii::$app->request->post()) && $questionsAnswers->validate()) { $questionsModel = new MappingQuestions(); foreach ($questionsAnswers->attributes as $attribute_id => $attribute) { $attributesArray = explode('_', $attribute_id); //ignore attributes without underscores if (count($attributesArray) < 2) { continue; } list($name, $id) = $attributesArray; if ($id > 0) { list($name, $id) = $attributesArray; if (!($model = MembersQuestionsAnswers::findOne(['question_id' => $id, 'member_id' => Yii::$app->getUser()->id]))) { $model = new MembersQuestionsAnswers(); } $has_option = false; if ($questionsModel = MappingQuestions::findOne($id)) { $type_id = $questionsModel->type_id; $fieldsModel = FieldsTypes::findOne($type_id); $has_option = $fieldsModel->has_options; } $model->{$name} = $questionsAnswers->{$attribute_id}; if ($has_option) { $model->value = ''; $model->option_id = ''; if ($optionsModel = MappingQuestionsToOptions::findOne($questionsAnswers->{$attribute_id})) { $model->value = $optionsModel->title; $model->option_id = $optionsModel->id; } if ($fieldsModel->has_other_field && $questionsModel->has_other && $name == 'value') { $model->option_id = $questionsAnswers->{$attribute_id}; } } $model->question_id = $id; $model->member_id = Yii::$app->getUser()->id; $model->save(); } } if (!empty($questionsModel->category_id)) { $this->saveProgress($questionsModel->category_id); } return true; } $this->stepsInformation['questionsAnswers'] = $questionsAnswers; return false; }
/** * Finds the FieldsTypes model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return FieldsTypes the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = FieldsTypes::find()->where(['id' => $id])->multilingual()->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Displays homepage. * * @return mixed */ public function actionIndex() { if (!Yii::$app->user->isGuest) { Yii::$app->MappingComponent->process(); $steps = Yii::$app->MappingComponent->getSteps(); if (empty($steps['view'])) { $user = Yii::$app->getUser()->getIdentity(); $user->status = User::STATUS_ACTIVE; if ($user->save()) { return Yii::$app->response->redirect(array('members/index')); } else { Yii::$app->getSession()->setFlash('warning', Yii::t('errors', 'Can not update user status. Please contact system administrator')); } } $settingsModel = GeneralSettings::findOne(['name' => 'mapping_page_id']); //$pageModel = CmsPages::findOne(['id' => $settingsModel->value]); return $this->render('mapping', ['steps' => $steps]); $user = Yii::$app->getUser()->getIdentity(); //@TODO new logic to find out if there are answers /*$answers = MembersQuestionsAnswers::find(['member_id' => $user->id])->count(); if ($answers > 0) { $user->status = User::STATUS_ACTIVE; if ($user->save()) { return Yii::$app->response->redirect(array('members/index')); } else { Yii::$app->getSession()->setFlash('warning', Yii::t('errors', 'Can not update user status. Please contact system administrator')); } }*/ if (Yii::$app->request->post()) { $mappingQuestionsSaved = false; if ($questionsAnswers->load(Yii::$app->request->post()) && $questionsAnswers->validate()) { foreach ($questionsAnswers->attributes as $attribute_id => $attribute) { $attributesArray = explode('_', $attribute_id); if (count($attributesArray) > 1) { list($name, $id) = $attributesArray; if (!($model = MembersQuestionsAnswers::findOne(['question_id' => $id, 'member_id' => Yii::$app->getUser()->id]))) { $model = new MembersQuestionsAnswers(); } $has_option = false; if ($questionsModel = MappingQuestions::findOne($id)) { $type_id = $questionsModel->type_id; $has_option = FieldsTypes::findOne($type_id)->has_options; } if ($has_option) { $model->value = ''; $model->option_id = ''; if ($optionsModel = MappingQuestionsToOptions::findOne($questionsAnswers->{$attribute_id})) { $model->value = $optionsModel->title; $model->option_id = $optionsModel->id; } } else { $model->value = $questionsAnswers->{$attribute_id}; } $model->question_id = $id; $model->member_id = Yii::$app->getUser()->id; $model->save(); } } $mappingQuestionsSaved = true; } if ($mappingQuestionsSaved) { $user = Yii::$app->getUser()->getIdentity(); //$user->status = User::STATUS_ACTIVE; if ($user->save()) { return Yii::$app->response->redirect(array('members')); } else { Yii::$app->getSession()->setFlash('warning', Yii::t('errors', 'Can not save mapping data. Please contact system administrator')); } } } //$categoryModel = MappingCategories::findOne(['id' => $pageModel->mapping_id]); $categoryModel = MappingCategories::find()->where(['is_active' => 1])->orderBy('sort_order')->all(); $questionsModel = \backend\models\MappingQuestions::find()->where(['category_id' => $category->id])->with('fieldsTypes')->all(); //$questionsModel = MappingQuestions::find()->where(['category_id' => $categoryModel->id])->with('fieldsTypes')->all(); return $this->render('mapping', ['questionsAnswers' => $questionsAnswers, 'pageModel' => $pageModel, 'categoryModel' => $categoryModel]); } else { return Yii::$app->response->redirect(array('site/login')); } }
?> <?php echo $form->field($model, 'order')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'category_id')->hiddenInput(['value' => $category_id])->label(false); ?> <?php echo $form->field($model, 'id')->hiddenInput(['value' => $model->id])->label(false); ?> <?php echo $form->field($model, 'type_id')->dropDownList(ArrayHelper::map(FieldsTypes::find()->all(), 'id', 'title'), ['prompt' => 'Select Option Type']); ?> <?php echo $form->field($model, 'is_required')->checkbox(['label' => Yii::t('backend', 'Required')]); ?> <?php echo $form->field($model, 'has_other')->checkbox(); ?> <?php echo $form->field($model, 'is_active')->checkbox(['label' => Yii::t('backend', 'Active')]); ?>