Refactor similar SQL generation code from get_users_by_capability and get_enrolled_uses to make get_with_capability_sql. Modified files: accesslib.php, enrollib.php, grouplib.php, new tests.