/** * Get the time element from datetime parameter, then get kode_waktu from fetched time, based on Noreg and Kode Seksi * @param $date * @return mixed|null */ public static function getKodeWaktuByDate($date, $kode_seksi, $noreg) { $instance = DB::select('SELECT time(tanggal) as time FROM presences WHERE date(tanggal)=? and kode_seksi=? and Noreg=? order by time desc', [$date, $kode_seksi, $noreg]); if (count($instance) == 0) { return null; } $time = $instance[0]->time; //next query timeslot, guaranteed to be not null by condition $timeslot = WaktuKuliah::getKodeWaktuByTime($time); return $timeslot; }
/** * @param $day string of course day * @param $time_start string of course start time * @param $time_end string of course end time */ public static function isAbsentFillable($day, $time_start, $time_end, $kode_seksi, $noreg) { //get current time in Indonesia $current_day = trans('messages.' . date('l')); //get current time $current_time = date('H:i'); //first condition current time must be in interval course time $stat = (bool) DB::select('select ? between ? and ? as result', [$current_time, $time_start, $time_end])[0]->result; //second condition current day must be within course day $stat2 = strcmp($current_day, $day) == 0; //third condition, check in presences table whether current slot already exist $current_slot = WaktuKuliah::getKodeWaktuByTime($current_time); if (is_null($current_slot)) { return 0; } $current_date = date('Y-m-d'); $recorded_slot = Presence::getKodeWaktuByDate($current_date, $kode_seksi, $noreg); //if(is_null($recorded_slot)) // return 0; //insertable if current slot different from recorded slot $stat3 = strcmp($current_slot, $recorded_slot) != 0; $final_stat = $stat && $stat2 && $stat3; return $final_stat; }