public function createAnswer(AnswerRequest $request) { // Check if current user created this application $input = $request->all(); $application = Application::find($input['application_id']); $question = Question::find($input['question_id']); if ($application->user->id != Auth::user()->id) { $request->session()->flash('error', 'Only the person who created an application may answer questions for it.'); return redirect('/login'); } if ($application->status != 'new') { $request->session()->flash('error', 'Your application has been submitted, you may no longer make changes.'); return redirect('/applications/' . $application->id . '/review'); } // Check if an answer already exists for this question $answer = Answer::firstOrNew(['application_id' => $application->id, 'question_id' => $question->id]); // Add submitted information $answer->application_id = $application->id; $answer->question_id = $question->id; $answer->answer = $input['answer']; $answer->save(); // Check if a file needs to be uploaded if ($question->type == 'file') { // Save uploaded file $upload = Document::handleUpload($request); // Save new document Document::createDocument($application, $upload, $answer); } $request->session()->flash('success', 'Your answer has been saved.'); return redirect('/applications/' . $application->id); }
public function actionIndex() { $model = Question::find()->with('answers')->where(['active' => 1]); $searchModel = new QuestionSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
function createFeedback(FeedbackRequest $request) { // Double check to make sure the current user is authorized to do this... $this->authorize('create-feedback'); $input = $request->all(); // Check application ID $application = Application::find($input['application_id']); // Check regarding ID / type, Note, nothing to be done for 'general' feedback if ($input['regarding_type'] == 'question') { $regarding = Question::find($input['regarding_id']); } elseif ($input['regarding_type'] == 'document') { // todo } // Create new feedback $feedback = new Feedback(); $feedback->application_id = $application->id; $feedback->regarding_type = $input['regarding_type']; if (isset($regarding) && $regarding->exists) { $feedback->regarding_id = $regarding->id; } // Set the current judge ID for a record of who requested this feedback $feedback->user_id = Auth::user()->id; $feedback->save(); $feedback->update($input); // Notify applicant of new feedback requested event(new FeedbackChanged($feedback, ['status' => 'created'])); $request->session()->flash('success', 'Your feedback has been requested.'); return redirect('/applications/' . $application->id . '/review'); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // $question = Question::find($id); if (!$question) { return $this->respondNotFound('Item Not Found'); } return $this->respond(['data' => [$this->questionTransformer->transform($question)]]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Question::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['fr_id' => $this->fr_id]); $query->andFilterWhere(['like', 'frage', $this->frage])->andFilterWhere(['like', 'display', $this->display])->andFilterWhere(['like', 'antworten', $this->antworten])->andFilterWhere(['like', 'suche', $this->suche]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Question::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSizeParam' => 'perpage', 'pageSizeLimit' => [30, 500]], 'sort' => ['defaultOrder' => ['occured_number' => SORT_ASC]]]); $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, 'occured_number' => $this->occured_number, 'correct_answer_id' => $this->correct_answer_id, 'author_id' => $this->author_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'active' => $this->active]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Question::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, 'description' => $this->description, 'answer_number' => $this->answer_number, 'section' => $this->section, 'cost' => $this->cost, 'level' => $this->level, 'subject_id' => $this->subject_id]); $query->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'var1', $this->var1])->andFilterWhere(['like', 'var2', $this->var2])->andFilterWhere(['like', 'var3', $this->var3])->andFilterWhere(['like', 'var4', $this->var4])->andFilterWhere(['like', 'var5', $this->var5])->andFilterWhere(['like', 'answer', $this->answer]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Question::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]); $query->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
public function allDo($params) { $query = Question::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['npp' => SORT_DESC]], 'pagination' => ['pageSize' => 50]]); $this->load($params); $query->where('npp!=0'); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('link=""'); return $dataProvider; } $query->andFilterWhere(['user_created' => $this->user_created]); return $dataProvider; }
public function comment(Request $request) { if ($request->has('answer_id')) { $answer = Answer::find($request->input('answer_id')); $comment = $answer->comments()->create(['body' => $request->input('body')]); $comment->user()->associate(\Auth::user())->save(); } else { if ($request->has('question_id')) { $question = Question::find($request->input('question_id')); $comment = $question->comments()->create(['body' => $request->input('body')]); $comment->user()->associate(\Auth::user())->save(); } } return back(); }
/** * Lists all Question models. * @return mixed */ public function actionIndex() { if (Yii::$app->user->isGuest) { return $this->redirect(['site/login']); } if (!\Yii::$app->user->can('7progress')) { return $this->goBack(); // goHome } User::checkQ(); $searchModel = new SearchQuestion(); $dataProvider = $searchModel->allPotenc(Yii::$app->request->queryParams); $dataProvider1 = $searchModel->allDo(Yii::$app->request->queryParams); //$dataProvider1->andFilterWhere(['like', 'user_take', '0']); //->andFilterWhere(['like', 'tbl_country.name', $this->country]); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'dataProvider1' => $dataProvider1, 'countOwnQ' => Question::find()->where(['user_created' => Yii::$app->user->id, 'npp' => 0])->count()]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $id = '') { if ($id == '') { $query = Question::find(); } else { $query = Question::find()->where(['e_id' => $id]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => '10']]); $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(['like', '_id', $this->_id])->andFilterWhere(['like', 'q_title', $this->q_title])->andFilterWhere(['like', 'knowledge', $this->knowledge])->andFilterWhere(['like', 'q_type', $this->q_type])->andFilterWhere(['like', 'q_choose', $this->q_choose])->andFilterWhere(['like', 'addtime', $this->addtime]); return $dataProvider; }
public function update($id, $inputs) { $question = Question::find($id); $answersLabels = $inputs['answerLabel']; foreach ($question->answers as $key => $answer) { $answer->setAttribute('label', $answersLabels[$key]); if ($key == $inputs['answerChecked']) { $answer->setAttribute('correct', true); } else { $answer->setAttribute('correct', false); } $answer->save(); } $question->fill($inputs); $question->save(); //Update pivots relations if (isset($inputs['quizz'])) { $question->quizzs()->sync($inputs['quizz']); } }
/** * Displays a single EntTest model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $q_ids = explode(',', $model->questions_ids); $questions = []; $count = 0; $isAnyAnswers = false; foreach ($q_ids as $q_id) { $questions[$count++] = Question::find()->where(['id' => $q_id])->one(); if ($_POST[$q_id]) { $isAnyAnswers = true; } if ($count > 125) { break; } } if ($isAnyAnswers) { $user_score = new UserScore(); $user_score->user_id = Yii::$app->user->identity->id; $user_score->test_id = $model->id; $user_score->test_type = 1; $user_score->score = 0; foreach ($questions as $q) { $user_score->answers .= $_POST[$q->id] . ', '; if ($_POST[$q->id] == $q->answer) { $user_score->score++; } } if (!UserScore::findOne(['user_id' => Yii::$app->user->identity->id, 'test_id' => $model->id, 'test_type' => 1])) { $user_score->save(); Yii::$app->session->setFlash('TestChecked'); } else { $score = UserScore::findOne(['user_id' => Yii::$app->user->identity->id, 'test_id' => $model->id, 'test_type' => 1]); $score->score = $user_score->score; $score->save(); Yii::$app->session->setFlash('TestChecked'); } } return $this->render('view', ['model' => $model, 'questions' => $questions]); }
public function questionSubscribe(Request $request, $id) { $question = Question::find($id); $message = []; if ($currentUser = \Auth::user()) { if ($question->subscribers->contains($currentUser)) { // $this->dispatch(new RemoveLikeFromAnswer($tag, \Auth::user())); $question->subscribers()->detach($currentUser); $message['type'] = 'unsubscribe'; } else { $question->subscribers()->attach($currentUser); $message['type'] = 'subscribe'; // $this->dispatch(new AddLikeToAnswer($tag, \Auth::user())); } } if ($request->ajax()) { $message['count'] = $question->subscribersCount; $message['title'] = count_subscribers($message['count']); return $message; } return back(); }
public static function checkQ() { $maxPub = Question::find()->max('publiced'); $tDay = 3600 * 24; // $maxPubNow = time() + $tDay * $maxPubNew = time() + Need::pro7gress('reserv') * $tDay; // User::per($maxPub, 'test', false); // User::per($maxPubNew, 'test', false); $cday = (int) round(($maxPubNew - $maxPub) / $tDay); // User::per($cday, 'cday', false); $res = Question::find()->where('npp=0')->orderBy('rand()')->limit($cday)->all(); // ->asArray() $count = 0; foreach ($res as $a) { $count++; $tmp = $maxPub + $tDay * $count; $a->publiced = $tmp; $maxNpp = Question::find()->max('npp'); $wday3 = Need::ua('wday3', getdate($tmp)['wday']); $a->user_take = Need::day2user($wday3); // User::per(User::day2user($wday3), 'wday3', false); $a->npp = $maxNpp + 1; $a->save(); // User::per($a->publiced, 'item: '.$a->id, false); } // User::per($res[0]->id, 'test', false); // die('--'); }
public function getDelete($id){ $question = Question::find($id); if(!$question){ App::abort(404); } if($question->user_id == $this->user->id){ $question->tegs()->detach();//удал¤ем св¤зи $question->delete(); return redirect('questions')->with('message','¬опрос удален'); }else{ return redirect('question/'.$id); } }
private function parseQuestions($text, $separator, $condition = "", &$qcount, $bank_id = null) { $data = explode($separator, trim($text)); $tmp = array(); foreach ($data as $val) { $entry = array(); $cmd = trim($val); $hidden = false; $aslist = false; $horizontal = false; if ($cmd != "") { switch ($cmd[0]) { case "#": $entry['cmd'] = "header"; $entry['text'] = substr($cmd, 1); $entry['condition'] = $condition; $tmp[] = $entry; break; case "@": $entry['cmd'] = "pagebreak"; $entry['condition'] = $condition; $tmp[] = $entry; break; case "w": $cond = array(); $stat = ""; for ($i = 4; $i < strlen($cmd); $i++) { if ($cmd[$i] == "(") { if ($stat == "condition") { $stat = "commands"; } else { $stat = "condition"; } } if ($cmd[$i] != "(" && $cmd[$i] != ")") { if (!isset($cond[$stat])) { $cond[$stat] = ''; } $cond[$stat] .= $cmd[$i]; } } $sub = $this->parseQuestions($cond['commands'], ",", $cond['condition'], $qcount); foreach ($sub as $entry) { $tmp[] = $entry; } break; case "H": case "L": case "N": $prefix = $cmd[0]; $cmd = substr($cmd, 1); if ($prefix == "H") { $hidden = true; } if ($prefix == "L") { $aslist = true; } if ($prefix == "N") { $horizontal = true; } default: $entry = Question::find()->where(['fr_id' => $cmd])->asArray()->one(); if (!$entry) { return 0; } //var_dump($entry); $entry['cmd'] = "question"; $entry['condition'] = $condition; $entry['pos'] = $qcount; if ($hidden) { $entry['hidden'] = true; } else { $entry['hidden'] = false; } if ($aslist) { $entry['aslist'] = true; } else { $entry['aslist'] = false; } if ($horizontal) { $entry['horizontal'] = true; } else { $entry['horizontal'] = false; } $qcount++; if (strpos($cmd, "!")) { $oal = explode("!", $cmd); $entry2 = Question::find()->where(['fr_id' => $oal[0]])->asArray()->one(); if (isset($entry2['frage'])) { $entry['frage'] = $entry2['frage']; $entry['dset'] = $oal[1]; } } if (strpos($cmd, "/")) { $al = explode("/", $cmd); $al = QuestionAlias::find()->where(['a_fr_id' => $al[0], 'al_id' => $al[1]])->asArray()->one(); if ($al) { $entry['frage'] = $al['alias']; } } //bank alias! if ($bank_id !== null) { $al = Alias::find()->where(['b_id' => $bank_id])->asArray()->all(); if (count($al)) { foreach ($al as $replacement) { $entry['frage'] = str_replace($replacement['original'], $replacement['alias'], $entry['frage']); } } } $tmp[] = $entry; break; } } } $data = $tmp; return $data; }
public function getAllQuestionBySurveyId($id) { return Question::find()->where(['Survey_id' => $id])->orderBy('order')->asArray()->all(); }
<div class="alert alert-success"> Thank you for contacting us. We will respond to you as soon as possible. </div> <?php } ?> <?php $form = ActiveForm::begin(['id' => 'test-form']); ?> <?php $dataProvider = new ActiveDataProvider(['query' => Question::find()->where(['id' => $q_ids]), 'pagination' => ['pageSize' => 25]]); echo ListView::widget(['dataProvider' => $dataProvider, 'itemView' => '_question']); ?> <div class="form-group"> <?php echo Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']); ?> </div> <?php ActiveForm::end(); ?>
public function saveAnswer(Request $request) { if ($request->input('is_test') != 1) { $applicant = Applicant::where('form_key', $request->input('form_key'))->first(); $blueprint = Blueprint::find($applicant->blueprint_id); $question = Question::find($request->input('question_id')); $answer = Answer::firstOrCreate(["blueprint_id" => $blueprint->id, "question_id" => $question->id, "form_key" => $applicant->form_key]); if ($question->type == "integer" || $question->type == "number") { $answer->num_value = $request->input('question_value'); $answer->text_value = null; } else { $answer->num_value = null; $answer->text_value = $request->input('question_value'); } $answer->update(); $answer->question_value = $request->input('question_value'); $answer->new_token = csrf_token(); } else { $question = Question::find($request->input('question_id')); $answer = new Answer(["blueprint_id" => $question->blueprint->id, "question_id" => $question->id, "form_key" => "xxx"]); $answer->num_value = $question->type == "number" ? $request->input('question_value') : null; $answer->text_value = $question->type != "number" ? $request->input('question_value') : null; $answer->question = $question; //$answer->update(); $answer->question_value = $request->input('question_value'); $answer->new_token = csrf_token(); } return response()->json($answer)->header('Access-Control-Allow-Origin', '*'); }
public function deleteQuestion($id) { $user = Auth::user(); $question = Question::find($id); $blueprint = $question->blueprint; Option::where("question_id", $question->id)->delete(); $remove_rule = Rule::where("blueprint_id", $blueprint->id)->where("question_id", $question->id)->delete(); $delete = $question->delete(); $response = ["remove_rule" => $remove_rule, "delete" => $delete]; return response()->json($response)->header('Access-Control-Allow-Origin', '*'); }
public function actionSearch() { $searchtext = $_POST['searchtext']; $questions = Question::find()->where(['like', 'description', $searchtext])->all(); return $this->render('search', ['questions' => $questions, 'searchtext' => $searchtext]); }
<?php /* @var $this yii\web\View */ use yii\helpers\Html; use app\models\Question; use yii\widgets\ListView; use yii\data\ActiveDataProvider; $this->title = 'Результаты поиска'; $this->params['breadcrumbs'][] = $this->title; ?> <h3>Результаты поиска по: <?php echo $searchtext; ?> </h3> <?php $dataProvider = new ActiveDataProvider(['query' => Question::find()->where(['like', 'description', $searchtext]), 'pagination' => ['pageSize' => 10]]); echo ListView::widget(['dataProvider' => $dataProvider, 'itemView' => '_searchlist', 'separator' => '<hr>']);
<?php echo $form->field($model, 'address')->textInput(['maxlength' => true, 'class' => 'form-control form-field-short']); ?> <?php echo $form->field($model, 'zip_code')->textInput(['maxlength' => true, 'class' => 'form-control form-field-short']); ?> <?php echo $form->field($model, 'state_id')->dropDownList(\app\enums\States::listData()); ?> <?php echo $form->field($model, 'question_id')->dropDownList(Question::find()->select(['text', 'id'])->indexBy('id')->column(), array('prompt' => ' - choose question - ')); ?> <?php echo $form->field($model, 'question_answer')->textInput(['maxlength' => true, 'class' => 'form-control form-field-short']); ?> </div> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? \Yii::t('app', 'Create') : \Yii::t('app', 'Save'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> <?php echo Html::a(\Yii::t('app', '<< All Users'), ['manage'], ['class' => 'btn btn-primary']);
<?php use app\models\Question; use app\models\Answer; $question = array_column(Question::find()->select(['id'])->asArray()->all(), 'id'); $answer = array_column(Answer::find()->select(['id'])->asArray()->all(), 'id'); $boolean = [0, 1]; return ['question_id' => $faker->randomElement($question), 'answer_id' => $faker->randomElement($answer), 'is_right' => $faker->randomElement($boolean)];
<h4>Fragen</h4> <?php echo \app\models\Question::find()->count(); ?> Fragen insgesamt, davon <br/> <?php echo \app\models\Question::find()->andFilterWhere(['display' => 'text'])->count(); ?> Textfragen<br/> <?php echo \app\models\Question::find()->andFilterWhere(['display' => 'radio'])->count(); ?> Auswahlfragen<br/> <?php echo \app\models\Question::find()->andFilterWhere(['display' => 'multi'])->count(); ?> Mehrfachauswahlfragen<br/> <h4>Banken</h4> <?php echo \app\models\Bank::find()->count(); ?> Banken insgesamt, in<br/> <?php echo \app\models\Bank::find()->distinct('klasse')->count(); ?> verschiedenen Bankenklassen<br/>
/** * Lists all Question models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Question::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
private function getQuestion() { $session = Yii::$app->session; $answered = $session['test']['answered']; if ($answered == null) { $answered = 0; } if (!isset($session['test']['actual_question'])) { $question = Question::find()->joinWith('answers')->where(['question.active' => 1])->andWhere(['NOT IN', 'question.id', explode(',', $answered)])->orderBy('RAND()')->one(); $_SESSION['test']['actual_question'] = $question->id; } else { $question = Question::find()->joinWith('answers')->where(['question.active' => 1])->andWhere(['question.id' => $session['test']['actual_question']])->one(); } return $question; }