MDL-47064 core_grades: fix the calculation of contribution towards total

Part of: MDL-46576
MDL-47064 Grades: Fix the contributed weights column for students and teachers.

Part of: MDL-46576
MDL-47064 Grades: Make the contribution to total column work

Part of: MDL-46576
MDL-47064 Grades: Add contribution to course total to behat test.

Part of: MDL-46576
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