Class: Team

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
PeopleInACollection
Defined in:
app/models/team.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PeopleInACollection

#added_people, #detect_if_list_changed, #map_member_strings_to_users, #remove_empty_fields, #removed_people, #update_collection_members, #validate_members

Instance Attribute Details

#members_overrideObject

When assigning faculty to a page, the user types in a series of strings that then need to be processed :members_override is a temporary variable that is used to do validation of the strings (to verify that they are people in the system) and then to save the people in the faculty association.



26
27
28
# File 'app/models/team.rb', line 26

def members_override
  @members_override
end

#team_members_list_changedObject

Returns the value of attribute team_members_list_changed.



15
16
17
# File 'app/models/team.rb', line 15

def team_members_list_changed
  @team_members_list_changed
end

Class Method Details

.find_by_person(user) ⇒ Object



63
64
65
# File 'app/models/team.rb', line 63

def self.find_by_person(user)
  Team.find_by_sql("SELECT t.* FROM  teams t INNER JOIN team_assignments ta ON ( t.id = ta.team_id) WHERE ta.user_id = #{user.id}")
end

.find_current_by_person(user) ⇒ Object



67
68
69
70
71
# File 'app/models/team.rb', line 67

def self.find_current_by_person(user)
  current_year = Date.today.year()
  current_semester = AcademicCalendar.current_semester()
  Team.find_by_sql(["SELECT t.* FROM  teams t INNER JOIN team_assignments ta ON ( t.id = ta.team_id) INNER JOIN courses c ON (t.course_id = c.id) WHERE ta.user_id = ? AND c.semester = ? AND c.year = ?", user.id, current_semester, current_year])
end

.find_past_by_person(user) ⇒ Object



73
74
75
76
77
# File 'app/models/team.rb', line 73

def self.find_past_by_person(user)
  current_year = Date.today.year()
  current_semester = AcademicCalendar.current_semester()
  Team.find_by_sql(["SELECT t.* FROM  teams t INNER JOIN team_assignments ta ON ( t.id = ta.team_id) INNER JOIN courses c ON (t.course_id = c.id) WHERE ta.user_id = ? AND (c.semester <> ? OR c.year <> ?)", user.id, current_semester, current_year])
end

Instance Method Details

#clean_up_dataObject



34
35
36
# File 'app/models/team.rb', line 34

def clean_up_data
  self.name = self.name.strip() unless self.name.blank?
end

#clone_to_another_course(destination_course_id) ⇒ Object



141
142
143
144
145
146
147
148
# File 'app/models/team.rb', line 141

def clone_to_another_course(destination_course_id)
  destination_course = Course.find(destination_course_id)
  clone = self.clone
  clone.member_ids = self.member_ids
  clone.course_id = destination_course_id
  clone.name = self.name + " - " + destination_course.short_or_course_number
  clone.save
end

#copy_peer_evaluation_dates_from_courseObject



38
39
40
41
# File 'app/models/team.rb', line 38

def copy_peer_evaluation_dates_from_course
  self.peer_evaluation_first_email = self.course.peer_evaluation_first_email if self.peer_evaluation_first_email.blank?
  self.peer_evaluation_second_email = self.course.peer_evaluation_second_email if self.peer_evaluation_second_email.blank?
end

#faculty_email_addressesObject



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/models/team.rb', line 113

def faculty_email_addresses
  faculty = []
  unless self.primary_faculty_id.nil?
    from_address = User.find_by_id(self.primary_faculty_id).email
    faculty << from_address
  end
  unless self.secondary_faculty_id.nil?
    #if there is a coach listed we want the email to come from the coach
    from_address = User.find_by_id(self.secondary_faculty_id).email
    faculty << from_address
  end
  return faculty
end

#google_groupObject



59
60
61
# File 'app/models/team.rb', line 59

def google_group
  self.email.split('@')[0] #strips out @sv.cmu.edu
end

#is_person_on_team?(person) ⇒ Boolean

Returns:

  • (Boolean)


127
128
129
130
# File 'app/models/team.rb', line 127

def is_person_on_team?(person)
  user = User.find(person.id)
  self.members.include?(user)
end

#is_user_on_team?(user) ⇒ Boolean

Returns:

  • (Boolean)


132
133
134
# File 'app/models/team.rb', line 132

def is_user_on_team?(user)
  self.members.include?(user)
end

#need_to_update_google_list?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'app/models/team.rb', line 43

def need_to_update_google_list?
  if self.email_changed?
    self.updating_email = true
  end
end

#peer_evaluation_message_oneObject



136
137
138
139
# File 'app/models/team.rb', line 136

def peer_evaluation_message_one
  return "Action Required: please do this peer evaluation survey\n\n by the end of " + self.course.peer_evaluation_second_email.to_date.to_formatted_s(:long)

end

#show_addresses_for_mailing_listObject



101
102
103
104
105
106
107
108
109
110
111
# File 'app/models/team.rb', line 101

def show_addresses_for_mailing_list
  begin
    @members = []
    GoogleWrapper.retrieve_all_members(self.google_group).each do |member|
      @members << member.member_id.sub('@west.cmu.edu', '@sv.cmu.edu')
    end
    return @members
  rescue GDataError => e
    return [pretty_print_google_error(e)]
  end
end

#update_email_addressObject



80
81
82
# File 'app/models/team.rb', line 80

def update_email_address
  self.email = generate_email_name unless self.name.blank?
end

#update_mailing_listObject



49
50
51
52
53
54
55
56
# File 'app/models/team.rb', line 49

def update_mailing_list
  tmp = self.updating_email
  if self.updating_email
    Delayed::Job.enqueue(GoogleMailingListJob.new(self.email, self.email_was, self.members, self.name, "#{self.name} for course #{self.course.name}", self.id, "teams"))
    self.course.updating_email = true
    self.course.save
  end
end

#update_membersObject

When modifying validate_members or update_members, modify the same code in course.rb Todo - move to a higher class or try as a mixin



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/models/team.rb', line 87

def update_members
  return "" if members_override.nil?

  self.members_override = members_override.select { |name| name != nil && name.strip != "" }
  #if the list has changed
  if (self.members_override.sort != self.members.collect { |person| person.human_name }.sort)
    self.updating_email = true
    list = map_member_strings_to_users(self.members_override)
    raise "Error converting members_override to IDs!" if list.include?(nil)
    self.members = list
  end
  members_override = nil
end

#validate_team_membersObject



30
31
32
# File 'app/models/team.rb', line 30

def validate_team_members
  validate_members :members_override
end