MDL-47064 Grades: Fix contribution column for other types of aggregation

Part of: MDL-46576
MDL-47064 Grades: Add comments to explain this tricky code.

Part of: MDL-46576
MDL-47064 Grades: Peer review cleanups

Changes include:
 * Search for existing items to reduce DB queries in grade_category::aggregate_grades
 * Comments improvements
 * Move brackets to be part of lang string
 * Convert aggregationhints to be a class variable instead of passing it around

Part of: MDL-46576
MDL-47064 Grades: Final fix - set the grademax from the item, not the cat

Part of: MDL-46576