public function status($statusType) { if (1 == $statusType) { $buildingNumber = Building::count(); $roomNumber = Room::count(); $buildingRet = ['buildingNumber' => $buildingNumber, 'roomNumber' => $roomNumber]; return $buildingRet; } else { if (2 == $statusType) { $roomNumber = Room::count(); $rentedRoomNumber = Contract::count(); $emptyRoomNumber = $roomNumber - $rentedRoomNumber; $rentRet = ['roomNumber' => $roomNumber, 'rentedNumber' => $rentedRoomNumber, 'emptyNumber' => $emptyRoomNumber]; return $rentRet; } else { if (3 == $statusType) { $feePlanItem = DB::select('SELECT COUNT(DISTINCT feemeta_id) as counts FROM fee_plans WHERE status=0 AND deleted_at IS NULL'); $feePlanRentNumber = DB::select('SELECT COUNT(DISTINCT rent_id) as counts FROM fee_plans WHERE status=0 AND deleted_at IS NULL'); $feeRet = ['feePlanNumber' => $feePlanItem[0]->counts, 'feePlanRentNumber' => $feePlanRentNumber[0]->counts]; return $feeRet; } else { if (4 == $statusType) { $userNumber = User::count(); $userRet = ['userCount' => $userNumber]; return $userRet; } } } } }
/** * Show the application dashboard. * * @return \Illuminate\Http\Response */ public function index() { $_schedule_masters = Master::orderBy('id', 'desc')->lists('name', 'id'); $master_id = array_keys(head($_schedule_masters))[0]; $data_pie = DB::select('SELECT da.code, count(sc.id) total_class FROM ( SELECT isc.* FROM schedules isc GROUP BY isc.section_key ) sc INNER JOIN semesters se ON sc.semester_id = se.id INNER JOIN plans pl ON se.plan_id = pl.id INNER JOIN curriculums cu ON pl.curriculum_id = cu.id INNER JOIN courses co ON pl.course_id = co.id INNER JOIN departments da ON co.department_id = da.id WHERE sc.master_id = ' . $master_id . ' GROUP BY da.id'); $data_query = DB::select('SELECT count(sc.id) total FROM ( SELECT isc.* FROM schedules isc GROUP BY isc.room_id ) sc WHERE sc.master_id = ' . $master_id); $data_room = []; if ($data_query) { $data_room['used'] = $data_query[0]->total; $data_room['total'] = \App\Room::count(); } $data_query = DB::select('SELECT count(sc.id) total FROM ( SELECT isc.* FROM schedules isc WHERE not faculty_id is null GROUP BY isc.faculty_id ) sc WHERE sc.master_id = ' . $master_id); $data_faculty = []; if ($data_query) { $data_faculty['used'] = $data_query[0]->total; $data_faculty['total'] = \App\Faculty::count(); } $data_query = DB::select('SELECT count(sc.id) total FROM ( SELECT isc.* FROM schedules isc INNER JOIN semesters se ON isc.semester_id = se.id INNER JOIN plans pl ON se.plan_id = pl.id INNER JOIN curriculums cu ON pl.curriculum_id = cu.id INNER JOIN courses co ON pl.course_id = co.id GROUP BY co.id ) sc WHERE sc.master_id = ' . $master_id); $data_course = []; if ($data_query) { $data_course['used'] = $data_query[0]->total; $data_course['total'] = \App\Course::count(); } $data_query = DB::select('SELECT count(sc.id) total FROM ( SELECT isc.* FROM schedules isc WHERE faculty_id is null OR room_id is null GROUP BY isc.key ) sc WHERE sc.master_id = ' . $master_id); $data_unallocated = []; if ($data_query) { $data_unallocated['used'] = $data_query[0]->total; $data_query = DB::select('SELECT count(sc.id) total FROM ( SELECT isc.* FROM schedules isc GROUP BY isc.key ) sc WHERE sc.master_id = ' . $master_id); $data_unallocated['total'] = $data_query[0]->total; } return view('dashboard.index', compact('data_pie', 'data_room', 'data_faculty', 'data_course', 'data_unallocated')); }
public function store(Request $request) { if (Room::count() == 0) { flash()->error("You must add at least one room before creating\n a conference"); return back()->withInput(); } $this->validate($request, ['name' => 'required|min:5|max:255']); $first = $request['start_time']; $last = $request['end_time']; if (empty($first[0]) or empty($last[0])) { flash()->error("You must add a start time and an end time"); return back()->withInput(); } $conference = new Conference(); $conference->name = $request['name']; $conference->save(); $rooms = Room::where('available', true)->get(); $numDays = sizeOf($first); //start day loop from here if ($numDays == 1) { $times = []; $tStart = strtotime($first[0]); $tEnd = strtotime($last[0]); $tNow = $tStart; $i = 1; $times[0] = date("H:i", $tNow) . "\n"; while ($tNow < $tEnd) { $tNow = strtotime('+30 minutes', $tNow); $times[$i] = date("H:i", $tNow) . "\n"; $i = $i + 1; } foreach ($rooms as $room) { foreach ($times as $time) { $timeslot = new Timeslot(); $timeslot->day = 1; $timeslot->room_code = $room->code; $timeslot->conference_id = $conference->id; $timeslot->time = $time; $timeslot->save(); } } } else { for ($day = 1, $index = 0; $day < $numDays || $index < $numDays - 1; $day++, $index++) { $times = []; $tStart = strtotime($first[$index]); $tEnd = strtotime($last[$index]); $tNow = $tStart; $i = 1; $times[0] = date("H:i", $tNow) . "\n"; while ($tNow < $tEnd) { $tNow = strtotime('+30 minutes', $tNow); $times[$i] = date("H:i", $tNow) . "\n"; $i = $i + 1; } //$i os the number of timeslots foreach ($rooms as $room) { foreach ($times as $time) { $timeslot = new Timeslot(); $timeslot->day = $day; $timeslot->room_code = $room->code; $timeslot->conference_id = $conference->id; $timeslot->time = $time; $timeslot->save(); } } } } flash()->success("New conference created successfully!!"); return redirect()->route('user.show'); }