示例#1
0
				<div id="panel3" class="panel-body js_result trueresult">
					<hr  style="display: none;">
					<div id="test_content">
						<div class="progre">
							<span class="value"  style="display: none;"><span class="current">我的测试结果</span></span>
							<p>
							<?php 
echo $model_SurveyResulte->name;
echo $model_AnswerUser->answer_name ? '<span class="answer-name">' . $model_AnswerUser->answer_name . '</span>' : '';
echo $model_SurveyResulte->value;
?>
				            </p>
				            <div>
            			    <?php 
if (isset($model_SurveyResulte->image) && !empty($model_SurveyResulte->image)) {
    echo '<img style="width: 100%;" src="', $image = SurveyResulte::getImageUrl($model_SurveyResulte), '"/>';
}
?>
            				</div>
            				
						</div>

					</div>
					
					<dl>
						<dt>详细分析:</dt>
						<dd style="" id="details">
							<p></p>
							<p>
    							<?php 
echo $model_SurveyResulte->intro;
echo $model_SurveyResulte->sr_id;
?>
" >
            <input type="hidden" id="SurveyResulte-image"

            class="form-control " name="SurveyResulte[image]" value="<?php 
echo $model_SurveyResulte->image;
?>
">

            <div class="help-block"></div>
        </div>
		<div id="image-wrap">
            <?php 
if (isset($model_SurveyResulte->image) && !empty($model_SurveyResulte->image)) {
    echo '<img src="', $image = SurveyResulte::getImageUrl($model_SurveyResulte), '"/>';
}
?>
        </div>
        <br/>
        <div class="btn_bg btn-2" style="padding:0;" >
            <?php 
$prv_url = Yii::$app->urlManager->createUrl(['survey/step4_2_question', 'id' => $model->id]);
$model->tax == 2 ? $prv_url = Yii::$app->urlManager->createUrl(['survey/step4_3', 'id' => $model->id]) : '';
$model->tax == 1 ? $prv_url = Yii::$app->urlManager->createUrl(['survey/step1_3', 'id' => $model->id]) : '';
$model->tax == 3 ? $prv_url = Yii::$app->urlManager->createUrl(['survey/step4_2_question', 'id' => $model->id]) : '';
?>
			<a  style=""
			href="<?php 
echo $prv_url;
?>
示例#3
0
 /**
  * 检测发布
  */
 public function checkPublish($question_all, $model, $result_all)
 {
     $message = '';
     isset($question_all['questions'][0]) ? null : ($question_all['questions'] = []);
     if ($model->tax > 1) {
         !isset($question_all['questions'][0]) ? $message = '至少包含一个问题,' : null;
     }
     isset($question_all['options'][0]) ? null : ($question_all['options'] = []);
     isset($result_all[0]) ? null : ($result_all = []);
     $replace_prefix = '<b class="replace_word" style="color: blue;">';
     $replace_self = false;
     $replace_suffix = '</b>';
     $replace = true;
     $all_count = 0;
     // 敏感词数量
     $all_count_empty = 0;
     // 未填写项
     $all_question_empty = 0;
     // 空问题数量
     $all_question_option_empty = 0;
     // 空选项数量
     ZCommonFun::replace_filter_words($model->title, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
     $all_count += $replace_count;
     ZCommonFun::replace_filter_words($model->intro, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
     $all_count += $replace_count;
     empty($model->title) ? $all_count_empty++ : null;
     empty($model->intro) ? $all_count_empty++ : null;
     // 问题
     $index = 0;
     foreach ($question_all['questions'] as $key => $question) {
         $index++;
         $label = $question->label;
         $replace_count = 0;
         $label = ZCommonFun::replace_filter_words($label, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
         $all_count += $replace_count;
         $error = !empty($label) ? '' : '问题不能为空';
         $error ? $all_count_empty++ : null;
         isset($question_all['options'][$key]) ? null : ($question_all['options'][$key] = []);
         if (count($question_all['options'][$key]) < 1) {
             $all_count_empty++;
         }
         foreach ($question_all['options'][$key] as $key2 => $question_option) {
             $option_label = $question_option->option_label;
             $option_label = ZCommonFun::replace_filter_words($option_label, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
             $all_count += $replace_count;
             $error_option_label = !empty($option_label) ? '' : '选项不能为空';
             $error_option_label ? $all_count_empty++ : null;
             $speparator = $question_option->skip_question > 0 || $question_option->skip_resulte > 0 ? '——' : '';
             $skip_text = '';
             $question_option->skip_question > 0 ? $skip_text = "转{$question_option->skip_question}题" : '';
             $question_option->skip_resulte > 0 ? $skip_text = "转{$question_option->skip_question}结果" : '';
             $score_text = '';
             if ($model->tax == 2) {
                 $score_text = '—(' . $question_option->option_score . '分)';
             }
         }
     }
     $index = 0;
     !isset($result_all[0]) ? $message .= '至少包含一个测试结果' : '';
     foreach ($result_all as $key => $result) {
         $index++;
         $name = $result->name;
         $name = ZCommonFun::replace_filter_words($name, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
         $all_count += $replace_count;
         $error_name = !empty($name) ? '' : '姓名之前不能为空';
         $error_name ? $all_count_empty++ : null;
         $value = $result->value;
         $value = ZCommonFun::replace_filter_words($value, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
         $all_count += $replace_count;
         $error_value = !empty($value) ? '' : '姓名之后不能为空';
         $error_value ? $all_count_empty++ : null;
         $intro = $result->intro;
         $intro = ZCommonFun::replace_filter_words($intro, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
         $all_count += $replace_count;
         $error_intro = !empty($intro) ? '' : '结果详情不能为空';
         $error_intro ? $all_count_empty++ : null;
         $image = $result->image;
         $error_image = !empty($image) ? '' : '图片不能为空';
         $error_image ? $all_count_empty++ : null;
         $image = SurveyResulte::getImageUrl($result);
         $score_text = '';
         if ($model->tax == 2) {
             $score_text = '' . $result->score_min . '分~~' . $result->score_max . '分';
         }
     }
     return [$all_count, $all_count_empty, 'message' => $message];
 }
示例#4
0
 /**
  * 分数型问题回答2
  */
 public function actionStep2Answer2($id)
 {
     $this->layout = false;
     $model = Survey::findOne($id);
     if (!$model) {
         //没找到
         $model = new Survey();
     }
     if ($model->is_publish < 1) {
         $this->popupMessage($model->title . '未发布,不能测试');
         exit;
     }
     $data = $model->FindAllQuestionsOptions($id);
     //                 ZCommonFun::print_r_debug($_POST);
     //                 exit;
     $posts = Yii::$app->request->post();
     $error = '';
     if (isset($posts['name'])) {
         is_array($posts['options']) ?: ($posts['options'] = array());
         $op = count($posts['options']) > 0 ? true : false;
         $res = isset($posts['res']) ? intval($posts['res']) : 0;
         $res_model_SurveyResulte = $res > 0 ? SurveyResulte::findOne($res) : null;
         if ($res_model_SurveyResulte && $res_model_SurveyResulte->s_id == $id) {
         } else {
             $res_model_SurveyResulte = null;
         }
         $total_score = 0;
         $save = 0;
         $result = null;
         //保存结果
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $name = isset($posts['name']) ? $posts['name'] : '';
             $year = isset($posts['birth']['year']) ? $posts['birth']['year'] : 2015;
             $month = isset($posts['birth']['month']) ? $posts['birth']['month'] : '01';
             $day = isset($posts['birth']['day']) ? $posts['birth']['day'] : '01';
             $constellation = isset($posts['constellation']) ? intval($posts['constellation']) : 0;
             $constellation = $constellation > 0 && $constellation < 13 ? $constellation : 0;
             $birth = $year . '-' . $month . '-' . $day;
             $birth = date('Y-m-d', strtotime($birth));
             $model_AnswerUser = new AnswerUser();
             $model_AnswerUser->sid = $id;
             $model_AnswerUser->table = 'survey_resulte';
             $res_model_SurveyResulte ? $model_AnswerUser->table_id = $res_model_SurveyResulte->sr_id : null;
             $model_AnswerUser->answer_name = $name;
             $model_AnswerUser->answer_age = $birth;
             $model_AnswerUser->constellation = $constellation;
             $model_AnswerUser->ip = self::getUserIP();
             if (!$model_AnswerUser->save()) {
                 $error = '用户操作失败';
                 $transaction->rollBack();
             } else {
                 foreach ($data['options'] as $key => $value) {
                     foreach ($value as $option) {
                         foreach ($posts['options'] as $question_id => $row) {
                             //找到选项
                             if ($option->qo_id = $row[0]) {
                                 $model_Answer = new Answer();
                                 $model_Answer->table_id = $id;
                                 $model_Answer->question_id = $option->question_id;
                                 $model_Answer->qo_id = $row[0];
                                 $model_Answer->answer_score += $option->option_score;
                                 $model_Answer->au_id = $model_AnswerUser->au_id;
                                 $total_score += $model_Answer->answer_score;
                                 $model_Answer->save() ? $save++ : null;
                             }
                         }
                     }
                 }
                 if ($save > 0) {
                     $model_SurveyResulte = new SurveyResulte();
                     //如果直接选择了答案
                     if ($model_AnswerUser->table == 'survey_resulte' && $model_AnswerUser->table_id > 0) {
                         $result = $res_model_SurveyResulte;
                         //
                     } else {
                         $result = $model_SurveyResulte->getStep2Result($id, $model_AnswerUser->answer_score);
                     }
                     if ($result && !$res_model_SurveyResulte) {
                         //保存回答者结果,防止用户更改数据导致结果丢失
                         $mode_AnswerSurveyResulte = new AnswerSurveyResulte();
                         $mode_AnswerSurveyResulte->attributes = $result->attributes;
                         $mode_AnswerSurveyResulte->save();
                         $model_AnswerUser->table == 'answer_survey_resulte';
                         $model_AnswerUser->table_id = $mode_AnswerSurveyResulte->answer_sr_id;
                     }
                     $model_AnswerUser->save();
                     $transaction->commit();
                     //设置测试数量
                     $model->setAnswerCount($id);
                     $model_UserProfile = new UserProfile();
                     $model_UserProfile->setTestCount($model_AnswerUser->uid);
                     return $this->redirect(['resulte', 'au_id' => $model_AnswerUser->au_id]);
                 } else {
                     $error = '没有选项';
                     $transaction->rollBack();
                 }
             }
         } catch (\Exception $e) {
             $error = '事物异常';
             ZCommonFun::print_r_debug($e);
             $transaction->rollBack();
         }
     }
     $model_Users = null;
     $model_UsersProfile = null;
     if ($model->uid) {
         $zhao_condition['uid'] = $model->uid;
         $model_Users = User::findOne($zhao_condition);
         $model_UsersProfile = UserProfile::findOne($zhao_condition);
     }
     !$model_Users ? $model_Users = new User() : '';
     !$model_UsersProfile ? $model_UsersProfile = new UserProfile() : '';
     $model_UsersProfile->uid = $model->uid;
     //         echo $error;
     //         exit;
     //         ZCommonFun::print_r_debug($result);
     $model_SurveyOperation = new SurveyOperation();
     $models_SurveyOperation = $model_SurveyOperation->getIsTop();
     return $this->render('step2answer3', ['models_SurveyOperation' => $models_SurveyOperation, 'data' => $data, 'model' => $model, 'error' => $error, 'posts' => $posts, 'image' => Survey::getImageUrl($model), 'model_Users' => $model_Users, 'model_UsersProfile' => $model_UsersProfile, 'randSurvey' => $this->getRandSurvey()]);
     //         return $this->render('step2answer',[
     //             'data'=>$data,
     //             'model'=>$model,
     //             'error'=>$error,
     //             'posts'=>$posts,
     //             'image'=>Survey::getImageUrl($model),
     //             'model_Users'=>$model_Users,
     //             'model_UsersProfile'=>$model_UsersProfile,
     //         ]);
 }
示例#5
0
 /**
  * 分页查找测试结果
  * @param integer $survey_id
  * @param integer $limit
  * @param integer $offset
  * @param boolean $question 是否查找问题,默认true
  * @param boolean $SurveyResulte_lis_multi 是否多条
  * @return array
  */
 public function findOneSurveyResulte($survey_id, $limit, $offset, $question = true, $SurveyResulte_lis_multi = false)
 {
     $model_SurveyResulte = new SurveyResulte();
     $model_QuestionOptions = new QuestionOptions();
     $condition['s_id'] = $survey_id;
     //结果数量
     $data['count'] = SurveyResulte::find()->where($condition)->orderBy([])->count();
     //结果内容
     $data['SurveyResulte'] = [];
     //问题
     $data['question'] = [];
     if ($data['count'] > 0) {
         $query = $model_SurveyResulte->find()->where($condition)->limit($limit)->offset($offset);
         $model_SurveyResulte = $SurveyResulte_lis_multi ? $query->all() : $query->one();
         $data['SurveyResulte'] = $model_SurveyResulte;
     }
     $data['question'] = $question ? (new Survey())->FindAllQuestionsOptions($survey_id) : [];
     return $data;
 }
示例#6
0
 /**
  * 分数型测试结果保存
  * @param unknown $post
  * @param unknown $condition
  * @param unknown $id
  */
 public function step4_2SaveResulteCondition2($post, $condition, $id)
 {
     $post_data = [];
     $url = $error = '';
     if (isset($post['name'][0])) {
         foreach ($post['name'] as $key => $name) {
             $value = isset($post['value'][$key]) ? $post['value'][$key] : '';
             $intro = isset($post['intro'][$key]) ? $post['intro'][$key] : '';
             $min = isset($post['score-min'][$key]) ? $post['score-min'][$key] : 1;
             $max = isset($post['score-max'][$key]) ? $post['score-max'][$key] : 1;
             $temp = $min > $max ? $min : $max;
             if ($min > $max) {
                 $temp = $min;
                 $min = $max;
                 $max = $temp;
             }
             if ($max > 0 && $min > 0 && !empty($value) && isset($name[0])) {
                 $post_data[$key]['name'] = $value;
                 $post_data[$key]['value'] = $value;
                 $post_data[$key]['intro'] = $intro;
                 $post_data[$key]['sr-id'] = isset($post['sr-id'][$key]) ? $post['sr-id'][$key] : null;
                 $post_data[$key]['min'] = $min;
                 $post_data[$key]['max'] = $max;
             }
         }
         //             ZCommonFun::print_r_debug($post_data);
         //             ZCommonFun::print_r_debug($post);
         //             exit();
         //有结果
         if ($post_data) {
             //保存结果
             $transaction = Yii::$app->db->beginTransaction();
             //删除结果
             $deleteSurveyResulte = new SurveyResulte();
             $deleteAll = $deleteSurveyResulte->getAll($id);
             isset($deleteAll[0]) ? null : ($deleteAll = []);
             $sr_ids = ZCommonFun::listData($deleteAll, 'sr_id', 'sr_id');
             $save = 0;
             try {
                 foreach ($post_data as $key => $row) {
                     if (isset($row['sr-id']) && $row['sr-id'] > 0) {
                         $row_SurveyResulte = SurveyResulte::findOne($row['sr-id']);
                         if ($row_SurveyResulte) {
                             //结果存在,就不删除
                             unset($sr_ids[$row['sr-id']]);
                             if ($row_SurveyResulte->s_id != $id) {
                                 continue;
                             }
                             $save++;
                         } else {
                             $row_SurveyResulte = new SurveyResulte();
                         }
                     } else {
                         $row_SurveyResulte = new SurveyResulte();
                     }
                     $row_SurveyResulte->score_max = $row['max'];
                     $row_SurveyResulte->score_min = $row['min'];
                     $row_SurveyResulte->name = $row['name'];
                     $row_SurveyResulte->value = $row['value'];
                     $row_SurveyResulte->intro = $row['intro'];
                     $row_SurveyResulte->value = $row['value'];
                     $row_SurveyResulte->value = $row['value'];
                     $row_SurveyResulte->uid = ZCommonSessionFun::get_user_id();
                     $row_SurveyResulte->s_id = $id;
                     $row_SurveyResulte->save() ? $save++ : null;
                 }
                 if ($save > 0) {
                     $condition = null;
                     if (count($sr_ids) > 0) {
                         $condition['sr_id'] = $sr_ids;
                         $condition['s_id'] = $id;
                         //删除所有结果
                         SurveyResulte::deleteAll($condition);
                     }
                     $transaction->commit();
                     $url = ['my'];
                 }
                 //                     ZCommonFun::print_r_debug($sr_ids);
                 //                     ZCommonFun::print_r_debug($post_data);
                 //                     exit;
                 $url = ['my'];
             } catch (\Exception $e) {
                 //                     ZCommonFun::print_r_debug($e);
                 $transaction->rollBack();
             }
         }
     }
     return $url;
 }
示例#7
0
$index = 0;
foreach ($result_all as $key => $result) {
    $index++;
    $row_change_result_url = Yii::$app->urlManager->createUrl(['survey/step4_2', 'id' => $model->id, 'page' => $index]);
    $name = $result->name;
    $name = ZCommonFun::replace_filter_words($name, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
    $error_name = !empty($name) ? '' : '姓名之前不能为空';
    $value = $result->value;
    $value = ZCommonFun::replace_filter_words($value, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
    $error_value = !empty($value) ? '' : '姓名之后不能为空';
    $intro = $result->intro;
    $intro = ZCommonFun::replace_filter_words($intro, $replace_prefix, $replace_self, $replace_suffix, $replace, $replace_count);
    $error_intro = !empty($intro) ? '' : '结果详情不能为空';
    $image = $result->image;
    $error_image = !empty($image) ? '' : '图片不能为空';
    $image = SurveyResulte::getImageUrl($result);
    $score_text = '';
    if ($model->tax == 2) {
        $score_text = '' . $result->score_min . '分~~' . $result->score_max . '分';
    }
    ?>
                 <section class="layout">
                    <section data-bcless="lighten">
                        <h2><?php 
    echo '结果', $index;
    ?>
</h2>
                        <a class="change-btn" href="<?php 
    echo $row_change_result_url;
    ?>
" >修改此结果</a>