Esempio n. 1
0
 public function actionUpdateAnswer($id)
 {
     $btnYes = Yii::$app->request->post('btn-yes');
     $btnNo = Yii::$app->request->post('btn-no');
     if (isset($btnNo)) {
         $memberProgress = MembersProgress::find()->where(['member_id' => Yii::$app->user->id, 'category_id' => $id])->one();
         if (!$memberProgress) {
             $memberProgress = new MembersProgress();
             $memberProgress->progress = 1;
             $memberProgress->member_id = Yii::$app->user->id;
             $memberProgress->category_id = $id;
         } else {
             $memberProgress->progress++;
         }
         if ($memberProgress->save()) {
             return Yii::$app->response->redirect(array('members/index'));
         }
     } else {
         $questionsAnswers = new MembersQuestionsAnswers($id);
         $precessStatus = Yii::$app->MappingComponent->processQuestions($questionsAnswers);
         if ($precessStatus) {
             return Yii::$app->response->redirect(array('members/index'));
         } else {
             $categoryModel = MappingCategories::findOne($id);
             $questionsModel = MappingQuestions::find()->where(['category_id' => $id, 'is_active' => 1])->orderBy('order DESC')->with('fieldsTypes')->all();
             return $this->render('update_answers', ['categoryModel' => $categoryModel, 'questionsModel' => $questionsModel, 'questionsAnswers' => $questionsAnswers]);
         }
     }
 }
Esempio n. 2
0
 public function run()
 {
     $category = MappingCategories::findOne($this->mappingCategoryId);
     $route = Yii::$app->controller->route;
     $request_id = Yii::$app->request->get('id');
     $ignore_route = array('site/changepassword', 'mapping/index');
     if ($route == 'mapping/update-answer' && $request_id == $this->mappingCategoryId || in_array($route, $ignore_route)) {
         return false;
     } else {
         if ($category) {
             return $this->render('mapping/modal', ['category' => $category]);
         }
     }
 }
Esempio n. 3
0
 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'));
     }
 }
Esempio n. 4
0
<?php

use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\models\MappingQuestions */
$this->title = Yii::t('backend', 'Create Question');
$this->params['breadcrumbs'][] = ['label' => Yii::t('backend', 'Mapping Categories'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => \backend\models\MappingCategories::findOne($category_id)->name . ' ' . Yii::t('backend', 'Questions'), 'url' => ['mapping-categories/view', 'id' => $category_id]];
$this->params['breadcrumbs'][] = $this->title;
$this->registerJsFile(Yii::getAlias('@web/js/questions.js'), ['depends' => ['yii\\web\\YiiAsset', 'yii\\bootstrap\\BootstrapAsset']]);
?>
<div class="mapping-questions-create">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <?php 
echo $this->render('_form', ['model' => $model, 'category_id' => $category_id, 'optionsDataProvider' => $optionsDataProvider, 'optionsModel' => $optionsModel, 'languages' => $languages, 'languageDefault' => $languageDefault]);
?>

</div>