123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Professor;
- use App\Semester;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Http\Request;
-
- class ProfessorController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index(Request $request)
- {
- // dd(Professor::where('dept_id', '=', 1)->with(['sections:semester_code,credits,student_count', 'semesters:semester_code,admin_load,investigative_load'])->orderBy('professors.last_name')->get());
-
- $professors = Professor::with(['sections:semester_code,credits,student_count', 'semesters:semester_code,admin_load,investigative_load,other'])->select('professors.id', 'first_name', 'last_name');
- if ($request->session()->get('filter') === 'f') {
- $professors->join('departments', 'professors.dept_id', '=', 'departments.id')->where('faculty_id', '=', $request->session()->get('faculty'));
- } else if ($request->session()->get('filter') === 'd') {
- $professors->where('dept_id', '=', $request->session()->get('department'));
- }
- return view('professors.index', [
- 'professors' => $professors->orderBy('professors.last_name')->get(),
- 'semesters' => Semester::orderBy('semesters.code', 'asc')->get(),
- ]);
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- //
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- //
- $professor = Professor::create( $request->validate([
- 'num_prof' => ['required', 'unique:professors', 'max:16', 'string'],
- 'first_name' => ['required', 'max:255', 'string', 'alpha'],
- 'last_name' => ['required', 'max:255', 'string', 'alpha'],
- 'email' => ['nullable', 'email'],
- 'type' => ['nullable', 'in:plantilla,contrato,ta'],
- 'dept_id' => ['required', 'exists:departments,id', 'integer'],
- ]));
- // dd($professor);
-
- return redirect('/professor/' . $professor->id);
- }
-
- /**
- * Display the specified resource.
- *
- * @param \App\Professor $professor
- * @return \Illuminate\Http\Response
- */
- public function show(Professor $professor)
- {
- $professor->loadMissing(['sections.course', 'semesters.sections.course', 'sections.schedules']);
- $loads = $professor->semesters()->get()->keyBy('code');
- $sections = $professor->sections()->with('course:id,code')->get()->groupBy('semester_code');
- $semesters = Semester::whereIn('code', $loads->keys())->orWhereIn('code', $sections->keys())->orderBy('code', 'desc')->get();
-
- return view('professors.show', compact([
- 'professor',
- 'semesters',
- 'sections',
- 'loads'
- ]));
- }
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param \App\Professor $professor
- * @return \Illuminate\Http\Response
- */
- public function edit(Professor $professor)
- {
- //
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param \App\Professor $professor
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, Professor $professor)
- {
- // TODO: Update section percent,schedule and eval
- if ($request->isMethod('put')) {
- $data = array_filter($request->validate([
- 'semester_code' => ['required_with:admin_load,investigative_load,other', 'string','size:3'],
- 'admin_load' => ['nullable', 'numeric'],
- 'investigative_load' => ['nullable', 'numeric'],
- 'other' => ['nullable', 'numeric']
- ]));
- // dd($data);
- if (! $professor->semesters->contains($data['semester_code'])) {
- $professor->semesters()->attach($data['semester_code'], $data);
- } else {
- $professor->semesters()->updateExistingPivot($data['semester_code'], $data);
- }
- } else if ($request->isMethod('patch')) {
- $data = array_filter($request->validate([
- 'num_prof' => ['nullable', 'unique:professors', 'max:16', 'string'],
- 'first_name' => ['nullable', 'max:255', 'string', 'alpha'],
- 'last_name' => ['nullable', 'max:255', 'string', 'alpha'],
- 'email' => ['nullable', 'email'],
- 'type' => ['nullable', 'in:plantilla,contrato,ta'],
- 'dept_id' => ['nullable', 'exists:departments,id', 'integer'],
- ]));
- $professor->update($data);
- }
- return redirect()->back();
- }
-
- /**
- * Remove the specified resource from storage.
- *
- * @param \App\Professor $professor
- * @return \Illuminate\Http\Response
- */
- public function destroy(Professor $professor)
- {
- //
- }
- }
|