query($sql)->fetchAll(PDO::FETCH_ASSOC); } function db_team_get(PDO $pdo, int $id): ?array { $stmt = $pdo->prepare("SELECT * FROM team WHERE id = ? AND gym_id = ? LIMIT 1"); $stmt->execute([$id, admin_gym_id()]); return $stmt->fetch(PDO::FETCH_ASSOC) ?: null; } function db_team_create(PDO $pdo, array $data): int { $stmt = $pdo->prepare(" INSERT INTO team (gym_id, name, title, birthday, `at`, status, description, skills, certifications, photo, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW()) "); $stmt->execute([ admin_gym_id(), $data['name'], $data['title'] ?? '', $data['birthday'] ?: null, $data['at'] ?: null, $data['status'] ?? 'ativo', $data['description'] ?? null, ($data['skills'] ?? '') !== '' ? $data['skills'] : null, ($data['certifications'] ?? '') !== '' ? $data['certifications'] : null, $data['photo'] ?? null, ]); $__id = (int) $pdo->lastInsertId(); audit_change($pdo, 'team', 'team', 'id', (int) $__id, 'create', null, 'name'); return $__id; } function db_team_update(PDO $pdo, int $id, array $data, ?string $photo = null): bool { $__before = audit_row($pdo, 'team', 'id', (int) $id); $sets = ["name = ?", "title = ?", "birthday = ?", "`at` = ?", "status = ?", "description = ?", "skills = ?", "certifications = ?", "updated_at = NOW()"]; $params = [ $data['name'], $data['title'] ?? '', $data['birthday'] ?: null, $data['at'] ?: null, $data['status'] ?? 'ativo', $data['description'] ?? null, ($data['skills'] ?? '') !== '' ? $data['skills'] : null, ($data['certifications'] ?? '') !== '' ? $data['certifications'] : null, ]; if ($photo !== null) { $sets[] = "photo = ?"; $params[] = $photo; } $params[] = $id; $stmt = $pdo->prepare("UPDATE team SET " . implode(', ', $sets) . " WHERE id = ?"); $stmt->execute($params); $__r = $stmt->rowCount() > 0; audit_change($pdo, 'team', 'team', 'id', (int) $id, 'update', $__before, 'name'); return $__r; } // Soft delete para a lixeira (config/functions_trash.php). function db_team_delete(PDO $pdo, int $id): bool { return trash_delete($pdo, 'team', $id); } function db_team_restore(PDO $pdo, int $id): bool { return trash_restore($pdo, 'team', $id); }