public function index() { $user = Auth::user(); $blueprints = $user->level == 3 ? Blueprint::with("applicants")->where("is_closed", 0)->where("is_visible", 1)->get() : Blueprint::with("applicants")->where("user_id", $user->id)->where("is_closed", 0)->where("is_visible", 1)->get(); $data['title'] = 'Encuestas por aplicar Tú Evalúas'; $data['description'] = ''; $data['body_class'] = 'applicants'; $data['user'] = $user; $data['blueprints'] = $blueprints; $data['status'] = session('status'); return view("applicants")->with($data); }
public function show($id) { $user = Auth::user(); $blueprint = $user->level == 3 ? Blueprint::with(["questions.options", "rules"])->find($id) : Blueprint::with(["questions.options", "rules"])->where("user_id", $user->id)->find($id); if (!$blueprint) { die("Este formulario no existe!"); } $data = []; $data['applicant'] = $user; $data['blueprint'] = $blueprint; $data['questions'] = $blueprint->questions; $data['rules'] = $blueprint->rules; $data['options'] = $blueprint->options; $data['answers'] = []; $data['is_test'] = true; return view("test-form")->with($data); }
function result($id) { $blueprint = Blueprint::with(["questions.options"])->find($id); $test = function ($question_type, $inegi_key) { if (!$inegi_key) { return "-"; } switch ($question_type) { case "location-a": $key = substr($inegi_key->text_value, 0, 2); $name = !empty($key) ? $this->states[$key] : "-"; break; case "location-b": $state_key = substr($inegi_key->text_value, 0, 2); $state_name = !empty($state_key) ? $this->states[$state_key] : "-"; $city_key = substr($inegi_key->text_value, 2, 3); $city = !empty($city_key) ? City::where("clave", $city_key)->where("estado_id", (int) $state_key)->first() : null; $city_name = $city ? $city->nombre : "-"; $name = $city_name . ", " . $state_name; break; case "location-c": $state_key = substr($inegi_key->text_value, 0, 2); $state_name = !empty((int) $state_key) ? $this->states[$state_key] : "-"; $city_key = substr($inegi_key->text_value, 2, 3); $city = !empty($city_key) ? City::where("clave", $city_key)->where("estado_id", (int) $state_key)->first() : null; $city_name = $city ? $city->nombre : "-"; $location_key = substr($inegi_key->text_value, 5, 4); $location = !empty((int) $location_key) ? Location::where("clave", $location_key)->where("municipio_id", $city->id)->first() : null; $location_name = $location ? $location->nombre : "-"; $name = $location_name . ", " . $city_name . ", " . $state_name; break; default: $name = "-"; break; } return $name; }; if (!$blueprint) { die("Este formulario no existe!"); } $data = []; $data['blueprint'] = $blueprint; $data['title'] = 'Resultados | Tú Evalúas'; $data['description'] = 'Resultados de cuestionarios en Tú Evalúas'; $data['body_class'] = 'results'; $data['test'] = $test; return view("frontend.result_survey")->with($data); }
/** * Execute the console command. * * @return mixed */ public function handle() { $id = $this->argument('blueprint'); $type = $this->argument('type'); $full = (int) $this->argument('full'); /// $type, public_path('csv') $path = $full ? storage_path('app') : public_path('csv'); $user = Auth::user(); $blueprint = Blueprint::with("questions.options")->find($id); $title = $this->sluggable($blueprint->title); Excel::create($title, function ($excel) use($blueprint, $full) { // Set the title $excel->setTitle($blueprint->title); // Chain the setters $excel->setCreator('Tú Evalúas'); //->setCompany('Transpar'); // Call them separately $excel->setDescription("Resultado desagregados"); // add a sheet for each day, and set the date as the name of the sheet $excel->sheet("encuestas", function ($sheet) use($blueprint, $full) { //var_dump($titles->toArray()); $questions = $blueprint->questions; $titles = $questions->pluck("question"); $titles = $titles->toArray(); array_unshift($titles, "id"); $sheet->appendRow($titles); $applicants = $blueprint->applicants()->has("answers")->with("answers")->get(); foreach ($applicants as $applicant) { $row = []; $row[] = $applicant->id; foreach ($questions as $question) { if ($question->is_description) { $row[] = "es descripción"; } elseif (in_array($question->type, ['location-a', 'location-b', 'location-c'])) { $inegi_key = $applicant->answers()->where("question_id", $question->id)->get()->first(); $row[] = $this->find_location($question->type, $inegi_key); } elseif ($question->type == "multiple-multiple") { $open_answer = $applicant->answers()->where("question_id", $question->id)->get()->first(); if ($open_answer && !empty($open_answer->text_value)) { $r = Option::whereIn("value", explode(",", $open_answer->text_value))->where("blueprint_id", $blueprint->id)->where("question_id", $question->id)->lists('description')->toArray(); $row[] = implode(",", $r); } else { $row[] = "no contestó"; } } elseif (in_array($question->type, ['text', 'multiple'])) { $open_answer = $applicant->answers()->where("question_id", $question->id)->get()->first(); //->text_value; $row[] = $open_answer ? $open_answer->text_value : "no contestó"; } elseif ($question->type == "personal") { $open_answer = $applicant->answers()->where("question_id", $question->id)->get()->first(); //->text_value; $row[] = $open_answer && $full ? $open_answer->text_value : ""; } else { $num_value = $applicant->answers()->where("question_id", $question->id)->get()->first(); //->text_value; $row[] = $num_value ? $num_value->num_value : "-"; } } $sheet->appendRow($row); } }); })->store($type, $path); $blueprint->csv_file = $title; $blueprint->update(); $this->info('El archivo se guardó!'); }