Ejemplo n.º 1
0
        case 1:
            $row_url = Yii::$app->urlManager->createUrl(['answer/step1', 'id' => $row->id]);
            break;
        case 2:
        case 3:
            $row_url = Yii::$app->urlManager->createUrl(['answer/step2-answer2', 'id' => $row->id]);
            break;
        default:
            $row_url = '';
            break;
    }
    $row_ur_done = Yii::$app->urlManager->createUrl(['survey/done', 'id' => $row->id]);
    //发布
    $row_ur_done_publish = Yii::$app->urlManager->createUrl(['survey/done', 'is_ajax' => 1, 'id' => $row->id]);
    $row_ur_change = Yii::$app->urlManager->createUrl(['survey/step2', 'id' => $row->id]);
    $image = common\models\Survey::getImageUrl($row);
    ?>
				<dl>
					<a href="<?php 
    echo $row_url;
    ?>
">
						<dt>
							<img src="<?php 
    echo $image;
    ?>
"
								alt="<?php 
    echo $row->title;
    ?>
">
Ejemplo n.º 2
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,
     //         ]);
 }
Ejemplo n.º 3
0
    /**
     * Lists all Survey models.
     *
     * @return mixed
     */
    public function actionIndexAjax()
    {
        $sort = Yii::$app->request->get('sort', 1);
        $self = Yii::$app->request->get('self', 0);
        $queryParams = Yii::$app->request->queryParams;
        if ($self > 0) {
            if (ZCommonSessionFun::get_user_id() < 1) {
                $url = Yii::$app->urlManager->createUrl([ZCommonSessionFun::urlLoginUserStr]);
                return $this->redirect($url);
            }
            $queryParams['SurverySearch']['uid'] = ZCommonSessionFun::get_user_id();
        } else {
            $queryParams['SurverySearch']['is_publish'] = 1;
        }
        $queryParams['SurverySearch']['is_publish'] = 1;
        $this->layout = false;
        $searchModel = new SurverySearch();
        $query = $searchModel->query($queryParams);
        $count = $query->count();
        // 分页
        $pagination = new Pagination();
        // 每页现实数量
        $pagination->pageSize = $this->pageSize;
        // 总数量
        $pagination->totalCount = $count;
        $offset = $pagination->getOffset();
        $limit = $pagination->getLimit();
        $query->offset($offset);
        $query->limit($limit);
        if ($self > 0) {
            $sort = 1;
        }
        // 最新
        if ($sort > 0) {
            $query->orderBy(['created' => SORT_DESC]);
        } else {
            $query->orderBy(['answer_count' => SORT_DESC]);
        }
        $a_models = $query->all();
        $role = ZCommonSessionFun::get_role();
        $pageCount = $pagination->getPageCount();
        $page = Yii::$app->request->get('page', 0);
        $data = '';
        // 有数据,从第1页开始到最后一页
        if ($pageCount > 0 && $page > 0) {
            // echo $page,$pageCount;
            // 超过最后一页
            if ($page > $pageCount) {
                $tempData['data'] = $data;
                $tempData['status'] = 0;
                $tempData['message'] = '';
                echo json_encode($tempData);
                exit;
            }
            foreach ($a_models as $key => $row) {
                if ($row->tax == 1) {
                    $url = Yii::$app->urlManager->createUrl(['answer/step1', 'id' => $row->id]);
                } else {
                    $url = Yii::$app->urlManager->createUrl(['answer/step2-answer2', 'id' => $row->id]);
                }
                $image = common\models\Survey::getImageUrl($row);
                $is_top_text = '';
                $is_top_url = '';
                $op0 = Yii::$app->urlManager->createUrl(['survey/recommend', 'id' => $row->id, 'op' => 0]);
                $op1 = Yii::$app->urlManager->createUrl(['survey/recommend', 'id' => $row->id, 'op' => 1]);
                $is_top = 0;
                if ($row->is_top > 0) {
                    $is_top_text = '取消推荐';
                    $is_top = 0;
                } else {
                    $is_top_text = '推荐';
                    $is_top = 1;
                }
                $str_recommend = '';
                if ($role == 1) {
                    $str_recommend = <<<str
       \t\t\t\t<a
       \t\t\t\t\tis_top="{$is_top}" op0="{$op0}" op1="{$op1}"
       \t\t\t\t\tclass="play recommend" data-ui="danger small icon-right" style="right: 75px;"> {$is_top_text}<i
       \t\t\t\t\t\tclass="iconfont icon-right"></i>
       \t\t\t\t</a>
str;
                }
                if ($self > 0) {
                    $row_ur_done = Yii::$app->urlManager->createUrl(['survey/done', 'id' => $row->id]);
                    // 发布
                    $row_ur_done_publish = Yii::$app->urlManager->createUrl(['survey/done', 'is_ajax' => 1, 'id' => $row->id]);
                    $row_ur_change = Yii::$app->urlManager->createUrl(['survey/step2', 'id' => $row->id]);
                    $data .= <<<str
                   <dl>
                   <a href="{$url}">
                   <dt>
                   <img src="{$image}"
                   alt="你有多怕谈恋爱:恋爱恐怖程度自评">
                   </dt>
                   <dd>
                   <h3>{$row->title}</h3>
                   </dd>
                   <dd>{$row->intro}</dd>
                   <dd>
                       <a class="btn_bg" href="{$row_ur_done}">预览</a>
    \t\t\t\t      &nbsp; &nbsp;
    \t\t\t\t      <a class="btn_bg ajax-publish" href="{$row_ur_done_publish}">发布</a>
    \t\t\t\t      &nbsp;&nbsp;
    \t\t\t\t    <a class="btn_bg" href="{$row_ur_change}">修改</a>
    \t\t\t\t\t<span>测试过:{$row->answer_count}</span>
                   </dd>

                   </a>
                   </dl>
str;
                } else {
                    $data .= <<<str


\t\t\t    <li class="diy-item" date-id="2626"><a
\t\t\t\t\thref="{$url}"
\t\t\t\t\ttarget="_blank">
\t\t\t\t\t\t<figure class="cover">
\t\t\t\t\t\t\t<img class=""
\t\t\t\t\t\t\t\tsrc="{$image}">
\t\t\t\t\t\t</figure>
\t\t\t\t\t\t<div class="diy-meta">
\t\t\t\t\t\t\t<div class="title mui-ellipsis">{$row->title}</div>
\t\t\t\t\t\t\t<span class="iconfont icon-start-filled5"></span> <span
\t\t\t\t\t\t\t\tclass="count">{$row->answer_count}人在测</span>
\t\t\t\t\t\t\t<div class="desc mui-ellipsis">{$row->intro}</div>
\t\t\t\t\t\t</div>
\t\t\t\t</a>
                   {$str_recommend}
\t\t\t\t<a
\t\t\t\t\thref="{$url}"
\t\t\t\t\tclass="play" data-ui="danger small icon-right"> 去测<i
\t\t\t\t\t\tclass="iconfont icon-right"></i>
\t\t\t\t</a></li>
str;
                }
            }
        }
        $tempData['data'] = $data;
        $tempData['status'] = 0;
        $tempData['message'] = '';
        echo json_encode($tempData);
        exit;
    }
Ejemplo n.º 4
0
		<a class="btn_bg"
		href="<?php echo Yii::$app->urlManager->createUrl(['survey/step2','id'=>$model->id]);?>"
		id="prev-step">上一步</a>
		<br />

		<a class="btn_bg" href="<?php echo Yii::$app->urlManager->createUrl(['survey/done','id'=>$model->id]);?>">
	       <input type="button" value="预览">
	    </a>
<br />
*/
?>

        <div id="image-wrap">
            <?php 
if (isset($model->images->image) && !empty($model->images->image)) {
    echo '<img src="', Survey::getImageUrl($model), '"/>';
}
?>
        </div>



        <?php 
ActiveForm::end();
?>
        <p class="text-hint"><?php 
echo $text_hint;
?>
</p>
	</section>