Please only experienced Magento developers only!
Make sorting work like this:
First, all products are sorted by this first-level sorting. Then, as second level, they are sorted by normal sorting, inside these groups.
First level sorting:
1. If product has more than 0 qty, it shows first in catalog.
2. If product has 0 qty, but has specific custom boolean attribute set to True, it shows next.
3. All other products (which have 0 qty and specific custom attribute = false) are at the end.
Inside these 3 groups. products are sorted by normal rules (e.g. by price, popularity etc., what customer chooses).
1. Magento stock managing is disabled, but stock is loaded by API.
2. We have custom theme, and custom sorting extention installed.