Gluon polarization tensor in a magnetized medium: Analytic approach starting from the sum over Landau levels