return '

' . __('Tidak ada jadwal acara untuk ditampilkan.', 'radio-schedule') . '

'; } $current_program = $show_current ? $this->get_current_schedule() : null; $next_program = $show_current ? $this->get_next_program() : null; ob_start(); include RADIO_SCHEDULE_PLUGIN_PATH . 'templates/timetable-display.php'; return ob_get_clean(); } public function timetable_shortcode($atts) { $atts = shortcode_atts(array( 'days' => 7, 'show_current' => 'yes', 'start_hour' => 4, 'end_hour' => 24, 'style' => 'modern' ), $atts, 'radio_timetable'); // Validasi jam $start_hour = intval($atts['start_hour']); $end_hour = intval($atts['end_hour']); // Pastikan jam valid (0-23) $start_hour = max(0, min(23, $start_hour)); $end_hour = max(0, min(23, $end_hour)); // Jika start hour lebih besar dari end hour, swap if ($start_hour > $end_hour) { $temp = $start_hour; $start_hour = $end_hour; $end_hour = $temp; } return $this->display_timetable( absint($atts['days']), $atts['show_current'] === 'yes', $start_hour, $end_hour ); } private function get_weekly_schedule_for_timetable($days = 7, $start_hour = 5, $end_hour = 23) { $schedule = array(); $days_of_week = array( 'monday' => __('Senin', 'radio-schedule'), 'tuesday' => __('Selasa', 'radio-schedule'), 'wednesday' => __('Rabu', 'radio-schedule'), 'thursday' => __('Kamis', 'radio-schedule'), 'friday' => __('Jumat', 'radio-schedule'), 'saturday' => __('Sabtu', 'radio-schedule'), 'sunday' => __('Minggu', 'radio-schedule') ); // Get time slots berdasarkan parameter jam $time_slots = array(); for ($i = $start_hour; $i <= $end_hour; $i++) { $time_slots[] = sprintf('%02d:00', $i); } $args = array( 'post_type' => 'radio_program', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => '_is_recurring', 'value' => '1', 'compare' => '=' ) ) ); $programs = get_posts($args); // Initialize schedule structure $schedule_data = array(); foreach ($time_slots as $time_slot) { $schedule_data[$time_slot] = array(); foreach ($days_of_week as $day_key => $day_name) { $schedule_data[$time_slot][$day_name] = array(); } } // Fill schedule with programs foreach ($programs as $program) { $schedule_days = get_post_meta($program->ID, '_schedule_days', true); $start_time = get_post_meta($program->ID, '_start_time', true); $end_time = get_post_meta($program->ID, '_end_time', true); $host = get_post_meta($program->ID, '_host_name', true); $color = get_post_meta($program->ID, '_program_color', true); if (is_array($schedule_days) && $start_time && $end_time) { $program_start_hour = (int) substr($start_time, 0, 2); $program_end_hour = (int) substr($end_time, 0, 2); foreach ($schedule_days as $day_key) { $day_name = $days_of_week[$day_key]; for ($hour = $program_start_hour; $hour <= $program_end_hour; $hour++) { // Hanya tambahkan jika jam berada dalam range yang diminta if ($hour >= $start_hour && $hour <= $end_hour) { $time_slot = sprintf('%02d:00', $hour); if (isset($schedule_data[$time_slot][$day_name])) { $schedule_data[$time_slot][$day_name][] = array( 'title' => $program->post_title, 'start_time' => $start_time, 'end_time' => $end_time, 'host' => $host, 'color' => $color, 'is_current' => $this->is_current_program($program, $day_key), 'program_id' => $program->ID, 'duration' => $this->calculate_duration($start_time, $end_time) ); } } } } } } // Process merged cells $merged_schedule = $this->process_merged_cells($schedule_data, $time_slots, array_values($days_of_week), $start_hour, $end_hour); return array( 'time_slots' => $time_slots, 'days' => array_values($days_of_week), 'schedule' => $merged_schedule, 'start_hour' => $start_hour, 'end_hour' => $end_hour ); } private function process_merged_cells($schedule_data, $time_slots, $days, $start_hour, $end_hour) { $merged_data = array(); foreach ($days as $day) { $day_programs = array(); // Collect all programs for this day foreach ($time_slots as $time_slot) { if (!empty($schedule_data[$time_slot][$day])) { foreach ($schedule_data[$time_slot][$day] as $program) { $program_key = $program['program_id'] . '_' . $program['start_time'] . '_' . $program['end_time']; if (!isset($day_programs[$program_key])) { $day_programs[$program_key] = array( 'program' => $program, 'time_slots' => array(), 'rowspan' => 1 ); } $day_programs[$program_key]['time_slots'][] = $time_slot; } } } // Calculate rowspan for each program foreach ($day_programs as $key => $program_data) { $time_slots_count = count($program_data['time_slots']); if ($time_slots_count > 1) { $day_programs[$key]['rowspan'] = $time_slots_count; } } // Build merged schedule foreach ($time_slots as $time_slot) { if (!isset($merged_data[$time_slot])) { $merged_data[$time_slot] = array(); } $merged_data[$time_slot][$day] = array(); // Find program for this time slot foreach ($day_programs as $program_data) { if (in_array($time_slot, $program_data['time_slots'])) { // Only add to first time slot of the program if ($time_slot === $program_data['time_slots'][0]) { $merged_program = $program_data['program']; $merged_program['rowspan'] = $program_data['rowspan']; $merged_data[$time_slot][$day][] = $merged_program; } } } } } return $merged_data; } private function calculate_duration($start_time, $end_time) { $start = DateTime::createFromFormat('H:i', $start_time); $end = DateTime::createFromFormat('H:i', $end_time); if ($start && $end) { $interval = $start->diff($end); $hours = $interval->h; $minutes = $interval->i; if ($hours > 0) { return $hours . ' jam' . ($minutes > 0 ? ' ' . $minutes . ' menit' : ''); } else { return $minutes . ' menit'; } } return ''; } private function is_current_program($program, $day_key) { $current_time = current_time('H:i'); $current_day = strtolower(current_time('l')); if ($current_day !== $day_key) { return false; } $start_time = get_post_meta($program->ID, '_start_time', true); $end_time = get_post_meta($program->ID, '_end_time', true); return ($current_time >= $start_time && $current_time <= $end_time); } private function get_current_schedule() { $radio_manager = Radio_Schedule_Manager::get_instance(); return $radio_manager->core->get_current_schedule(); } private function get_next_program() { $radio_manager = Radio_Schedule_Manager::get_instance(); return $radio_manager->core->get_next_program(); } private function is_current_time_slot($time_slot) { $current_hour = (int) current_time('H'); $slot_hour = (int) substr($time_slot, 0, 2); return $current_hour === $slot_hour; } } ?> Komentar di: Tutup Akhir Tahun, Kepala Rutan Salatiga Lakukan Pengecekan ‘Troling’ https://rasikafm.com/tutup-akhir-tahun-kepala-rutan-salatiga-lakukan-pengecekan-troling/ Kawan Pemandu Jalan Tue, 02 Jan 2024 01:59:17 +0000 hourly 1 https://wordpress.org/?v=6.8.3