Class: Presentation

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_by_presenter(current_user) ⇒ Object



71
72
73
74
75
76
# File 'app/models/presentation.rb', line 71

def self.find_by_presenter(current_user)
  # Find everything where the passed in person is either the assignee
  # or is on the presentation's team
  teams = Team.find_by_person(current_user)
  Presentation.find_by_user_and_teams(current_user, teams)
end

.find_by_user_and_teams(current_user, teams) ⇒ Object



78
79
80
81
82
83
84
85
86
# File 'app/models/presentation.rb', line 78

def self.find_by_user_and_teams(current_user, teams)
  team_condition = ""
  if !teams.empty?
    team_condition = "team_id IN ("
    team_condition << teams.collect { |t| t.id }.join(',')
    team_condition << ") OR "
  end
  Presentation.where(team_condition + "(team_id IS NULL AND user_id = #{current_user.id})")
end

.find_comments(feedbacks, questions) ⇒ Object



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/presentation.rb', line 122

def self.find_comments (feedbacks, questions)

  # code for comments

  feedback_ids = []
  question_comments = Hash.new

  feedbacks.each do |f|
    feedback_ids << f.id
  end

  questions.each do |q|
    unless q.deleted?

      comments = " "
      found_answers = PresentationFeedbackAnswer.where(:feedback_id => feedback_ids, :question_id => q.id)
      found_answers.each do |f|
        unless (f.comment == "") || (f.comment.nil?)
          comments = comments + "*- " + f.comment
        end
      end
      question_comments[q.id] = comments
    end
  end
  return question_comments
end

.find_ratings(feedbacks, questions) ⇒ Object



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
# File 'app/models/presentation.rb', line 95

def self.find_ratings (feedbacks, questions)

  #code for ratings
  presentation_answers = []
  question_ratings = Hash.new
  ratings= []

  feedbacks.each do |f|
    feedback_answers = PresentationFeedbackAnswer.find(:all, :conditions => {:feedback_id => f.id})
    presentation_answers << feedback_answers
  end

  questions.each do |q|
    unless q.deleted?
      question_ratings[q.id] = [0, 0, 0, 0]
    end
  end

  presentation_answers.each do |a|
    a.each do |ans|
      ratings = question_ratings[ans.question_id]
      ratings[ans.rating-1] += 1
    end
  end
  return question_ratings
end

Instance Method Details

#can_view_feedback?(user) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
92
93
# File 'app/models/presentation.rb', line 88

def can_view_feedback?(user)
  if presenter?(user) || user.is_staff? || user.is_admin
    return true
  end
  return false
end

#has_given_feedback?(user) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
# File 'app/models/presentation.rb', line 60

def has_given_feedback?(user)
  @presentation_feedbacks = PresentationFeedback.where("evaluator_id = :uid AND presentation_id = :pid",
                                                       {:uid => user.id, :pid => self.id})

  if @presentation_feedbacks[0] == nil
    return false
  else
    return true
  end
end

#is_team_presentation?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/presentation.rb', line 44

def is_team_presentation?
  !self.team.blank?
end

#presenterObject



48
49
50
51
52
53
54
# File 'app/models/presentation.rb', line 48

def presenter
  if self.is_team_presentation?
    team.name
  else
    user.human_name
  end
end

#presenter?(current_user) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/presentation.rb', line 56

def presenter?(current_user)
  current_user == self.user || current_user.teams.include?(team)
end

#send_presentation_feedback_email(url) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'app/models/presentation.rb', line 157

def send_presentation_feedback_email(url)

  mail_to = self.user_email
  message = "See feedback for your presentation "
  message += self.name + " for " + self.course.name

  subject = ""
  subject = subject + self.course.short_name unless self.course.short_name.nil?
  subject = subject + "Feedback for presentation " + self.name

  options = {:to => mail_to,
             :subject => subject,
             :message => message,
             :url_label => "View feedback",
             :url => url
  }
  GenericMailer.email(options).deliver
end

#team_or_user_for_presenter?Boolean

Returns:

  • (Boolean)


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

def team_or_user_for_presenter?
  if team_id.blank? && user_id.blank?
    errors.add(:base, "Can't create a presentation without a team or person giving it")
  end
end

#user_emailObject



149
150
151
152
153
154
155
# File 'app/models/presentation.rb', line 149

def user_email
  if !self.team_id.nil?
    self.team.email
  else
    self.user.email
  end
end