Modificación del de vista de dopcumentos del alumno
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\Tarea;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class EntregaController extends Controller
|
||||
{
|
||||
@@ -25,12 +26,23 @@ class EntregaController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
$cicloActual = Campan::where('status', 1)->first();
|
||||
// Ciclo más alto del alumno = semestre en curso
|
||||
$maxCiclo = DB::table('alumno_grupo')
|
||||
->join('grupos', 'grupos.id', '=', 'alumno_grupo.grupo_id')
|
||||
->where('alumno_grupo.alumno_id', $alumno->id)
|
||||
->max('grupos.ciclo');
|
||||
|
||||
// Solo grupos del ciclo activo
|
||||
$gruposActuales = $alumno->grupos()
|
||||
->when($cicloActual, fn($q) => $q->where('ciclo', $cicloActual->id))
|
||||
->pluck('grupos.id');
|
||||
// Campan para mostrar el nombre en la vista (busca por id = ciclo, o cae al activo)
|
||||
$cicloActual = $maxCiclo ? Campan::find($maxCiclo) ?? Campan::where('status', 1)->first() : null;
|
||||
|
||||
// Grupos del alumno en ese ciclo
|
||||
$gruposActuales = $maxCiclo
|
||||
? DB::table('alumno_grupo')
|
||||
->join('grupos', 'grupos.id', '=', 'alumno_grupo.grupo_id')
|
||||
->where('alumno_grupo.alumno_id', $alumno->id)
|
||||
->where('grupos.ciclo', $maxCiclo)
|
||||
->pluck('alumno_grupo.grupo_id')
|
||||
: collect();
|
||||
|
||||
$todasTareas = Tarea::whereIn('grupo_id', $gruposActuales)
|
||||
->with(['material', 'grupo'])
|
||||
@@ -59,15 +71,21 @@ class EntregaController extends Controller
|
||||
public function store(Request $request, Tarea $tarea)
|
||||
{
|
||||
$request->validate([
|
||||
'archivo' => 'nullable|file|max:20480',
|
||||
'archivo' => 'nullable|file|max:2048',
|
||||
'texto' => 'nullable|string|max:5000',
|
||||
]);
|
||||
|
||||
if (!$request->hasFile('archivo') && !filled($request->texto)) {
|
||||
return back()->withErrors(['entrega' => 'Debes escribir un texto o adjuntar un archivo.']);
|
||||
return redirect()->route('mis.tareas')
|
||||
->withErrors(['entrega' => 'Debes escribir un texto o adjuntar un archivo.']);
|
||||
}
|
||||
|
||||
$alumno = Alumno::whereHas('alumnos', fn($q) => $q->where('id', Auth::id()))->firstOrFail();
|
||||
$alumno = Alumno::whereHas('alumnos', fn($q) => $q->where('id', Auth::id()))->first();
|
||||
|
||||
if (!$alumno) {
|
||||
return redirect()->route('mis.tareas')
|
||||
->with('error', 'No se encontró un perfil de alumno para tu cuenta.');
|
||||
}
|
||||
|
||||
$entrega = Entrega::where('tarea_id', $tarea->id)
|
||||
->where('alumno_id', $alumno->id)
|
||||
@@ -82,12 +100,12 @@ class EntregaController extends Controller
|
||||
}
|
||||
|
||||
if ($entrega->status !== 'sin_subir') {
|
||||
return back()->with('error', 'Ya entregaste esta tarea y no puedes volver a subirla.');
|
||||
return redirect()->route('mis.tareas')
|
||||
->with('error', 'Ya entregaste esta tarea y no puedes volver a subirla.');
|
||||
}
|
||||
|
||||
$path = null;
|
||||
$path = $entrega->archivo;
|
||||
if ($request->hasFile('archivo')) {
|
||||
// Almacena en disco local (privado) igual que el FileController espera
|
||||
$path = $request->file('archivo')->store("entregas/{$tarea->id}");
|
||||
}
|
||||
|
||||
@@ -97,6 +115,7 @@ class EntregaController extends Controller
|
||||
'status' => 'pendiente',
|
||||
]);
|
||||
|
||||
return back()->with('info', 'Tarea enviada correctamente. Queda pendiente de calificación.');
|
||||
return redirect()->route('mis.tareas')
|
||||
->with('info', 'Tarea enviada correctamente. Queda pendiente de calificación.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user