CONTRIB-4960 - Ensure grade item exists to avoid 'Invalid argument supplied for foreach()' error

Thanks to David Balch for reporting this and providing a patch.