middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
return view('dashboard.index', [
'professors' => Professor::orderBy('last_name')->get(),
'semesters' => Semester::orderBy('code')->get()
]);
}
/**
* Download the schedule for the given semester.
*
* @param string $semester
* @return View
*/
public function schedule(Request $request, $semester_code) {
$semester = Semester::findOrFail($semester_code);
$data = (object)['alpha' => $semester->alpha];
$data->dept = Department::find($request->session()->get('department'));
$data->courses = $semester->courses()->where('dept_id', '=', $data->dept->id)->with([
'sections' => function ($query) use ($semester) {
$query->where('semester_code', '=', $semester->code);
},
'sections.schedules',
'sections.professors',
])->distinct()->get()->sort('cmpCourseCode')->values();
// dump(json_encode($data, JSON_PRETTY_PRINT));
return '';
}
public function export($semester_code) {
$semester = Semester::findOrFail($semester_code);
$professors = Professor::with([
'sections' => function ($query) use ($semester_code) {
$query->where('semester_code', '=', $semester_code);
},
'semesters:code,admin_load,investigative_load,other'
])->whereIn('id', function($query) use ($semester_code) {
$query->select('professor_id')
->from('professor_semester')
->where('semester_code', '=', $semester_code);
})->orWhereIn('id', function($query) use ($semester_code) {
$query->select('professor_id')
->from('sections')
->join('professor_section', 'sections.id', '=', 'professor_section.section_id')
->where('semester_code', '=', $semester_code);
})->orderBy('last_name')->get();
header('Content-Type: application/csv');
header(`Content-Disposition: attachment; filename="${semester_code}.csv";`);
if ($file = fopen('php://output', 'w+')) {
fputcsv($file, ['PROFESOR', 'CARGA ACADEMICA', 'CARGA ADMINISTRATIVA', 'CARGA INVESTIGATIVA', 'OTRAS CARGAS', 'CARGA TOTAL']);
foreach ($professors as $professor) {
$professor->academic_load = $professor->getAcademicLoad($semester);
$prof_loads = $professor->semesters->find($semester);
fputcsv($file, [
$professor->last_name . ', ' . $professor->first_name,
$professor->academic_load,
$prof_loads->admin_load ?? 0,
$prof_loads->investigative_load ?? 0,
$prof_loads->other ?? 0,
$professor->academic_load + ($prof_loads->admin_load ?? 0) + ($prof_loads->investigative_load ?? 0) + ($prof_loads->other ?? 0),
]);
}
fclose($file);
die();
}
}
public function exportCourses(Request $request) {
$courses = Course::where('dept_id', '=', $request->session()->get('department'))->with('sections:id,course_id,semester_code')->get()->sort('cmpCourseCode');
$semesters = Semester::orderBy('code', 'asc')->get();
header('Content-Type: application/csv');
header(`Content-Disposition: attachment; filename="courses.csv";`);
if ($file = fopen('php://output', 'w+')) {
fputcsv($file, array_merge(['CURSO'], $semesters->pluck('alpha')->toArray()));
foreach ($courses as $course) {
fputcsv($file,
array_merge([$course->code], $semesters->map(function ($semester) use ($course) {
return $course->getSemesterSectionCount($semester->code);
})->toArray())
);
}
fclose($file);
die();
}
}
public function cloneSemester(Request $request, $semester_code) {
$semester = Semester::findOrFail($semester_code);
// dd($semester->sections);
$data = $request->validate([
'new_semester' => 'required|regex:/^[a-zA-Z][0-9][123]$/',
'new_alpha' => 'nullable'
]);
try {
$semester->clone(strtoupper($data['new_semester']), strtoupper($data['new_alpha']), $request->session()->get('department'));
} catch (Exception $e) {
echo $e->getMessage();
}
return redirect()->back();
}
/**
*/
public function addUser(Request $request) {
return view('dashboard.user');
}
}