Added method to get locations count by type

Also, splitted core changes from PR: https://github.com/dimagi/commcare-hq/pull/3839
Indentation changed from 2 to 4 spaces here. Granted, indentation in this file is a bit wonky.