Class: GradesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/grades_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#exportObject



116
117
118
119
120
121
# File 'app/controllers/grades_controller.rb', line 116

def export
  temp_file_path = File.expand_path("#{Rails.root}/tmp/#{Process.pid}_") + "export.xls"
  Grade.export_grade_book_to_spreadsheet(@course, temp_file_path)
  flash[:notice] = "grade book was exported to " + temp_file_path
  send_file(temp_file_path, :filename => "GradeBook_#{@course.name}.xls")
end

#get_courseObject



12
13
14
# File 'app/controllers/grades_controller.rb', line 12

def get_course
  @course=Course.find(params[:course_id])
end

#get_team_assignmentObject



26
27
28
29
30
31
32
33
# File 'app/controllers/grades_controller.rb', line 26

def get_team_assignment
  @team_assignment = {}
  @course.teams.each do |t|
    t.members.each do |m|
      @team_assignment[m.id] = t
    end
  end
end

#importObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/grades_controller.rb', line 101

def import
  if params[:import].nil? || params[:import][:spreadsheet].nil?
    flash[:error] = "please select a file to import"
    redirect_to course_grades_path(@course) and return
  end

  temp_file_path = params[:import][:spreadsheet].path
  if Grade.import_grade_book_from_spreadsheet(temp_file_path, @course.id)
    flash[:notice] = "grade book was imported"
  else
    flash[:error] = "spreadsheet format is incorrect"
  end
  redirect_to course_grades_path(@course)
end

#indexObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/grades_controller.rb', line 35

def index
  if @course.grading_rule.nil?
    flash[:error] = I18n.t(:no_grading_rule_for_course)
    redirect_to course_path(@course) and return
  end
  if @course.grading_rule.default_values?
    flash.now[:error] = I18n.t(:default_grading_rule_for_course)
  end
  @no_pad = true
  @students = @course.registered_students_or_on_teams
  @assignments = @course.assignments
  @grades = {}
  @students.each do |student|
    @grades[student] = Grade.get_grades_for_student_per_course(@course, student)
  end
  render
end

#post_drafted_and_sendObject

and send email



75
76
77
78
79
80
81
82
83
# File 'app/controllers/grades_controller.rb', line 75

def post_drafted_and_send #and send email
  grades = params["grades"]
  faculty_email = nil
  if params[:send_copy_to_myself] == "1"
    faculty_email = current_user.email
  end
  Grade.mail_drafted_grade(@course.id, request.host_with_port, faculty_email)
  render :json => ({"message" => "true"})
end

#render_grade_book_menuObject



16
17
18
# File 'app/controllers/grades_controller.rb', line 16

def render_grade_book_menu
  @is_in_grade_book = true
end

#saveObject



85
86
87
88
89
# File 'app/controllers/grades_controller.rb', line 85

def save
  grades = params["grades"]
  Grade.give_grades(grades, current_user.id)
  render :json => ({"message" => "true"})
end

#send_final_gradeObject



91
92
93
94
95
96
97
98
99
# File 'app/controllers/grades_controller.rb', line 91

def send_final_grade
  grades = params["grades"]
  faculty_email = nil
  if params[:send_copy_to_myself] == "1"
    faculty_email = current_user.email
  end
  Grade.mail_final_grade(@course.id, request.host_with_port, faculty_email)
  render :json => ({"message" => "true"})
end

#student_deliverables_and_grades_for_courseObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/grades_controller.rb', line 53

def student_deliverables_and_grades_for_course
  @course = Course.find(params[:course_id])
  if (params[:user_id])
    @user = User.find_by_param(params[:user_id])
  else
    @user = current_user
  end
  if (current_user.id != @user.id)
    unless (@course.faculty.include?(current_user))||(current_user.is_admin?)
      flash[:error] = I18n.t(:not_your_deliverable)
      redirect_to root_path and return
    end
  end
  @assignments = @course.assignments
  @grades = {}
  @grades[@user] = Grade.get_grades_for_student_per_course(@course, @user)
  respond_to do |format|
    format.html { render :action => "student_deliverables" }
    format.xml { render :xml => @assignments }
  end
end

#validate_permissionObject



20
21
22
23
24
# File 'app/controllers/grades_controller.rb', line 20

def validate_permission
  unless (current_user.is_admin? || @course.faculty.include?(current_user))
    has_permissions_or_redirect(:admin, root_path)
  end
end