Ejemplo n.º 1
0
 /**
  * Finds the Question model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Question the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Question::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 2
0
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     $id = Yii::$app->request->get('id');
     $this->question = Question::findOne($id);
     if (!$this->question) {
         throw new HttpException(404, "Question not found");
     }
     return true;
     // or false to not run the action
 }
Ejemplo n.º 3
0
 /**
  * Displays a single Survey model.
  * @param integer $id
  * @param integer $Administrator_id
  * @return mixed
  */
 public function actionView($id)
 {
     $validate = false;
     $model = $this->findModel($id);
     if (Yii::$app->user->can('surveyDo') && !SurveyHasParticipant::checkParticipantHasDone($id) && $model->is_enable == 1) {
         $validate = true;
     }
     if (Yii::$app->user->can('surveyEdit')) {
         $validate = true;
     }
     if ($validate) {
         //The permission name
         $questionModels = [];
         $questions = Question::getAllQuestionBySurveyId($model->id);
         foreach ($questions as $row) {
             $question = Question::findOne(['id' => $row['id']]);
             if ($question->required == 1) {
                 $question->temp_input_required = null;
             }
             if (TextBox::checkIsTextBoxByQuestionId($row['id'])) {
                 $question->temp_type = 0;
                 array_push($questionModels, $question);
                 continue;
             }
             if (Checkbutton::checkIsCheckBoxByQuestionId($row['id'])) {
                 $question->temp_type = 1;
                 array_push($questionModels, $question);
                 continue;
             }
             if (RadioButton::checkIsRadioButtonByQuestionId($row['id'])) {
                 $question->temp_type = 2;
                 array_push($questionModels, $question);
                 continue;
             }
         }
         $post = Yii::$app->request->post();
         if (Model::loadMultiple($questionModels, $post)) {
             foreach ($questionModels as $row) {
                 if ($row['required'] == 1) {
                     $input = $row['temp_input_required'];
                 } else {
                     $input = $row['temp_input'];
                     if ($input == '') {
                         continue;
                     }
                 }
                 if ($row['temp_type'] == 0) {
                     $respond = new TextResponse();
                     $respond->content = $input;
                     $respond->TextBox_id = $row['id'];
                     $respond->save();
                 }
                 if ($row['temp_type'] == 1) {
                     foreach ($input as $checked) {
                         Checkbutton::increaseOptionById($checked);
                     }
                 }
                 if ($row['temp_type'] == 2) {
                     Radiobutton::increaseOptionById($input);
                 }
             }
             $participant = new SurveyHasParticipant();
             $participant->Participant_id = Yii::$app->user->id;
             $participant->Survey_id = $model->id;
             $participant->datetime = date("Y-m-d H:i:s");
             $participant->save();
             \app\models\User::addScore(5, Yii::$app->user->id);
             return $this->redirect(['index', 'done' => true]);
         } else {
             //die(var_dump($questionModels));
             return $this->render('view', ['model' => $model, 'questionModels' => $questionModels]);
         }
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
 }
Ejemplo n.º 4
0
<?php

use yii\helpers\Html;
use yii\widgets\DetailView;
use app\models\Question;
/* @var $this yii\web\View */
/* @var $model app\models\HardQuestion */
$question = Question::findOne(['id' => $model->question_id]);
$this->title = 'Вопрос №' . $question->id;
$this->params['breadcrumbs'][] = ['label' => 'Вопрос №' . $question->id, 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hard-question-view">

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


        <?php 
$variants = [$question->var1 => $question->var1, $question->var2 => $question->var2, $question->var3 => $question->var3, $question->var4 => $question->var4, $question->var5 => $question->var5];
?>

        <div class="question-row row">
            <div id="question<?php 
echo $question->id;
?>
" class="hard-question">
            <?php 
echo Html::a('<i class="fa fa-fw fa-minus"></i>', '/graduate/hard-question/remove?question_id=' . $question->id, ['onclick' => "\n                            \$.ajax({\n                            type     :'POST',\n                            cache    : false,\n                            url  : '/graduate/hard-question/remove?question_id=" . $question->id . "',\n                            success  : function(response) {\n                                \$('#close').html(response);\n                            }\n                            });return false;"]);
Ejemplo n.º 5
0
use yii\grid\GridView;
use app\models\Question;
use app\models\Subject;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Сложные вопросы';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hard-question-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'description', 'format' => 'html', 'value' => function ($model) {
    return Question::findOne(['id' => $model->question_id])->description;
}], ['attribute' => 'subject_id', 'value' => function ($model) {
    $subject_id = Question::findOne(['id' => $model->question_id])->subject_id;
    return Subject::findOne(['id' => $subject_id])->title;
}], ['attribute' => 'section', 'value' => function ($model) {
    if (Question::findOne(['id' => $model->question_id])->section == 0) {
        return 'Русское';
    } else {
        return 'Казахское';
    }
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Ejemplo n.º 6
0
 public function getQuestionContentByQuestionId($id)
 {
     $raw = Question::findOne($id);
     return $raw['content'];
 }
Ejemplo n.º 7
0
 private function checkSubCondition($condition)
 {
     $q['condition'] = $condition;
     if ($q['condition'] == "") {
         return true;
     }
     $negate = false;
     if ($condition[0] == "!") {
         $q['condition'] = substr($q['condition'], 1);
         $negate = true;
     }
     $dat = explode(".", $q['condition']);
     $result = Result::findOne(['e_fr_id' => $dat[0], 'e_z_id' => Yii::$app->session['anketData']['code']['z_id']]);
     //$quer = "select a_id, antwort from ".RES." where e_fr_id='".$dat[0]."' and e_z_id='".$user['uid']."'";
     $question = Question::findOne($dat[0])->toArray();
     $ok = false;
     //If there were no answers
     if (is_null($result)) {
         return $ok;
     }
     $aid = $result->a_id;
     $answers = $result->antwort;
     $alist = array();
     if (trim($answers) == "") {
         $alist[] = $aid;
     } else {
         $questionAnswers = explode(";", $question['antworten']);
         $userAnswers = explode(";", $answers);
         for ($i = 0; $i < count($questionAnswers); $i++) {
             foreach ($userAnswers as $userAnswer) {
                 if ($userAnswer == $questionAnswers[$i]) {
                     $alist[] = $i;
                 }
             }
         }
     }
     foreach ($alist as $a) {
         if ($a == $dat[1] - 1) {
             if (isset($a)) {
                 $ok = true;
             }
         }
     }
     if ($negate) {
         return !$ok;
     } else {
         return $ok;
     }
 }