Class: Assignment

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/assignment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dateObject

Returns the value of attribute date


24
25
26
# File 'app/models/assignment.rb', line 24

def date
  @date
end

#hourObject

Returns the value of attribute hour


24
25
26
# File 'app/models/assignment.rb', line 24

def hour
  @hour
end

#minuteObject

Returns the value of attribute minute


24
25
26
# File 'app/models/assignment.rb', line 24

def minute
  @minute
end

Class Method Details

.list_assignments_for_student(student_id, type = :all) ⇒ Object

To get list of all the assignments for the student from the courses he has registered.


90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/assignment.rb', line 90

def self.list_assignments_for_student student_id, type= :all
  student = User.find(student_id)
  courses = case type
              when :all
                student.registered_courses
              when :current
                student.registered_for_these_courses_during_current_semester
              when :past
                student.registered_for_these_courses_during_past_semesters
            end
  assignments = Assignment.unscoped.find_all_by_course_id(courses.map(&:id), :order => "course_id ASC, id ASC")
end

.reposition(ids) ⇒ Object

Re-position: change the sequence of Assignments


104
105
106
# File 'app/models/assignment.rb', line 104

def self.reposition(ids)
  update_all(["assignment_order = STRPOS(?, ','||id||',')", ",#{ids.join(',')},"], {:id => ids})
end

Instance Method Details

#formatted_maximum_scoreObject


81
82
83
84
85
86
87
# File 'app/models/assignment.rb', line 81

def formatted_maximum_score
  if self.course.nil? || self.course.grading_rule.nil? || self.course.grading_rule.grade_type=="points"
    self.maximum_score.to_s
  else
    "100"
  end
end

#get_student_deliverable(student_id) ⇒ Object

To get the list of deliverables submitted by the student.


65
66
67
68
69
70
71
72
73
74
# File 'app/models/assignment.rb', line 65

def get_student_deliverable student_id
  if self.is_team_deliverable?
    team = User.find(student_id).teams.find_by_course_id(self.course_id)
    unless team.nil?
      self.deliverables.find_by_team_id(team.id)
    end
  else
    self.deliverables.find_by_creator_id(student_id)
  end
end

#get_student_grade(student_id) ⇒ Object

To get the student grade for an assignment.


77
78
79
# File 'app/models/assignment.rb', line 77

def get_student_grade student_id
  Grade.get_grade(self.course.id, self.id, student_id)
end

#name_with_typeObject


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/assignment.rb', line 39

def name_with_type
  unless self.course.grading_rule.nil?
    nomenclature = self.course.nomenclature_assignment_or_deliverable.capitalize
  else
    nomenclature = "deliverable"
  end

  if self.task_number.blank?
    task = ""
  else
    task = "Task #{self.task_number}. "
  end

  if self.is_team_deliverable?
    task + self.name + " (Team " + nomenclature + ")"
  else
    task + self.name + " (Individual " + nomenclature + ")"
  end
end

#set_due_date(date, hour, minute) ⇒ Object


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/models/assignment.rb', line 108

def set_due_date date, hour, minute
  self.date = date
  self.hour = hour
  self.minute = minute

  if self.date.blank?
    self.due_date = nil
    return
  end

  if self.hour.blank?
    self.hour = "22"
    self.minute = "0"
  end

  if self.minute.blank?
    self.minute = "0"
  end

  self.due_date = "#{self.date} #{self.hour}:#{self.minute}"
end

#verify_deliverables_submittedObject

To check whether the deliverable is submitted or not.


60
61
62
# File 'app/models/assignment.rb', line 60

def 
  self.deliverables.size <= 0
end