/** * Store a newly created resource in storage. * * @return Response */ public function store($airplane_id) { $timetable_ids = []; foreach (json_decode(Input::get('timetable')) as $item) { if (isset($item->mysql_id)) { $timetable = Timetable::find($item->mysql_id); } else { $timetable = new Timetable(); } $timetable->airline_id = Auth::user()->id; $timetable->airplane_id = $airplane_id; $timetable->origin_airport_id = $item->origin->id; $timetable->destination_airport_id = $item->destination->id; $timetable->departure_day_of_week = $item->departure_day_of_week; $timetable->departure_hour = $item->departure_hour; $timetable->flight_duration = $item->flight_duration; $timetable->flight_number = $item->flight_number; $timetable->save(); array_push($timetable_ids, $timetable->id); } DB::table('timetables')->where('airplane_id', $airplane_id)->where('airline_id', Auth::user()->id)->whereNotIn('id', $timetable_ids)->delete(); DB::table('flights')->where('airplane_id', $airplane_id)->where('airline_id', Auth::user()->id)->where('accounted', '=', '0')->whereNotIn('timetable_id', $timetable_ids)->delete(); }
public function postAddTimeTablePeriods() { $period_id = Input::get('period_id'); $class_id = Input::get('class_id'); $day_id = Input::get('day_id'); $section_id = Input::get('section_id'); $subject_id = Input::get('subject_id'); $teacher_id = Input::get('teacher_id'); $timetable_period_id = Input::get('timetable_period_id'); if ($timetable_period_id) { $timetable_period = Timetable::find($timetable_period_id); } else { $timetable_period = new Timetable(); } $timetable_period->period_id = $period_id; $timetable_period->class_id = $class_id; $timetable_period->subject_id = $subject_id; $timetable_period->day_id = $day_id; $timetable_period->section_id = $section_id; $timetable_period->users_id = $teacher_id; $subject = Subjects::find($subject_id); $teacher = UserDetails::find($teacher_id); $period = Periods::find($period_id); if ($timetable_period->save()) { $response = array('status' => 'success', 'msg' => 'New Timetable period is saved, Successfully', 'result' => array('period' => $period, 'subject' => $subject, 'teacher' => $teacher, 'timetable_period' => $timetable_period)); return Response::json($response); } $response = array('status' => 'failed', 'msg' => 'New Timetable period Couldnt be saved', 'result' => array('timetable_period' => 'none')); return Response::json($response); }
/** * Create single timetable and link it with $bus. * * @var $type string (working_day, sunday, holiday) * @var $time string * @var $bus object * @return boolean */ protected function create_timetable($type, $time, $bus) { $n_timetable = new Timetable(array('type' => $type, 'time' => $time)); $n_timetable->save(); $bus_timetable = new BusTimetablePivotal(array('bus_id' => $bus->id, 'timetable_id' => $n_timetable->id)); $bus_timetable->timestamps = false; $bus_timetable->save(); }
protected function validate() { $required = array("section" => "Section"); global $user; if ($user->checkAdmin() == true) { if (isset($_POST)) { foreach ($required as $key => $value) { if (!isset($_POST[$key]) || $_POST[$key] == '' || $_POST[$key] == 'select') { echo $value . ' is Required<br/>'; return; } } global $objPDO; include $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/timetable_settings_class.php'; $sett = new TimetableSettings($objPDO); $slots = $sett->getAllSlots(); if (!isset($slots)) { $num_slots = 0; } else { $num_slots = count($slots); } require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/timetable_class.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/section_teacher_subject_class.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/controller/utility_class.php'; for ($i = 0; $i < count($_POST['time_table']); $i++) { $spl = array(); $spl = explode("-", $_POST['time_table'][$i]); if (isset($spl[1])) { $ttab = new Timetable($objPDO); $ttab->setSectionId($_POST['section']); $ttab->setSlot($spl[1]); $ttab->getBySecSlot(); if ($spl[0] != '0') { $rel = new SectionTeacherSubjectRelations($objPDO); $tid = $rel->getByClassSubject($_POST['section'], $spl[0]); if ($ttab->checkTeacherSlot($spl[1], $tid, $_POST['section'])) { $ttab->setSubjectId($spl[0]); $ttab->setTeacherId($tid); } else { $ttab->markForDeletion(); include_once $_SERVER['DOCUMENT_ROOT'] . '/cloud/model/subject_class.php'; $sub = new Subject($objPDO, $spl[0]); $day = floor($spl[1] / $num_slots); $slot = $spl[1] % $num_slots; echo "Teacher Slot Unavailable for " . $sub->getName() . " at " . Utility::getDay($day + 1) . " " . $slots[$slot] . "<br/>"; return; $label = false; } } else { if ($spl[0] == '0') { $ttab->markForDeletion(); } } if (!isset($label) || $label != false) { } $ttab->save(); } } echo 'Saving...'; if (!isset($label) || $label != false) { echo '<meta http-equiv="Refresh" content="0;url=http://localhost/cloud/timetable"/>'; } } } else { header('Location:http://localhost/cloud'); } }