When $client_filter is provided, the function performs JOINs across multiple tables (de_posts, de_postmeta) to filter sessions by client association. This may impact query performance for large datasets.
Query without filter:
$stmt = $pdo->query("SELECT * FROM de_app_sessions");
Query with client filter:
$sql = "SELECT s.* FROM de_app_sessions s JOIN de_posts p ON s.gameId = p.ID JOIN de_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_cliente_asociado' JOIN de_posts c ON CAST(pm.meta_value AS UNSIGNED) = c.ID WHERE c.post_title = :client";
// Get all sessions$allSessions = get_sessions();// Filter by date range and user$filtered = get_filtered_sessions($allSessions, [ 'startDate' => '2024-01-01', 'endDate' => '2024-12-31', 'userId' => 42]);// Filter by game only$gameFiltered = get_filtered_sessions($allSessions, [ 'gameId' => 10]);
This function is useful when you already have sessions in memory and need to apply additional filters without making another database query.
// Get answers for a specific session$answers = get_user_game_answers(42, 10, 1234);// Get answers from latest session$answers = get_user_game_answers(42, 10);foreach ($answers as $answer) { echo "Question: " . $answer['text']; echo "Correct: " . ($answer['is_correct'] ? 'Yes' : 'No'); echo "Score: " . $answer['score'];}
The function automatically detects whether the game is an “Angel vs Demonio” type dilemma by checking for entries in the de_app_ad_questions table and returns appropriately formatted answer data.