Sindbad~EG File Manager
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Competencia;
use App\Models\Interrogante;
use Livewire\WithPagination;
class Interrogantes extends Component{
use WithPagination;
protected $queryString = ['buscar' => ['except' => '']];
protected $paginationTheme = 'bootstrap';
public $buscar='';
public $int_nom, $int_tipo, $interrogante_id, $competencia_id,$ubicacion,$grafico;
public $updateMode = false;
public function render(){
$competencia = Competencia::where('id',$this->competencia_id)->first();
$interrogantes=Interrogante::where('int_nom','LIKE',"%{$this->buscar}%")->where('competencia_id',$competencia->id)->where('int_estado',1)->orderBy('int_ubicacion','asc')->paginate(12);
return view('livewire.interrogantes.index',["competencia" => $competencia, "interrogantes" => $interrogantes]);
}
private function resetInputFields(){
$this->int_nom = '';
$this->int_tipo = '';
$this->grafico = '';
}
public function store(){
$validatedDate = $this->validate([
'int_nom' => 'required',
'int_tipo' => 'required',
'competencia_id' => 'required',
]);
$ultimainterrogante = Interrogante::where('competencia_id',$this->competencia_id)->orderBy('id','desc')->first();
if( $ultimainterrogante == NULL ) {
$this->ubicacion = 1;
}else{
$this->ubicacion=$ultimainterrogante->int_ubicacion+1;
}
Interrogante::create([
'int_nom' => $this->int_nom,
'int_tipo' => $this->int_tipo,
'int_ubicacion' => $this->ubicacion,
'grafico' => $this->grafico,
'competencia_id' => $this->competencia_id,
]);
$this->emit('alert', ['type' => 'success', 'message' => 'Interrogante creada correctamente.']);
$this->resetInputFields();
}
public function edit($id)
{
$this->updateMode = true;
$interrogante = Interrogante::where('id',$id)->first();
$this->interrogante_id = $id;
$this->int_nom = $interrogante->int_nom;
$this->int_tipo = $interrogante->int_tipo;
$this->grafico = $interrogante->grafico;
}
public function subir($posicion){
$prox_posicion=intval($posicion)-1;
$acceso_posicion=Interrogante::where('competencia_id',$this->competencia_id)->where('int_ubicacion',$posicion)->first();
$acceso_prox_posicion=Interrogante::where('competencia_id',$this->competencia_id)->where('int_ubicacion',$prox_posicion)->first();
$id=$acceso_posicion->id;
$interrogante = Interrogante::find($id);
$interrogante->update([
'int_ubicacion' => $prox_posicion,
]);
$id=$acceso_prox_posicion->id;
$interrogante = Interrogante::find($id);
$interrogante->update([
'int_ubicacion' => $posicion,
]);
}
public function bajar($posicion){
$prox_posicion=intval($posicion)+1;
$acceso_posicion=Interrogante::where('competencia_id',$this->competencia_id)->where('int_ubicacion',$posicion)->first();
$acceso_prox_posicion=Interrogante::where('competencia_id',$this->competencia_id)->where('int_ubicacion',$prox_posicion)->first();
$id=$acceso_posicion->id;
$interrogante = Interrogante::find($id);
$interrogante->update([
'int_ubicacion' => $prox_posicion,
]);
$id=$acceso_prox_posicion->id;
$interrogante = Interrogante::find($id);
$interrogante->update([
'int_ubicacion' => $posicion,
]);
}
public function cancel()
{
$this->updateMode = false;
$this->resetInputFields();
}
public function update()
{
$validatedDate = $this->validate([
'int_nom' => 'required',
'int_tipo' => 'required',
'interrogante_id' => 'required',
]);
if ($this->interrogante_id) {
$interrogante = Interrogante::find($this->interrogante_id);
$interrogante->update([
'int_nom' => $this->int_nom,
'int_tipo' => $this->int_tipo,
'grafico' => $this->grafico,
]);
$this->updateMode = false;
$this->emit('alert', ['type' => 'info', 'message' => 'interrogante actualizada correctamente.']);
$this->resetInputFields();
}
}
public function delete($id)
{
if($id){
$interrogante = Interrogante::find($id);
$interrogante->update([
'int_estado' => 0,
]);
$this->emit('alert', ['type' => 'error', 'message' => '¡Interrogante eliminada correctamente.!']);
}
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists