I guess this is about as beautiful as PHP gets :p
(I had not fun discovering this monstrosity.)
One minor suggestion I have is to eliminate the duplication here:
if (isset($question[$field_name])) { $sql_params[':' . $field_name] = $question[$field_name]; } else { $sql_params[':' . $field_name] = 0; }
I'm surprised our good friend of ternarys @Quill@Quill forgot to include this prime candidate:
$sql_params[':' . $field_name] = isset($question[$field_name]) ? $question[$field_name] : 0;
Another thing that put me off a little bit is this mysterious piece in the middle the code:
$filter = "!)rcjzniPuafk4WNG65yr";
What is this about? Where did this value come from? Is it important?
Like all magic constants, it would be good to put it near the top of the file with a descriptive name.
Lastly, maybe it's not feasible at all,
but it would be nice to be able to style the display using CSS,
instead of the hard-coded $color values.
Finally, strpos($apiCall, '?') === false is cryptic enough (fault of PHP, not yours), that it might be worth encapsulating it in a helper method:
function contains($haystack, $needle) {
return strpos($haystack, $needle) !== false;
}
It keeps the rest of your code clean and nicely readable, and isolates the, ahem, garbage.