classrooms: add sort_by_period for sorting an array by period.

This helps with various tasks that other things must do.