Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MappingCategories::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'duration' => $this->duration, 'sort_order' => $this->sort_order, 'is_active' => $this->is_active]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'attributes_id', $this->attributes_id]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 /**
  * @return array|\yii\db\ActiveRecord[]
  */
 public function getCategories($options = array(), $asArray = true, $all = true)
 {
     //if (empty($this->categories)) {
     $categories = MappingCategories::find()->orderBy('sort_order, name');
     if (!empty($options)) {
         $categories->where($options);
     }
     if ($asArray) {
         $categories->asArray();
     }
     if ($all == true) {
         $this->categories = $categories->all();
     } else {
         $this->categories = $categories->one();
     }
     //}
     return $this->categories;
 }
Ejemplo n.º 3
0
 public function actionMapping_()
 {
     if (!Yii::$app->user->isGuest) {
         $steps = Yii::$app->MappingComponent->getSteps();
         print_r($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'));
                         }
                     }*/
         $settingsModel = GeneralSettings::findOne(['name' => 'mapping_page_id']);
         $pageModel = CmsPages::findOne(['id' => $settingsModel->value]);
         $categoryModel = MappingCategories::findOne(['id' => $pageModel->mapping_id]);
         $questionsAnswers = new MembersQuestionsAnswers($categoryModel->id);
         if (Yii::$app->request->post()) {
             $mappingQuestionsSaved = false;
             echo $questionsAnswers->validate();
             print_r($questionsAnswers->errors);
             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])->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'));
     }
 }
Ejemplo n.º 4
0
    $category_options['options'] = [$model->category_id => ['Selected' => 'selected']];
    $questions_condition['category_id'] = $model->category_id;
    $question_options['options'] = [$model->question_id => ['Selected' => 'selected']];
    $answers_condition['question_id'] = $model->question_id;
    $answers_options['options'] = [$model->options_id => ['Selected' => 'selected']];
}
$question_items = array();
$options_items = array();
if (!$model->isNewRecord) {
    $question_items = \yii\helpers\ArrayHelper::map(\backend\models\MappingQuestions::find()->joinWith('fieldsTypes')->where($questions_condition)->all(), 'id', 'title');
    $options_items = \yii\helpers\ArrayHelper::map(\backend\models\MappingQuestionsToOptions::find()->where($answers_condition)->all(), 'id', 'title');
}
?>

    <?php 
echo $form->field($model, 'category_id')->dropDownList(\yii\helpers\ArrayHelper::map(\backend\models\MappingCategories::find()->all(), 'id', 'name'), $category_options)->label(Yii::t('backend', 'Select Categories'));
?>

    <?php 
echo $form->field($model, 'question_id')->dropDownList($question_items, $question_options)->label(Yii::t('backend', 'Select Question'));
?>

    <?php 
echo $form->field($model, 'options_id')->dropDownList($options_items, $answers_options)->label(Yii::t('backend', 'Select Answers'));
?>

    <?php 
echo $form->field($model, 'progress')->textInput();
?>

    <?php 
 /**
  * Finds the MappingCategories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MappingCategories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MappingCategories::find()->where(['id' => $id])->multilingual()->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }