diff --git a/app/Http/Controllers/DocenteController.php b/app/Http/Controllers/DocenteController.php index d79aa2be..8fdcb1ab 100644 --- a/app/Http/Controllers/DocenteController.php +++ b/app/Http/Controllers/DocenteController.php @@ -2,7 +2,15 @@ namespace App\Http\Controllers; +use App\Models\Docente; +use App\Models\Role; +use App\Models\User; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Password; +use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Str; +use Illuminate\Auth\Notifications\ResetPassword; class DocenteController extends Controller { @@ -11,7 +19,19 @@ class DocenteController extends Controller */ public function index() { - // + + $user = Auth::user(); + $plantelesIds = $user->plantelUsuarios->pluck('id'); + + $docentes = Docente::with(['docentes.plantelUsuarios', 'docentes.roles']) + ->whereHas('docentes', function($query) use ($plantelesIds) { + $query->whereHas('plantelUsuarios', function($q) use ($plantelesIds) { + $q->whereIn('plantels.id', $plantelesIds); + }); + }) + ->get(); + + return view('Docente.index', compact('docentes')); } /** @@ -19,7 +39,10 @@ class DocenteController extends Controller */ public function create() { - // + $user = Auth::user(); + $roles = Role::where('name','Docente')->get(); + $plantels = $user->plantelUsuarios; + return view('Docente.create',compact(['plantels','roles'])); } /** @@ -27,7 +50,49 @@ class DocenteController extends Controller */ public function store(Request $request) { - // + if (User::where('email', $request->email) + ->orWhere('telefono', $request->telefono) + ->exists()) { + + return redirect()->route('docente.create')->with('warn','Ya se encuentra registrado el número de teléfono o correo electrónico, porfavor cambialos')->withInput(); + } + + if ($request->plantel ==0) { + return redirect()->route('docente.create')->with('warn','Selecciona el campus')->withInput(); + } + + if ($request->rol ==0) { + return redirect()->route('docente.create')->with('warn','Selecciona el rol')->withInput(); + } + + $passwordTemporal = Str::random(12); + + $user = User::create([ + 'name' => mb_strtoupper($request->name, 'UTF-8'), + 'apellidoPaterno' => mb_strtoupper($request->apellidoPaterno, 'UTF-8'), + 'apellidoMaterno' => mb_strtoupper($request->apellidoMaterno, 'UTF-8'), + 'email' => $request->email, + 'telefono' => $request->telefono, + 'direccion' => $request->direccion, + 'password' => Hash::make($passwordTemporal), + 'status' => $request->status + ]); + + $user->roles()->sync($request->rol); + $user->plantelUsuarios()->sync([$request->plantel]); + + $token = Password::createToken($user); + $user->notify(new ResetPassword($token)); + + $docente = Docente::create([ + 'usuario_registro' => Auth::id(), + 'status' => $request->status, + ]); + + $docente->docentes()->sync([$user->id]); + + return redirect()->route('docente.edit',compact('docente'))->with('info','Se creó el docente correctamente'); + } /** @@ -41,9 +106,14 @@ class DocenteController extends Controller /** * Show the form for editing the specified resource. */ - public function edit(string $id) + public function edit(Docente $docente) { - // + $user = Auth::user(); + $roles = Role::where('name', 'Docente')->get(); + $plantels = $user->plantelUsuarios; + $usr = $docente->docentes->first(); + + return view('Docente.edit', compact(['docente', 'plantels', 'roles', 'usr'])); } /** @@ -57,8 +127,28 @@ class DocenteController extends Controller /** * Remove the specified resource from storage. */ - public function destroy(string $id) + public function destroy(Docente $docente) { - // + $user = $docente->docentes->first(); + + $docente->grupos()->detach(); + + $docente->docentes()->detach(); + + $docente->delete(); + + if ($user) { + $user->roles()->detach(); + $user->plantelUsuarios()->detach(); + $user->delete(); + } + + session()->flash('swal', [ + 'icon' => 'success', + 'title' => 'Eliminado!', + 'text' => 'Se ha eliminado el registro correctamente' + ]); + + return redirect()->route('docente.index'); } } diff --git a/app/Http/Controllers/DocumentoTipoController.php b/app/Http/Controllers/DocumentoTipoController.php index 6402e5c4..f3df7df0 100644 --- a/app/Http/Controllers/DocumentoTipoController.php +++ b/app/Http/Controllers/DocumentoTipoController.php @@ -2,12 +2,12 @@ namespace App\Http\Controllers; -use App\Models\DocumentoTipo; +use App\Models\documentoTipo; use App\Models\Nivel; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -class DocumentoTipoController extends Controller +class documentoTipoController extends Controller { public function __construct() { $this->middleware('can:documentoTipo.index')->only('index','show'); @@ -18,8 +18,8 @@ class DocumentoTipoController extends Controller public function index() { - $documentotipos=DocumentoTipo::all(); - return view('documento.index',compact('documentotipos')); + $documentoTipos=documentoTipo::all(); + return view('documento.index',compact('documentoTipos')); } @@ -40,15 +40,15 @@ class DocumentoTipoController extends Controller 'extensiones' => 'required|array' ]); - $documentotipo=DocumentoTipo::create([ + $documentoTipo=documentoTipo::create([ 'name' => $request->name, 'slug' => $request->slug, 'extensiones' => $request->extensiones ]); - $documentotipo->niveles()->sync($request->nivels ?? []); + $documentoTipo->niveles()->sync($request->nivels ?? []); - return redirect()->route('documentotipo.edit',compact('documentotipo'))->with('info','Se creó la la documentación correctamente'); + return redirect()->route('documentoTipo.edit',compact('documentoTipo'))->with('info','Se creó la la documentación correctamente'); } /** @@ -62,42 +62,42 @@ class DocumentoTipoController extends Controller /** * Show the form for editing the specified resource. */ - public function edit(DocumentoTipo $documentotipo) + public function edit(documentoTipo $documentoTipo) { - $documentotipo->load('niveles'); + $documentoTipo->load('niveles'); $nivels = Nivel::where('status','=','1')->get(); - return view('documento.edit',compact(['documentotipo','nivels'])); + return view('documento.edit',compact(['documentoTipo','nivels'])); } /** * Update the specified resource in storage. */ - public function update(Request $request, DocumentoTipo $documentotipo) + public function update(Request $request, documentoTipo $documentoTipo) { - $documentotipo->update([ + $documentoTipo->update([ 'name' => $request->name, 'slug' => $request->slug, 'extensiones' => $request->extensiones ]); - $documentotipo->niveles()->sync($request->nivels ?? []); + $documentoTipo->niveles()->sync($request->nivels ?? []); - return redirect()->route('documentotipo.edit',compact('documentotipo'))->with('info','Se modificó la la documentación correctamente'); + return redirect()->route('documentoTipo.edit',compact('documentoTipo'))->with('info','Se modificó la la documentación correctamente'); } /** * Remove the specified resource from storage. */ - public function destroy(DocumentoTipo $documentotipo) + public function destroy(documentoTipo $documentoTipo) { - $documentotipo->niveles()->detach(); - $documentotipo->delete(); + $documentoTipo->niveles()->detach(); + $documentoTipo->delete(); session()->flash('swal',[ 'icon'=>'success', 'title'=>'Eliminado!', 'text'=>'Se han eliminado los registros correctamente' ]); - return redirect()->route('documentotipo.index'); + return redirect()->route('documentoTipo.index'); } } diff --git a/app/Http/Controllers/TareaController.php b/app/Http/Controllers/TareaController.php new file mode 100644 index 00000000..4795554a --- /dev/null +++ b/app/Http/Controllers/TareaController.php @@ -0,0 +1,64 @@ +grupo = $grupo; // <- primero asignar el grupo + + $user = Auth::user(); + $plantelesIds = $user->plantelUsuarios->pluck('id'); + + $this->docentes = Docente::with(['docentes.plantelUsuarios']) + ->whereHas('docentes', function($query) use ($plantelesIds) { + $query->whereHas('plantelUsuarios', function($q) use ($plantelesIds) { + $q->whereIn('plantels.id', $plantelesIds); + }); + }) + ->get(); + + // Todas las materias de la carrera sin filtro de ciclo +$this->materias = Material::whereHas('carreraMaterial', function($query) use ($grupo) { + $query->where('carreras.id', $grupo->plan->carrera); + }) + ->orderBy('ciclo') + ->get(); + +$materiasAsignadas = DB::table('docente_grupo') + ->where('grupo_id', $this->grupo->id) + ->pluck('materia_id') + ->toArray(); + +$this->materiasSelect = Material::whereHas('carreraMaterial', function($query) use ($grupo) { + $query->where('carreras.id', $grupo->plan->carrera); + }) + ->where('ciclo', $this->grupo->ciclo) // solo ciclo actual + ->when(!empty($materiasAsignadas), function($query) use ($materiasAsignadas) { + $query->whereNotIn('id', $materiasAsignadas); // excluir ya asignadas + }) + ->get(); +} + + public function guardar() + { + $this->validate([ + 'docente_id' => 'required|exists:docentes,id', + 'materia_id' => 'required|exists:materials,id', + ]); + + $this->grupo->docentes()->attach($this->docente_id, [ + 'materia_id' => $this->materia_id + ]); + + $this->reset(['docente_id', 'materia_id']); + $this->dispatch('close-modal-docente'); + + $this->dispatch('swal', + icon: 'success', + title: '¡Listo!', + text: 'Docente asignado correctamente', + timer: 2000, + confirm: false, + closeModal: true, + reload: true + ); + } + + public function eliminar($docenteId) + { + $this->grupo->docentes()->detach($docenteId); + + $this->dispatch('swal', + icon: 'success', + title: '¡Eliminado!', + text: 'Docente removido correctamente', + timer: 2000, + confirm: false, + closeModal: false, + reload: true + ); + } + + public function render() + { + return view('livewire.grupo-docente'); + } +} diff --git a/app/Models/Docente.php b/app/Models/Docente.php index 3fed6463..ec9f6cf7 100644 --- a/app/Models/Docente.php +++ b/app/Models/Docente.php @@ -3,8 +3,31 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Docente extends Model { - // + protected $guarded = []; + + public $timestamps = false; + + // Relación con User + public function docentes(): BelongsToMany + { + return $this->belongsToMany(User::class); + } + + // Relación con Grupo + public function grupos(): BelongsToMany + { + return $this->belongsToMany(Grupo::class, 'docente_grupo') + ->withPivot('materia_id'); + } + + // Relación con Material + public function materias(): BelongsToMany + { + return $this->belongsToMany(Material::class, 'docente_grupo') + ->withPivot('grupo_id'); + } } diff --git a/app/Models/Grupo.php b/app/Models/Grupo.php index 3fcbb6f3..93f6dd8a 100644 --- a/app/Models/Grupo.php +++ b/app/Models/Grupo.php @@ -15,9 +15,14 @@ class Grupo extends Model return $this->belongsToMany(Alumno::class); } - public function plan() -{ - return $this->belongsTo(Plan::class); -} + public function docentes(): BelongsToMany + { + return $this->belongsToMany(Docente::class, 'docente_grupo') + ->withPivot('materia_id'); + } + public function plan() + { + return $this->belongsTo(Plan::class); + } } diff --git a/app/Models/Materia.php b/app/Models/Materia.php index 0c05c804..393e2b9d 100644 --- a/app/Models/Materia.php +++ b/app/Models/Materia.php @@ -1,10 +1,16 @@ belongsTo(Plan::class); } + public function tareas() { return $this->hasMany(Tarea::class); } + public function docentes() { + return $this->belongsToMany(Docente::class, 'docente_grupo') + ->withPivot('grupo_id'); + } } diff --git a/app/Models/Material.php b/app/Models/Material.php index 946ad267..0cbc32c2 100644 --- a/app/Models/Material.php +++ b/app/Models/Material.php @@ -2,8 +2,8 @@ namespace App\Models; +use App\Models\Tarea; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Material extends Model @@ -12,9 +12,15 @@ class Material extends Model public $timestamps = false; - public function carreraMaterial() : BelongsToMany + // Relación con Carrera + public function carreraMaterial(): BelongsToMany { return $this->belongsToMany(Carrera::class); } + // Tareas de esta materia + public function tareas() + { + return $this->hasMany(Tarea::class); + } } diff --git a/app/Models/Tarea.php b/app/Models/Tarea.php new file mode 100644 index 00000000..b316c890 --- /dev/null +++ b/app/Models/Tarea.php @@ -0,0 +1,19 @@ +belongsToMany(Carrera::class); + } +} diff --git a/database/migrations/2026_01_03_173803_create_alumno_status_table.php b/database/migrations/2026_01_03_173803_create_alumno_status_table.php index 3db02103..2ce0cf1b 100644 --- a/database/migrations/2026_01_03_173803_create_alumno_status_table.php +++ b/database/migrations/2026_01_03_173803_create_alumno_status_table.php @@ -14,6 +14,8 @@ return new class extends Migration Schema::create('alumno_status', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->string('color'); + }); } diff --git a/database/migrations/2026_03_19_135700_create_materias_table.php b/database/migrations/2026_03_19_135700_create_materias_table.php index 1ad869cb..c95db659 100644 --- a/database/migrations/2026_03_19_135700_create_materias_table.php +++ b/database/migrations/2026_03_19_135700_create_materias_table.php @@ -13,7 +13,13 @@ return new class extends Migration { Schema::create('materias', function (Blueprint $table) { $table->id(); + $table->string('name'); + $table->string('clave')->nullable(); + $table->unsignedBigInteger('plan_id'); // pertenece a un plan de estudios + $table->integer('ciclo'); // en qué ciclo se imparte $table->timestamps(); + + $table->foreign('plan_id')->references('id')->on('plans'); }); } diff --git a/database/migrations/2026_03_19_135756_create_docentes_table.php b/database/migrations/2026_03_19_135756_create_docentes_table.php index 40efe97c..4e8144b2 100644 --- a/database/migrations/2026_03_19_135756_create_docentes_table.php +++ b/database/migrations/2026_03_19_135756_create_docentes_table.php @@ -13,7 +13,8 @@ return new class extends Migration { Schema::create('docentes', function (Blueprint $table) { $table->id(); - $table->timestamps(); + $table->unsignedBigInteger('usuario_registro'); + $table->unsignedBigInteger('status')->default('1'); }); } diff --git a/database/migrations/2026_04_18_082244_create_becas_table.php b/database/migrations/2026_04_18_082244_create_becas_table.php new file mode 100644 index 00000000..1a929aad --- /dev/null +++ b/database/migrations/2026_04_18_082244_create_becas_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name'); + $table->string('description'); + $table->unsignedBigInteger('inscripcion')->default(0); + $table->unsignedBigInteger('reinscripcion')->default(0); + $table->unsignedBigInteger('seguro')->default(0); + $table->unsignedBigInteger('colegiatura')->default(0); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('becas'); + } +}; diff --git a/database/migrations/2026_04_18_082630_create_docente_user_table.php b/database/migrations/2026_04_18_082630_create_docente_user_table.php new file mode 100644 index 00000000..dc714a48 --- /dev/null +++ b/database/migrations/2026_04_18_082630_create_docente_user_table.php @@ -0,0 +1,29 @@ +unsignedBigInteger('docente_id'); + $table->foreign('docente_id')->references('id')->on('docentes'); + $table->unsignedBigInteger('user_id'); + $table->foreign('user_id')->references('id')->on('users'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('docente_user'); + } +}; diff --git a/database/migrations/2026_04_18_152149_create_tareas_table.php b/database/migrations/2026_04_18_152149_create_tareas_table.php new file mode 100644 index 00000000..55abfd38 --- /dev/null +++ b/database/migrations/2026_04_18_152149_create_tareas_table.php @@ -0,0 +1,27 @@ +id(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('tareas'); + } +}; diff --git a/database/migrations/2026_04_18_152854_create_docente_grupo_table.php b/database/migrations/2026_04_18_152854_create_docente_grupo_table.php new file mode 100644 index 00000000..c8758810 --- /dev/null +++ b/database/migrations/2026_04_18_152854_create_docente_grupo_table.php @@ -0,0 +1,28 @@ +unsignedBigInteger('docente_id'); + $table->unsignedBigInteger('grupo_id'); + $table->unsignedBigInteger('materia_id'); + + $table->foreign('docente_id')->references('id')->on('docentes'); + $table->foreign('grupo_id')->references('id')->on('grupos'); + $table->foreign('materia_id')->references('id')->on('materials'); + + $table->unique(['docente_id', 'grupo_id', 'materia_id']); + }); +} + +public function down(): void +{ + Schema::dropIfExists('docente_grupo'); +} +}; diff --git a/database/seeders/AlumnoStatusSeeder.php b/database/seeders/AlumnoStatusSeeder.php index 71f1bf14..162df9df 100644 --- a/database/seeders/AlumnoStatusSeeder.php +++ b/database/seeders/AlumnoStatusSeeder.php @@ -11,27 +11,33 @@ class AlumnoStatusSeeder extends Seeder public function run(): void { DB::table('alumno_status')->insert([ - 'name' => 'prospecto' + 'name' => 'prospecto', + 'color' => 'primary' ]); DB::table('alumno_status')->insert([ - 'name' => 'inscrito' + 'name' => 'inscrito', + 'color' => 'warning' ]); DB::table('alumno_status')->insert([ - 'name' => 'alumno' + 'name' => 'alumno', + 'color' => 'success' ]); DB::table('alumno_status')->insert([ - 'name' => 'baja temporal' + 'name' => 'baja temporal', + 'color' => 'secondary' ]); DB::table('alumno_status')->insert([ - 'name' => 'baja definitiva' + 'name' => 'baja definitiva', + 'color' => 'danger' ]); DB::table('alumno_status')->insert([ - 'name' => 'graduado' + 'name' => 'graduado', + 'color' => '' ]); } } diff --git a/database/seeders/PlanSeeder.php b/database/seeders/PlanSeeder.php index 6ed2d65a..a3a4af5e 100644 --- a/database/seeders/PlanSeeder.php +++ b/database/seeders/PlanSeeder.php @@ -18,7 +18,7 @@ class PlanSeeder extends Seeder 'duracion'=>6, 'duration_id'=>1, 'nivel'=>1, - 'carrera'=>2 + 'carrera'=>1 ]); $plan1->planesPlantel()->sync([1,2,3]); diff --git a/database/seeders/PlaneSeeder.php b/database/seeders/PlaneSeeder.php index e96e1890..80a15c4e 100644 --- a/database/seeders/PlaneSeeder.php +++ b/database/seeders/PlaneSeeder.php @@ -16,6 +16,7 @@ class PlaneSeeder extends Seeder 'status' => 1 ]); $plan1->planPlantel()->sync([1,2,3]); + $plan1->nivelPlane()->sync([1]); $plan2=Plane::create([ 'name' => 'LICENCIATURA', @@ -23,6 +24,8 @@ class PlaneSeeder extends Seeder ]); $plan2->planPlantel()->sync([1,2,3]); + $plan2->nivelPlane()->sync([2]); + } } diff --git a/database/seeders/RoleSeeder.php b/database/seeders/RoleSeeder.php index fe799b0d..acc71ac6 100644 --- a/database/seeders/RoleSeeder.php +++ b/database/seeders/RoleSeeder.php @@ -136,9 +136,9 @@ class RoleSeeder extends Seeder Permission::create(['name'=>'docente.edit','description'=>'Editar docentes'])->syncRoles([$role1,$role6]); Permission::create(['name'=>'docente.destroy','description'=>'Eliminar docentes'])->syncRoles([$role1,$role6]); - Permission::create(['name'=>'documentoTipo.index','description'=>'Ver documentos por nivel'])->syncRoles([$role1]); - Permission::create(['name'=>'documentoTipo.create','description'=>'Crear documentos por nivel'])->syncRoles([$role1]); - Permission::create(['name'=>'documentoTipo.edit','description'=>'Editar documentos por nivel'])->syncRoles([$role1]); - Permission::create(['name'=>'documentoTipo.destroy','description'=>'Eliminar documentos por nivel'])->syncRoles([$role1]); + Permission::create(['name'=>'documentoTipo.index','description'=>'Ver documentación'])->syncRoles([$role1]); + Permission::create(['name'=>'documentoTipo.create','description'=>'Crear documentación'])->syncRoles([$role1]); + Permission::create(['name'=>'documentoTipo.edit','description'=>'Editar documentación'])->syncRoles([$role1]); + Permission::create(['name'=>'documentoTipo.destroy','description'=>'Eliminar documentación'])->syncRoles([$role1]); } } diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 0750ef63..1e043bfb 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -66,7 +66,7 @@ class UserSeeder extends Seeder 'medio' => 1, 'usuario_registro' => 1, 'plane_id' => 0, - 'status' => 2 + 'status' => 1 ]); $alumno->alumnos()->sync($usr->id); diff --git a/resources/views/Docente/create.blade.php b/resources/views/Docente/create.blade.php new file mode 100644 index 00000000..c92a5ba8 --- /dev/null +++ b/resources/views/Docente/create.blade.php @@ -0,0 +1,93 @@ +@extends('layouts.landing') + +@section('title',"Crear") + +@section('content') + +
| Id | +Nombre | +Campus | +Rol | +Correo | +Opciones | +
|---|---|---|---|---|---|
| {{ $docente->id }} | +{{ $usr?->name }} {{ $usr?->apellidoPaterno }} | ++ @foreach($usr?->plantelUsuarios ?? [] as $plantel) + {{ $plantel->name }} + @endforeach + | ++ @foreach($usr?->roles ?? [] as $rol) + {{ $rol->name }} + @endforeach + | +{{ $usr?->email }} | +
+ @can('docente.destroy')
+
+ Edit
+
+ @endcan
+
+ @can('docente.destroy')
+
+
+
+ @endcan
+ |
+