Skip to content

Commit

Permalink
reworked the associations between student, gradation, assignment, and…
Browse files Browse the repository at this point in the history
… courses
  • Loading branch information
rnhurt committed Feb 12, 2009
1 parent fdd1d72 commit 97650a8
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/models/enrollment.rb
Expand Up @@ -2,8 +2,8 @@ class Enrollment < ActiveRecord::Base
belongs_to :student
belongs_to :course

validates_existence_of :course
validates_existence_of :student
validates_existence_of :course

validates_uniqueness_of :student_id, :scope => :course_id

Expand Down
7 changes: 4 additions & 3 deletions app/models/gradation.rb
@@ -1,12 +1,13 @@
class Gradation < ActiveRecord::Base
belongs_to :assignment
belongs_to :student
belongs_to :assignment

validates_existence_of :student
validates_existence_of :assignment
# validates_uniqueness_of :assignment_id, :scope => [:student_id]

validates_existence_of :student

# validates_uniqueness_of :student_id, :scope => [:assignment_id]
# validates_uniqueness_of :assignment_id, :scope => [:student_id]

validates_numericality_of :points_earned, :allow_nil => :true, :greater_than_or_equal_to => 0.0

Expand Down
10 changes: 8 additions & 2 deletions app/models/student.rb
@@ -1,6 +1,12 @@
class Student < User
has_many :enrollments
has_many :courses, :through => :enrollments
has_many :enrollments
has_many :gradations
# has_many :comments
has_many :courses, :through => :enrollments
has_many :assignments, :through => :gradations




validates_length_of :homeroom, :maximum => 20

Expand Down
5 changes: 3 additions & 2 deletions app/models/user.rb
@@ -1,8 +1,9 @@
class User < ActiveRecord::Base
belongs_to :site
has_many :courses, :through => :enrollment
has_many :gradations
# has_many :gradations
has_many :comments
# has_many :courses, :through => :enrollment
# has_many :assignments, :through => :gradations

validates_length_of :first_name, :in => 1..20
validates_length_of :last_name, :in => 1..20
Expand Down
4 changes: 3 additions & 1 deletion app/views/reports/show.html.erb
Expand Up @@ -24,5 +24,7 @@
<%= @report.get_params() %>
</div>

<% student = Student.find("76558238", :include => [:courses, :gradations]) %>
<%= debug student %>

<%= debug @cached_reports %>
Binary file modified doc/models.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 52 additions & 8 deletions lib/report_card.rb
@@ -1,14 +1,49 @@
class ReportCard
# This report will print a standard report card on LEGAL sized paper. It can
# print a single student or an array of students (i.e. a whole class) and will
# separate each report into even number of pages so that duplex printing will
# be possible.

def self.get_params()
# Build the parameter screen
params = <<-EOS

# Allow the user to select a single student or multiple students.
students = Student.find(:all)
homerooms = Student.find_homerooms()

params = <<-EOS
<form action="/reports/report_card.pdf" method="get">
<label><span class='required'>Student ID</span>
<input class="input-text" id="student_id" name="student_id" size="30" type="text" value="343839479" />
</label>
<label><span>Homeroom</span>
<select size='1' id="homeroom_id" name="homeroom_id">
EOS

# List each homeroom
homerooms.each do |h|
params += "<option value='#{h}'>#{h}</option>"
end

params += <<-EOS
</select>
</label>
<label><span>&nbsp;</span>
OR
</label>
<label><span>Student(s)</span>
<select multiple size="7" id="student_id" name="student_id">
EOS

# List all of the students in the school
students.each do |s|
params += "<option value='#{s[:id]}'>#{s[:first_name]}</option>"
end

params += <<-EOS
</select>
</label>
<div class="spacer">
<input class="positive" name="commit" type="submit" value="Run Report" />
</div>
Expand All @@ -18,6 +53,14 @@ def self.get_params()
end

def self.draw(params)

# Gather the required data from the database
# the user info
student = Student.find(params[:student_id], :include => :courses)

# the courses they are enrolled in
# the assignments they were responsible for
# the grades for those assignments

# Create a new document
pdf = Prawn::Document.new :page_size => "LEGAL", :skip_page_creation => false
Expand Down Expand Up @@ -89,7 +132,7 @@ def self.draw(params)

# Print the grades for each class
course_counter = 0
courses = params[:courses].count
courses = 6
courses.times do
# We have limited space on the page so we can only print 3 sets of
# grades on each page.
Expand All @@ -104,7 +147,8 @@ def self.draw(params)
mask(:y) {
# Print a class on the left side of the paper...
span(bounds.width/2, :position => :left) do
headers = ["#{params[:courses][course_counter][:name]}\n#{params[:courses][course_counter][:teacher_id]}", "1", "2", "3", "AVG"]
# headers = ["#{params[:courses][course_counter][:name]}\n#{params[:courses][course_counter][:teacher_id]}", "1", "2", "3", "AVG"]
headers = ["SPELLING/VOCABULARY\nMrs. S. Vowels", "1", "2", "3", "AVG"]
data = [
["\t\tApplication","A","B"," ","B"],
["\t\tTest/quizes","B","B"," ","B"],
Expand Down Expand Up @@ -158,7 +202,7 @@ def self.draw(params)

start_new_page
cell [0,bounds.height-50], :width => bounds.width,
:text => params[:course].to_s
:text => 'YOMAMA'

end # instance_eval

Expand Down
4 changes: 2 additions & 2 deletions lib/student_roster.rb
Expand Up @@ -25,7 +25,7 @@ def self.get_params()
</label>
<div class="spacer">
<input class="positive" name="commit" type="submit" value="Build Roster" />
<input class="positive" type="submit" value="Run Report" />
</div>
</form>
EOS
Expand All @@ -42,7 +42,7 @@ def self.draw(params)
end

# Create a new document
pdf = Prawn::Document.new (:skip_page_creation => true)
pdf = Prawn::Document.new (:skip_page_creation => true, :page => "LETTER")

# Make it so we don't have to use pdf. everywhere. :)
pdf.instance_eval do
Expand Down

0 comments on commit 97650a8

Please sign in to comment.