/**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $assistent = Assistent::find($id);
     if ($this->getRouter()->getCurrentRoute()->getPrefix() == '/api') {
         // Si no existe ese assistent devolvemos un error.
         if (!$assistent) {
             // Se devuelve un array errors con los errores encontrados y cabecera HTTP 404.
             // En code podríamos indicar un código de error personalizado de nuestra aplicación si lo deseamos.
             return response()->json(['errors' => array(['code' => 404, 'message' => 'No se encuentra un assistent con ese código.'])], 404);
         }
         return response()->json(['status' => 'ok', 'data' => $assistent], 200);
     } else {
         if (!Auth::check()) {
             return Redirect::to('login');
         }
         $assistents = Assistent::where('usuari', '=', $assistent->usuari)->paginate(5);
         foreach ($assistents as $ass) {
             $ass->esd = $ass->esdeveniment()->select('titol', 'id')->first();
             $votacions = $ass->votacions()->get();
             $aux = array();
             foreach ($votacions as $vota) {
                 array_push($aux, $vota->votacio()->select('titol', 'id')->first());
             }
             $ass->vota = $aux;
         }
         return view('assistentLayouts.show')->with("ass", $assistents)->with("usuari", $assistent->usuari);
     }
 }
 public function respostesAssistents($idVotacio, $idAssistent)
 {
     $assistent = Assistent::find($idAssistent);
     $respostes = Resposta::where('usuari_id', '=', $assistent->usuari)->where('votacio_id', '=', $idVotacio)->get();
     $votacio = Votacio::find($idVotacio);
     //$result = array('votacio'=>$votacio->titol);
     //$result = array_add($result,'usuari',$assistent->usuari);
     //$i = 1;
     //$pregResp = Array();
     if ($respostes->count() == $votacio->preguntes()->count()) {
         $total = true;
     } else {
         $total = false;
     }
     foreach ($respostes as $res) {
         $pregunta = Pregunta::find($res->pregunta_id);
         $res->pregunta = $pregunta->titol;
         //$pregResp = array_add($pregResp,'pregunta'.$i,$res->resposta);
         //$pregResp = array_add($pregResp,'resposta'.$i,$res->resposta);
         //++$i;
     }
     //$result = array_add($result,'pregResp',$pregResp);
     return view('respostaLayouts.show')->with("result", $respostes)->with("votacio", $votacio->titol)->with("usuari", $assistent->usuari)->with("total", $total)->with("idAssistent", $idAssistent)->with("idVotacio", $idVotacio)->with("idEsdeveniment", $assistent->esdeveniment_id);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($idEsdeveniment, $idAssistent)
 {
     $assistent = Assistent::find($idAssistent);
     $votaAss = $assistent->votacions()->select('votacio_id')->get();
     $a = collect([]);
     $b = collect([]);
     foreach ($votaAss as $v) {
         $a->push($v->votacio_id);
     }
     $votacions = Esdeveniment::find($assistent->esdeveniment_id)->votacions()->get();
     foreach ($votacions as $v) {
         $b->push($v->id);
     }
     $diff = $b->diff($a);
     $arrayVota = [];
     $i = 1;
     foreach ($diff as $vota) {
         $votac = Votacio::find($vota);
         $arrayVota = array_add($arrayVota, $i, $votac->titol);
         ++$i;
     }
     return view('assistentLayouts.edit')->with("ass", $assistent)->with("vota", $arrayVota);
 }
Beispiel #4
0
 public function postAssistentsVotacio()
 {
     $array = Request::input('ass');
     if ($array) {
         foreach ($array as $ass) {
             $id = Assistent::where('usuari', "=", $ass)->select('id')->first();
             $voAs = VotacioAssistent::where('assistent_id', "=", $id->id)->where('votacio_id', '=', Request::input('id'))->get();
             if ($voAs->isEmpty()) {
                 $result = array('assistent_id' => $id->id);
                 $result = array_add($result, 'votacio_id', Request::input('id'));
                 $novaVoAs = VotacioAssistent::create($result);
             }
         }
     }
 }