Class: Deliverable
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Deliverable
- Defined in:
- app/models/deliverable.rb
Class Method Summary collapse
- .find_by_user_and_teams(user, teams) ⇒ Object
- .find_current_by_user(user) ⇒ Object
- .find_past_by_user(user) ⇒ Object
- .get_deliverables(course_id, faculty_id, options) ⇒ Object
Instance Method Summary collapse
-
#assignment_due_date ⇒ Object
Todo: update this when we are no longer using old data.
-
#assignment_name ⇒ Object
Todo: update this when we are no longer using old data.
-
#current_attachment ⇒ Object
To check the current attachment for the deliverable.
-
#editable?(current_user) ⇒ Boolean
To check if the current user can change/edit the deliverable.
-
#get_grade_status ⇒ Object
Todo: rename get_grade_status to grade_status To get the status of the deliverable for whether it is graded or not.
- #get_graded_by ⇒ Object
-
#get_status_for_every_individual(student_id) ⇒ Object
Todo: rename get_status_for_every_individual to status_for_every_individual To get the status of deliverable by student for is it graded or not.
-
#has_feedback? ⇒ Boolean
To see if this deliverable has a feedback or not.
- #inaccurate_course_and_assignment_check ⇒ Object
-
#is_team_deliverable? ⇒ Boolean
To check if it is a team deliverable.
-
#is_visible_to_student? ⇒ Boolean
To check if the grade received for this deliverable is visible to the students or not.
- #last_graded_by_for_every_individual(student_id) ⇒ Object
-
#owner_email ⇒ Object
To get the email_id/team_id who has submitted the deliverable.
-
#owner_name ⇒ Object
To get the name of the person/team who has submitted the deliverable.
- #owner_name_for_filename ⇒ Object
-
#send_deliverable_feedback_email(url, faculty_email = nil) ⇒ Object
To send the feedback in the email back to the students.
-
#send_deliverable_upload_email(url) ⇒ Object
To send the deliverable submitted mail to the primary and secondary faculty.
-
#send_feedback_to_student(member_id, member_email, url, faculty_email = nil) ⇒ Object
To send the feedback to the each student along with the score received respectively.
-
#unique_course_task_owner? ⇒ Boolean
To get the owner of the deliverable.
-
#update_feedback_and_notes(params) ⇒ Object
To update the feedback and the private notes by faculty.
-
#update_grade(params, is_student_visible, current_user_id) ⇒ Object
To update the grade received by the student.
- #update_team ⇒ Object
Class Method Details
.find_by_user_and_teams(user, teams) ⇒ Object
213 214 215 216 217 218 219 220 221 |
# File 'app/models/deliverable.rb', line 213 def self.find_by_user_and_teams(user, teams) team_condition = "" if !teams.empty? team_condition = "team_id IN (" team_condition << teams.collect { |t| t.id }.join(',') team_condition << ") OR " end Deliverable.find(:all, :conditions => team_condition + "(team_id IS NULL AND creator_id = #{user.id})") end |
.find_current_by_user(user) ⇒ Object
199 200 201 202 203 204 |
# File 'app/models/deliverable.rb', line 199 def self.find_current_by_user(user) # Find everything where the passed in person is either the creator # or is on the deliverable's team current_teams = Team.find_current_by_person(user) Deliverable.find_by_user_and_teams(user, current_teams) end |
.find_past_by_user(user) ⇒ Object
206 207 208 209 210 211 |
# File 'app/models/deliverable.rb', line 206 def self.find_past_by_user(user) # Find everything where the passed in person is either the creator # or is on the deliverable's team past_teams = Team.find_past_by_person(user) Deliverable.find_by_user_and_teams(user, past_teams) end |
.get_deliverables(course_id, faculty_id, options) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/models/deliverable.rb', line 62 def self.get_deliverables(course_id, faculty_id, ) # sql_template = "SELECT d.id FROM deliverables d INNER JOIN teams t ON d.team_id = t.id INNER JOIN team_assignments ta ON t.id = ta.team_id INNER JOIN users u1 ON d.creator_id = u1.id INNER JOIN users u2 ON ta.user_id = u2.id" sql_template = "SELECT d.id FROM deliverables d LEFT JOIN teams t ON d.team_id = t.id LEFT JOIN team_assignments ta ON t.id = ta.team_id LEFT JOIN users u1 ON d.creator_id = u1.id LEFT JOIN users u2 ON ta.user_id = u2.id" where_clause_course = " WHERE d.course_id = ?" where_clause_team_deliverable = " AND d.team_id IS NOT NULL AND t.primary_faculty_id = ?" where_clause_individual_deliverable = " AND d.team_id IS NULL AND d.creator_id IN (SELECT inner_ta.user_id FROM teams inner_t, team_assignments inner_ta WHERE inner_t.id = inner_ta.team_id AND inner_t.primary_faculty_id = ? AND course_id = ?)" where_clause_search = " AND (u1.first_name ILIKE ? OR u1.last_name ILIKE ? OR u1.human_name ILIKE ? OR u1.email ILIKE ? OR u1.webiso_account ILIKE ? OR u2.first_name ILIKE ? OR u2.last_name ILIKE ? OR u2.human_name ILIKE ? OR u2.email ILIKE ? OR u2.webiso_account ILIKE ? OR t.name ILIKE ?)" queue = [] # 1. Are there teams in this course? If there are, and the "filter by teams is on", filter by teams # 2. If there are no teams in the course, and if this deliverable is an individual deliverable, # show deliverables for individuals who are in the faculty's teams only. # 3. Otherwise, show every deliverable course_has_teams = Team.where(:course_id => course_id).any? has_search_string = ![:search_string].nil? selected_my_team = ([:is_my_team] == 1) if has_search_string search_string = [:search_string] end if !course_has_teams if has_search_string sql = sql_template + where_clause_course + where_clause_search deliverable_ids = Deliverable.find_by_sql([sql, course_id, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string]).uniq else sql = sql_template + where_clause_course deliverable_ids = Deliverable.find_by_sql([sql, course_id]).uniq end elsif selected_my_team if has_search_string sql = sql_template + where_clause_course + where_clause_team_deliverable + where_clause_search team_deliverable_ids = Deliverable.find_by_sql([sql, course_id, faculty_id, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string]).uniq sql = sql_template + where_clause_course + where_clause_individual_deliverable + where_clause_search individual_deliverable_ids = Deliverable.find_by_sql([sql, course_id, faculty_id, course_id, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string]).uniq else sql = sql_template + where_clause_course + where_clause_team_deliverable team_deliverable_ids = Deliverable.find_by_sql([sql, course_id, faculty_id]).uniq sql = sql_template + where_clause_course + where_clause_individual_deliverable individual_deliverable_ids = Deliverable.find_by_sql([sql, course_id, faculty_id, course_id]).uniq end deliverable_ids = [] team_deliverable_ids.each do |team_deliverable_id| deliverable_ids << team_deliverable_id end individual_deliverable_ids.each do |individual_deliverable_id| deliverable_ids << individual_deliverable_id end else if has_search_string sql = sql_template + where_clause_course + where_clause_search deliverable_ids = Deliverable.find_by_sql([sql, course_id, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string, search_string]).uniq else sql = sql_template + where_clause_course deliverable_ids = Deliverable.find_by_sql([sql, course_id]).uniq end end deliverables = [] deliverable_ids.each do |deliverable_id| deliverables << Deliverable.find(deliverable_id) end return deliverables end |
Instance Method Details
#assignment_due_date ⇒ Object
Todo: update this when we are no longer using old data
380 381 382 383 384 |
# File 'app/models/deliverable.rb', line 380 def assignment_due_date if self.assignment self.assignment.due_date end end |
#assignment_name ⇒ Object
Todo: update this when we are no longer using old data
371 372 373 374 375 376 377 |
# File 'app/models/deliverable.rb', line 371 def assignment_name if self.assignment.nil? self.name else self.assignment.name end end |
#current_attachment ⇒ Object
To check the current attachment for the deliverable
169 170 171 |
# File 'app/models/deliverable.rb', line 169 def .first end |
#editable?(current_user) ⇒ Boolean
To check if the current user can change/edit the deliverable
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'app/models/deliverable.rb', line 302 def editable?(current_user) return true if self.course.faculty.include?(current_user) if self.is_team_deliverable? unless self.team.is_user_on_team?(current_user) unless (current_user.is_staff?)||(current_user.is_admin?) return false end end end if !self.is_team_deliverable? unless current_user == self.creator unless (current_user.is_staff?)||(current_user.is_admin?) return false end end end return true end |
#get_grade_status ⇒ Object
Todo: rename get_grade_status to grade_status To get the status of the deliverable for whether it is graded or not.
388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'app/models/deliverable.rb', line 388 def get_grade_status if self.is_team_deliverable? return :ungraded if self.team.nil? self.team.members.each do |member| status = self.get_status_for_every_individual(member.id) if status != :graded return status end end return :graded else return self.get_status_for_every_individual(self.creator_id) end end |
#get_graded_by ⇒ Object
428 429 430 431 432 433 434 |
# File 'app/models/deliverable.rb', line 428 def get_graded_by if self.is_team_deliverable? return self.last_graded_by_for_every_individual(self.team.members[0].id) else return self.last_graded_by_for_every_individual(self.creator_id) end end |
#get_status_for_every_individual(student_id) ⇒ Object
Todo: rename get_status_for_every_individual to status_for_every_individual To get the status of deliverable by student for is it graded or not.
405 406 407 408 409 410 411 412 413 414 415 |
# File 'app/models/deliverable.rb', line 405 def get_status_for_every_individual(student_id) return :unknonwn if self.assignment.nil? #(guard for old deliverables) grade = Grade.get_grade(self.course.id, self.assignment.id, student_id) if grade.nil? return :ungraded elsif !grade.is_student_visible? return :drafted else return :graded end end |
#has_feedback? ⇒ Boolean
To see if this deliverable has a feedback or not
224 225 226 |
# File 'app/models/deliverable.rb', line 224 def has_feedback? !self.feedback_comment.blank? or !self.feedback_file_name.blank? end |
#inaccurate_course_and_assignment_check ⇒ Object
418 419 420 421 422 423 424 425 426 |
# File 'app/models/deliverable.rb', line 418 def inaccurate_course_and_assignment_check if self.assignment if self.assignment.course_id != self.course_id = {:to => "[email protected]", :subject => "inaccurate_course_and_assignment_check #{self.id}", :message => "The subject says it all", :url => "", :url_label => ""} GenericMailer.email().deliver end end end |
#is_team_deliverable? ⇒ Boolean
To check if it is a team deliverable
164 165 166 |
# File 'app/models/deliverable.rb', line 164 def is_team_deliverable? self.is_team_deliverable end |
#is_visible_to_student? ⇒ Boolean
To check if the grade received for this deliverable is visible to the students or not.
331 332 333 334 335 |
# File 'app/models/deliverable.rb', line 331 def is_visible_to_student? grade = Grade.get_grade(self.course.id, self.assignment.id, creator_id) grade.try(:is_student_visible) || false # grade_status == "graded" end |
#last_graded_by_for_every_individual(student_id) ⇒ Object
436 437 438 439 440 441 442 443 444 |
# File 'app/models/deliverable.rb', line 436 def last_graded_by_for_every_individual(student_id) return :unknonwn if self.assignment.nil? #(guard for old deliverables) grade = Grade.get_grade(self.course.id, self.assignment.id, student_id) if grade.nil? return nil else return User.find_by_id(grade.last_graded_by) unless grade.last_graded_by.nil? end end |
#owner_email ⇒ Object
To get the email_id/team_id who has submitted the deliverable
191 192 193 194 195 196 197 |
# File 'app/models/deliverable.rb', line 191 def owner_email if self.is_team_deliverable? team.email else creator.email end end |
#owner_name ⇒ Object
To get the name of the person/team who has submitted the deliverable
174 175 176 177 178 179 180 |
# File 'app/models/deliverable.rb', line 174 def owner_name if self.is_team_deliverable? team.name unless team.blank? # 1/25/2014, why is it possible for team to be blank? else creator.human_name end end |
#owner_name_for_filename ⇒ Object
182 183 184 185 186 187 188 |
# File 'app/models/deliverable.rb', line 182 def owner_name_for_filename if self.is_team_deliverable? team.name else "#{creator.last_name} #{creator.first_name}" end end |
#send_deliverable_feedback_email(url, faculty_email = nil) ⇒ Object
To send the feedback in the email back to the students.
291 292 293 294 295 296 297 298 299 |
# File 'app/models/deliverable.rb', line 291 def send_deliverable_feedback_email(url, faculty_email=nil) if self.is_team_deliverable? self.team.members.each do |member| send_feedback_to_student(member.id, member.email, url, faculty_email) end else send_feedback_to_student(self.creator_id, self.creator.email, url, faculty_email) end end |
#send_deliverable_upload_email(url) ⇒ Object
To send the deliverable submitted mail to the primary and secondary faculty
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'app/models/deliverable.rb', line 229 def send_deliverable_upload_email(url) mail_to = [] unless self.team.nil? || self.team.primary_faculty.nil? mail_to << self.team.primary_faculty.email end unless self.team.nil? || self.team.secondary_faculty.nil? mail_to << self.team.secondary_faculty.email end if mail_to.empty? return end = self.owner_name + " has submitted a deliverable for " if !self.assignment.task_number.nil? and self.assignment.task_number != "" and !self.assignment.name.nil? and self.assignment.name !="" += "#{self.assignment.name} (#{self.assignment.task_number}) of " end += self.course.name = {:to => mail_to, :subject => "Deliverable submitted for " + self.course.name + " by " + self.owner_name, :message => , :url_label => "View this deliverable", :url => url } GenericMailer.email().deliver end |
#send_feedback_to_student(member_id, member_email, url, faculty_email = nil) ⇒ Object
To send the feedback to the each student along with the score received respectively.
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'app/models/deliverable.rb', line 258 def send_feedback_to_student(member_id, member_email, url, faculty_email=nil) feedback = "Feedback has been submitted for " if !self.assignment.task_number.nil? and self.assignment.task_number != "" and !self.assignment.name.nil? and self.assignment.name !="" feedback += "#{self.assignment.name} (#{self.assignment.task_number}) of " end feedback +=self.course.name if self.feedback_comment feedback +="\n\nFeedback Given:\n" feedback += self.feedback_comment feedback += "\n" end given_grade=Grade.get_grade(self.course.id, self.assignment_id, member_id) unless given_grade.nil? feedback += "\nGrade earned for this " feedback += self.course.nomenclature_assignment_or_deliverable feedback += " is: " feedback += given_grade.score.to_s feedback+= " / " feedback += self.assignment.formatted_maximum_score feedback += "\n" end = {:to => member_email, :cc => faculty_email, :subject => "Feedback for " + self.course.name, :message => feedback, :url_label => "View this deliverable", :url => url} GenericMailer.email().deliver end |
#unique_course_task_owner? ⇒ Boolean
To get the owner of the deliverable
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/models/deliverable.rb', line 150 def unique_course_task_owner? if self.is_team_deliverable? duplicate = Deliverable.where(:course_id => self.course_id, :assignment_id => self.assignment_id, :team_id => self.team_id).first type = "team" else duplicate = Deliverable.where(:course_id => self.course_id, :assignment_id => self.assignment_id, :team_id => nil, :creator_id => self.creator_id).first type = "individual" end if duplicate && duplicate.id != self.id errors.add(:base, "Can't create another #{type} deliverable for the same course and task. Please edit the existing one.") end end |
#update_feedback_and_notes(params) ⇒ Object
To update the feedback and the private notes by faculty
338 339 340 341 342 343 344 345 346 347 348 |
# File 'app/models/deliverable.rb', line 338 def update_feedback_and_notes(params) self.feedback_comment = params[:feedback_comment] self.private_note = params[:private_note] unless params[:feedback].blank? self.feedback = params[:feedback] end if self.has_feedback? self.feedback_updated_at = Time.now end self.save end |
#update_grade(params, is_student_visible, current_user_id) ⇒ Object
To update the grade received by the student
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'app/models/deliverable.rb', line 351 def update_grade(params, is_student_visible, current_user_id) error_msg = [] if self.assignment.is_team_deliverable? self.team.members.each do |user| score = params[:"#{user.id}"] if Grade.give_grade(self.course_id, self.assignment.id, user.id, score, is_student_visible, current_user_id)==false error_msg << "Grade given to " + user.human_name + " is invalid!" end end else score = params[:"#{self.creator_id}"] unless Grade.give_grade(self.course_id, self.assignment.id, self.creator_id, score, is_student_visible, current_user_id) error_msg << "Grade given to " + self.creator.human_name + " is invalid!" end end error_msg end |
#update_team ⇒ Object
322 323 324 325 326 327 328 |
# File 'app/models/deliverable.rb', line 322 def update_team # Look up the team this user is on if it is a team deliverable Team.where(:course_id => self.course.id).each do |team| answer = team.members.include?(self.creator) self.team = team if team.members.include?(self.creator) end end |