[ticket/12742] Put duplicated code into one method in notifications base

Ticket: https://tracker.phpbb.com/browse/PHPBB3-12742
Is this sort() needed in every function call because some of the earlier code doesnt seem to be using it. If not I think we should add a flag parameter to determine whether to sort or not.