archivo de configuracion de nginx agregado para el puerto 9000
This commit is contained in:
@@ -2,63 +2,148 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Alumno;
|
||||
use App\Models\Docente;
|
||||
use App\Models\Entrega;
|
||||
use App\Models\Grupo;
|
||||
use App\Models\Material;
|
||||
use App\Models\Tarea;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class TareaController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
public function index(Grupo $grupo, Material $material)
|
||||
{
|
||||
//
|
||||
$tareas = Tarea::where('grupo_id', $grupo->id)
|
||||
->where('material_id', $material->id)
|
||||
->withCount([
|
||||
'entregas',
|
||||
'entregas as pendientes_count' => fn($q) => $q->where('status', 'pendiente'),
|
||||
'entregas as calificadas_count' => fn($q) => $q->where('status', 'calificada'),
|
||||
])
|
||||
->orderByDesc('created_at')
|
||||
->get();
|
||||
|
||||
return view('tarea.index', compact('grupo', 'material', 'tareas'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
public function create(Grupo $grupo, Material $material)
|
||||
{
|
||||
//
|
||||
return view('tarea.create', compact('grupo', 'material'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(Request $request, Grupo $grupo, Material $material)
|
||||
{
|
||||
//
|
||||
$request->validate([
|
||||
'titulo' => 'required|string|max:255',
|
||||
'descripcion' => 'nullable|string',
|
||||
'fecha_entrega' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$docente = Docente::whereHas('docentes', fn($q) => $q->where('id', Auth::id()))->firstOrFail();
|
||||
|
||||
$tarea = Tarea::create([
|
||||
'titulo' => $request->titulo,
|
||||
'descripcion' => $request->descripcion,
|
||||
'fecha_entrega' => $request->fecha_entrega,
|
||||
'material_id' => $material->id,
|
||||
'grupo_id' => $grupo->id,
|
||||
'docente_id' => $docente->id,
|
||||
]);
|
||||
|
||||
foreach ($grupo->alumnos as $alumno) {
|
||||
Entrega::create([
|
||||
'tarea_id' => $tarea->id,
|
||||
'alumno_id' => $alumno->id,
|
||||
'status' => 'sin_subir',
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('grupo.material.tareas', [$grupo, $material])
|
||||
->with('info', 'Tarea creada correctamente.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
public function show(Grupo $grupo, Material $material, Tarea $tarea)
|
||||
{
|
||||
//
|
||||
$alumnos = $grupo->alumnos()->with('alumnos')->get();
|
||||
|
||||
$entregasExistentes = Entrega::where('tarea_id', $tarea->id)->pluck('alumno_id')->toArray();
|
||||
|
||||
foreach ($alumnos as $alumno) {
|
||||
if (!in_array($alumno->id, $entregasExistentes)) {
|
||||
Entrega::create([
|
||||
'tarea_id' => $tarea->id,
|
||||
'alumno_id' => $alumno->id,
|
||||
'status' => 'sin_subir',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$entregas = Entrega::where('tarea_id', $tarea->id)
|
||||
->with('alumno.alumnos')
|
||||
->get()
|
||||
->keyBy('alumno_id');
|
||||
|
||||
return view('tarea.show', compact('grupo', 'material', 'tarea', 'alumnos', 'entregas'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
public function edit(Grupo $grupo, Material $material, Tarea $tarea)
|
||||
{
|
||||
//
|
||||
return view('tarea.create', compact('grupo', 'material', 'tarea'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
public function update(Request $request, Grupo $grupo, Material $material, Tarea $tarea)
|
||||
{
|
||||
//
|
||||
$request->validate([
|
||||
'titulo' => 'required|string|max:255',
|
||||
'descripcion' => 'nullable|string',
|
||||
'fecha_entrega' => 'nullable|date',
|
||||
]);
|
||||
|
||||
$tarea->update([
|
||||
'titulo' => $request->titulo,
|
||||
'descripcion' => $request->descripcion,
|
||||
'fecha_entrega' => $request->fecha_entrega,
|
||||
]);
|
||||
|
||||
return redirect()->route('grupo.material.tareas', [$grupo, $material])
|
||||
->with('info', 'Tarea actualizada correctamente.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
public function destroy(Grupo $grupo, Material $material, Tarea $tarea)
|
||||
{
|
||||
//
|
||||
// Borrar archivos físicos de cada entrega antes de eliminar los registros
|
||||
$tarea->entregas()
|
||||
->whereNotNull('archivo')
|
||||
->pluck('archivo')
|
||||
->each(fn($path) => Storage::delete($path));
|
||||
|
||||
$tarea->delete(); // las entregas se eliminan en cascada por FK
|
||||
|
||||
return redirect()->route('grupo.material.tareas', [$grupo, $material])
|
||||
->with('info', 'Tarea eliminada.');
|
||||
}
|
||||
|
||||
public function calificar(Request $request, Tarea $tarea, Alumno $alumno)
|
||||
{
|
||||
$request->validate([
|
||||
'calificacion' => 'required|numeric|min:0|max:10',
|
||||
'comentario' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$entrega = Entrega::where('tarea_id', $tarea->id)
|
||||
->where('alumno_id', $alumno->id)
|
||||
->firstOrFail();
|
||||
|
||||
$entrega->update([
|
||||
'calificacion' => $request->calificacion,
|
||||
'comentario' => $request->comentario,
|
||||
'status' => 'calificada',
|
||||
]);
|
||||
|
||||
return back()->with('info', 'Calificación guardada.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user