Browse files

Minor report card corrections

 * added a check for no-assignments
 * corrected an issue where courses wouldn't print in 2 columns
  • Loading branch information...
1 parent a533467 commit 9c1cd6f89a65f0b67104400094d7d21a7bdeabe2 Richard Hurt committed Aug 17, 2009
Showing with 18 additions and 14 deletions.
  1. +18 −14 lib/reports/report_card.rb
View
32 lib/reports/report_card.rb
@@ -93,14 +93,18 @@ def self.draw(params)
# Generate the table containing the course grade information
def make_table(headers, data)
- table(
- data,
- :headers => headers,
- :header_color => "C0C0C0",
- :font_size => 7,
- :border_style => :grid,
- :border_width => 0.5,
- :width => bounds.width)
+ if data.blank?
+ text "No assignments found for course '#{@course.name}'."
+ else
+ table(
+ data,
+ :headers => headers,
+ :header_color => "C0C0C0",
+ :font_size => 7,
+ :border_style => :grid,
+ :border_width => 0.5,
+ :width => bounds.width)
+ end
end
# Generate a new page for the report.
@@ -172,21 +176,21 @@ def new_page
# Print the grades for each course
- @courses.each_with_index do |course, index|
+ @courses.each_with_index do |@course, index|
# Try not to overflow into the next page
new_page if cursor < 300
data = []
data_hash = {}
- headers = ["#{course.name}\n #{course.teacher.full_name}"]
+ headers = ["#{@course.name}\n #{@course.teacher.full_name}"]
test_data = []
- course.course_terms.each{|ct| test_data << "ct#{ct.id}"}
+ @course.course_terms.each{|ct| test_data << "ct#{ct.id}"}
skill_score = Struct.new(:supporting_skill, *test_data)
# Gather the grades for each term in this course
- course.course_terms.sort!{|a,b| a.term.end_date <=> b.term.end_date}.each_with_index do |course_term, index|
+ @course.course_terms.sort!{|a,b| a.term.end_date <=> b.term.end_date}.each_with_index do |course_term, ctindex|
grade = course_term.calculate_grade(student.id)
header = "#{course_term.term.name}\n #{grade[:letter]}"
header += " (#{grade[:score].round}%)" if grade[:score] >= 0
@@ -199,15 +203,15 @@ def new_page
skill_score.new(ctskill.supporting_skill.description))
# Get the score for the current course_term_skill
- temp[index+1] = ctskill.score(student)
+ temp[ctindex+1] = ctskill.score(student)
# Store it back into the hash for data
data_hash[ctskill.supporting_skill] = temp
end
end
# Create the data for the table
data_hash.values.each{|value| data << value.to_a}
-
+
# Sort the skills alphabetically
data.sort!

0 comments on commit 9c1cd6f

Please sign in to comment.