File: /var/www/html/xfacil.desafio.com.py/app/Http/Livewire/Frontcurso.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Curso;
use App\Models\Importanciacurso;
use App\Models\Alcancecurso;
use App\Models\Objetivocurso;
use App\Models\Tutorcurso;
use App\Models\Recursocurso;
use App\Models\Reflexioncurso;
use App\Models\Formulario;
use App\Models\Podcastcurso;
use App\Models\Capsulacurso;
use App\Models\Emoticon;
use App\Models\Apunte;
use App\Models\Puntaje;
use Auth;
use DB;
class Frontcurso extends Component{
public $curso_id,$importancia,$alcance,$objetivo,$capsula,$tutor,$recurso,$apuntes,$reflexion,$podcast,$apunte,$apunteid,$respuestas,$feed,$capsula_id,$emocion='';
public function render(){
$curso = Curso::find($this->curso_id);
$capsulas = Capsulacurso::where('curso_id',$this->curso_id)->get();
$apuntess = Apunte::where('curso_id',$this->curso_id)->where('usuario_id',Auth::user()->id)->get();
return view('livewire.frontcurso',["curso"=>$curso,"capsulas"=>$capsulas,"apuntess"=>$apuntess]);
}
private function resetInputFields(){
$this->importancia = '';
$this->alcance = '';
$this->objetivo = '';
$this->capsula = '';
$this->tutor = '';
$this->recurso = '';
$this->apuntes = '';
$this->reflexion = '';
$this->podcast = '';
}
public function importancia(){
$this->resetInputFields();
$importancia=Importanciacurso::where('curso_id',$this->curso_id)->first();
$this->importancia = $importancia->importancia;
}
public function alcance(){
$this->resetInputFields();
$alcance=Alcancecurso::where('curso_id',$this->curso_id)->first();
$this->alcance = $alcance->alcance;
}
public function objetivo(){
$this->resetInputFields();
$objetivo=Objetivocurso::where('curso_id',$this->curso_id)->first();
$this->objetivo = $objetivo->objetivo;
}
public function capsula(){
$this->resetInputFields();
$capsula=Capsulacurso::where('curso_id',$this->curso_id)->first();
$this->capsula = $capsula->capsula;
$this->emit('apunte', $this->apunte);
}
public function tutor(){
$this->resetInputFields();
$tutor=Tutorcurso::where('curso_id',$this->curso_id)->first();
$this->tutor = $tutor->tutor;
}
public function recurso(){
$this->resetInputFields();
$recurso=Recursocurso::where('curso_id',$this->curso_id)->first();
$this->recurso = $recurso->recurso;
}
public function apuntes(){
$this->resetInputFields();
$this->apuntes = "apuntes";
$this->emit('apunte', $this->apunte);
}
public function reflexion(){
$this->resetInputFields();
$reflexion = Formulario::where('for_estado',1)->where('curso_id',$this->curso_id)->get();
$this->respuestas = DB::table('respuestas as re')
->join('interrogantes as in','re.interrogante_id','in.id')
->join('competencias as co','in.competencia_id','co.id')
->join('formularios as fo','co.formulario_id','fo.id')
->where('fo.curso_id',$this->curso_id)
->where('re.usuario_id',Auth::user()->id)
->select('fo.id')->get();
$this->feed=Puntaje::where('usuario_id',Auth::user()->id)->get();
$this->reflexion = $reflexion;
}
public function podcast(){
$this->resetInputFields();
$podcast=Podcastcurso::where('curso_id',$this->curso_id)->first();
$this->podcast = $podcast->podcast;
}
public function addemocion($capsula_id,$emocion,$estado){
if($emociondelete = Emoticon::where('usuario_id', Auth::user()->id)->where('capsula_id',$capsula_id)->first()){
$emociondelete->delete();
}
if($estado != $emocion){
Emoticon::create([
'usuario_id' => Auth::user()->id,
'capsula_id' => $capsula_id,
'emocion' => $emocion,
'curso_id' => $this->curso_id,
]);
}
}
public function guardarnota(){
$validatedDate = $this->validate([
'apunte' => 'required',
],
[
'apunte.required' => 'El campo apunte es requerido',
]);
Apunte::create([
'usuario_id' => Auth::user()->id,
'apunte' => $this->apunte,
'curso_id' => $this->curso_id,
]);
session()->flash('success', 'Apunte agregado correctamente!');
$this->emit('apunte', '');
}
public function editapunte($id){
$apunte2=Apunte::find($id);
$this->apunteid = $id;
$this->emit('apunte', $apunte2->apunte);
}
public function updatenota($id){
$apunte2=Apunte::find($id);
$apunte2->update([
'apunte' => $this->apunte,
]);
$this->apunteid = '';
$this->emit('apunte', '');
}
public function deleteapunte($id){
$apunte2=Apunte::find($id);
$apunte2->delete();
}
public function envioid($id){
$this->capsula_id=$id;
}
}