عفوا! ’t لا يمكن العثور على هذه الصفحة.
It looks like nothing was found at this location. Maybe try a search?
/* ===== /games (محدّثة ومصححة) ===== */ function flx_api_games( WP_REST_Request $r ) { global $wpdb; $p = $wpdb->prefix; // التحقق من وجود جدول المباريات فقط if ( ! flx_tbl_exists( "{$p}anwpfl_matches" ) ) { return new WP_Error( 'no_table', 'Table anwpfl_matches not found', ['status'=>500] ); } list($page,$per_page,$offset) = flx_pagination_args($r); $where = []; $params = []; // نفس أسماء أعمدتك بالضبط if ( $comp = absint( $r->get_param('comp_id') ) ) { $where[] = "m.competition_id = %d"; $params[] = $comp; } if ( $season = absint( $r->get_param('season_id') ) ){ $where[] = "m.season_id = %d"; $params[] = $season; } if ( $team = absint( $r->get_param('team_id') ) ) { $where[] = "(m.home_club = %d OR m.away_club = %d)"; $params[] = $team; $params[] = $team; } // finished: 0/1 (بديل عن status) if ( null !== $r->get_param('finished') ) { $finished = (int) $r->get_param('finished'); $where[] = "m.finished = %d"; $params[] = $finished; } // تواريخ حسب عمودك "kickoff" if ( $from = $r->get_param('date_from') ) { $where[] = "m.kickoff >= %s"; $params[] = $from; } if ( $to = $r->get_param('date_to') ) { $where[] = "m.kickoff <= %s"; $params[] = $to; } $where_sql = $where ? 'WHERE ' . implode(' AND ', $where) : ''; // ترتيب ديناميكي (kickoff موجود عندك) $order_dir = strtoupper( sanitize_text_field( $r->get_param('order') ?: 'ASC' ) ); $order_dir = in_array( $order_dir, ['ASC','DESC'], true ) ? $order_dir : 'ASC'; $order_col = 'kickoff'; // عندك موجود // ⚠️ إزالة الـ JOINS لأن الجداول غير موجودة // استخدام البيانات الأساسية فقط من جدول المباريات $joins = ''; $select_extra = ''; // العدّ $sql_count = "SELECT COUNT(*) FROM {$p}anwpfl_matches m $where_sql"; if ($params) { $total = (int) $wpdb->get_var( $wpdb->prepare( $sql_count, $params ) ); } else { $total = (int) $wpdb->get_var( $sql_count ); } // البيانات - فقط من جدول المباريات $sql = "SELECT m.* FROM {$p}anwpfl_matches m $where_sql ORDER BY m.`$order_col` $order_dir LIMIT %d OFFSET %d"; $params_pag = $params; $params_pag[] = $per_page; $params_pag[] = $offset; $rows = $wpdb->get_results( $wpdb->prepare( $sql, $params_pag ) ); // ✅ إضافة أسماء الأندية والبطولات باستخدام Custom Post Types $rows = flx_enrich_matches_data($rows); return flx_json_response( $rows, [ 'page' => $page, 'per_page' => $per_page, 'total' => $total, 'total_pages' => (int) ceil($total / max(1, $per_page)), 'order_by' => $order_col, 'note' => 'تم إثراء البيانات باستخدام Custom Post Types' ]); } /* ===== دالة إثراء البيانات ===== */ function flx_enrich_matches_data($matches) { if (empty($matches)) return $matches; foreach ($matches as $match) { // إضافة أسماء الأندية من Custom Post Types $match->home_club_name = flx_get_club_name($match->home_club); $match->away_club_name = flx_get_club_name($match->away_club); // إضافة اسم البطولة من Custom Post Types $match->competition_name = flx_get_competition_name($match->competition_id); // إضافة معلومات إضافية $match->match_status = $match->finished ? 'مكتمل' : 'لم يبدأ'; $match->score = $match->home_goals . ' - ' . $match->away_goals; } return $matches; } /* ===== الحصول على اسم النادي ===== */ function flx_get_club_name($club_id) { if (!$club_id) return 'غير معروف'; // البحث في Custom Post Type 'anwp_club' $club_post = get_posts([ 'post_type' => 'anwp_club', 'meta_query' => [ [ 'key' => '_anwpfl_club_id', 'value' => $club_id, 'compare' => '=' ] ], 'posts_per_page' => 1 ]); if (!empty($club_post)) { return $club_post[0]->post_title; } // إذا لم يوجد، جرب البحث المباشر $club_post_by_id = get_post($club_id); if ($club_post_by_id && $club_post_by_id->post_type === 'anwp_club') { return $club_post_by_id->post_title; } return 'النادي ' . $club_id; } /* ===== الحصول على اسم البطولة ===== */ function flx_get_competition_name($competition_id) { if (!$competition_id) return 'غير معروف'; // البحث في Custom Post Type 'anwp_competition' $comp_post = get_posts([ 'post_type' => 'anwp_competition', 'meta_query' => [ [ 'key' => '_anwpfl_competition_id', 'value' => $competition_id, 'compare' => '=' ] ], 'posts_per_page' => 1 ]); if (!empty($comp_post)) { return $comp_post[0]->post_title; } // إذا لم يوجد، جرب البحث المباشر $comp_post_by_id = get_post($competition_id); if ($comp_post_by_id && $comp_post_by_id->post_type === 'anwp_competition') { return $comp_post_by_id->post_title; } return 'البطولة ' . $competition_id; } /* ===== /games/facets (مصححة) ===== */ add_action( 'rest_api_init', function(){ register_rest_route( 'fl', '/games/facets', [ 'methods' => 'GET', 'permission_callback' => '__return_true', 'callback' => function( WP_REST_Request $r ){ global $wpdb; $p = $wpdb->prefix; if ( ! flx_tbl_exists( "{$p}anwpfl_matches" ) ) { return new WP_Error( 'no_table', 'Table anwpfl_matches not found', ['status'=>500] ); } $comps = $wpdb->get_col( "SELECT DISTINCT competition_id FROM {$p}anwpfl_matches WHERE competition_id IS NOT NULL ORDER BY competition_id ASC" ); $seasons = $wpdb->get_col( "SELECT DISTINCT season_id FROM {$p}anwpfl_matches WHERE season_id IS NOT NULL ORDER BY season_id DESC" ); $homes = $wpdb->get_col( "SELECT DISTINCT home_club FROM {$p}anwpfl_matches WHERE home_club IS NOT NULL ORDER BY home_club ASC" ); $aways = $wpdb->get_col( "SELECT DISTINCT away_club FROM {$p}anwpfl_matches WHERE away_club IS NOT NULL ORDER BY away_club ASC" ); // ✅ إضافة الأسماء للنتائج $competitions = []; foreach ($comps as $comp_id) { $competitions[] = [ 'id' => $comp_id, 'name' => flx_get_competition_name($comp_id) ]; } $home_clubs = []; foreach ($homes as $club_id) { $home_clubs[] = [ 'id' => $club_id, 'name' => flx_get_club_name($club_id) ]; } $away_clubs = []; foreach ($aways as $club_id) { $away_clubs[] = [ 'id' => $club_id, 'name' => flx_get_club_name($club_id) ]; } return flx_json_response( [ 'competitions' => $competitions, 'season_ids' => array_map('intval',$seasons), 'home_clubs' => $home_clubs, 'away_clubs' => $away_clubs, 'note' => 'تم إثراء البيانات باستخدام Custom Post Types' ]); } ]); }); /* ===== دالة التحقق من وجود الجداول ===== */ function flx_tbl_exists( $table ) { global $wpdb; return $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table ) ) === $table; } /* ===== دالة التقسيم ===== */ function flx_pagination_args( WP_REST_Request $r ) { $page = max( 1, (int) $r->get_param('page') ); $per_page = max( 1, min( 100, (int) $r->get_param('per_page') ?: 20 ) ); $offset = ( $page - 1 ) * $per_page; return [ $page, $per_page, $offset ]; } /* ===== دالة الرد JSON ===== */ function flx_json_response( $data, $extra = [] ) { return new WP_REST_Response( array_merge( [ 'success' => true, 'data' => $data ], $extra ) ); }
It looks like nothing was found at this location. Maybe try a search?