public function show($id){
try{
$s = '';
$question = Question::findOrFail($id);
if(empty($this->user) or $question->user_id != $this->user->id){
\DB::table('yiiquestions')->increment('views');//счетчик просмотров
}else{
$s = Subscribe::where('question_id', '=', $question->id)->where('user_id', '=', $this->user->id)->get();
}
return view('questions.show',[
'question' => $question,
's' => $s,
'answers' => Answer::where('question_id','=',$question->id)->with('user')->get()
]);
}catch(ModelNotFoundException $e){
return view('errors.404');
}
}
Esempio n. 2
0
 public function displayForm($form_key = null)
 {
     // [0] sin clave, reenvía a resultados
     if (!$form_key) {
         return redirect('resultados');
     }
     // [1] obtiene los datos para armar la encuesta
     $user = Auth::user();
     $applicant = Applicant::where("form_key", $form_key)->first();
     $blueprint = $applicant->blueprint;
     $is_admin = (bool) $user;
     // [2] si la encuestas es visible y ha terminado, revisa los datos
     if ($blueprint->is_closed && $bluprint->is_visible) {
         return redirect('resultado/' . $blueprint->id);
     }
     // [3] Es posible que el usuario lo vea estando oculto, si está identificado.
     //     Si no, regresa a la página de resultados
     if ($blueprint->is_visible == 0 && !$is_admin) {
         return redirect('resultados');
     }
     $data = [];
     $data['applicant'] = $applicant;
     $data['blueprint'] = $blueprint;
     $data['questions'] = $blueprint->questions;
     $data['rules'] = $blueprint->rules;
     $data['options'] = $blueprint->options;
     $data['answers'] = Answer::where("form_key", $form_key)->get();
     $data['is_test'] = false;
     $data['is_admin'] = $is_admin;
     return view("real-form")->with($data);
 }
Esempio n. 3
0
 /**
  * @return mixed
  */
 public function getTrue($questionId)
 {
     return Answer::where('correct', 1)->where('question_id', $questionId)->first();
 }