Alta de modificaciones de grupo con alumbnos y docentes
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TareaController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Docente;
|
||||
use App\Models\Material;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Component;
|
||||
|
||||
class GrupoDocente extends Component
|
||||
{
|
||||
public $grupo;
|
||||
public $docentes;
|
||||
public $materias;
|
||||
public $docente_id;
|
||||
public $materia_id;
|
||||
public $materiasSelect;
|
||||
|
||||
public function mount($grupo)
|
||||
{
|
||||
$this->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');
|
||||
}
|
||||
}
|
||||
+24
-1
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Materia extends Model
|
||||
{
|
||||
//
|
||||
protected $guarded = [];
|
||||
|
||||
public function plan() { return $this->belongsTo(Plan::class); }
|
||||
public function tareas() { return $this->hasMany(Tarea::class); }
|
||||
public function docentes() {
|
||||
return $this->belongsToMany(Docente::class, 'docente_grupo')
|
||||
->withPivot('grupo_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Material extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
// Relación con Carrera
|
||||
public function carreraMaterial(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Carrera::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user