Class: PeerEvaluationController

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

Constant Summary collapse

@@questions =
[
    "What was this team member's most significant positive contribution to the team?",
    "In what ways could this team member improve his/her contribution to team meetings?",
    "In what ways could this team member improve his/her contribution to the team's deliverables? ",
    "Please provide feedback on the progress of each individual's improvement objective:"
]
@@point_allocation =
"Point allocations"

Instance Method Summary collapse

Methods inherited from ApplicationController

#robot?

Instance Method Details

#complete_evaluationObject



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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'app/controllers/peer_evaluation_controller.rb', line 114

def complete_evaluation
  ex = nil

  begin
    @questions = @@questions

    @team = Team.find(params[:id])
    @users = @team.members

    @author = User.find(current_user.id)

    user_counter = 0
    question_counter = 0
    @users.each do |user|
      @questions.each do |question|
        @evaluation = PeerEvaluationReview.where(:author_id => @author.id, :recipient_id => user.id, :team_id => @team.id, :question => question).first
        if (@evaluation.nil?)
          @evaluation = PeerEvaluationReview.new(
              :author_id => @author.id,
              :recipient_id => user.id,
              :team_id => @team.id,
              :question => question,
              :answer => params[:peer_evaluation_review][(@questions.size*user_counter + question_counter).to_s][:answer],
              :sequence_number => question_counter
          )
        else
          @evaluation.answer = params[:peer_evaluation_review][(@questions.size*user_counter + question_counter).to_s][:answer]
        end
        @evaluation.save!
        question_counter += 1
      end

      user_counter += 1
      question_counter = 0
    end

    alloc_counter = 0
    alloc_answer = ""
    @users.each do |user|
      alloc_answer << user.human_name + ":" + params[:allocations][alloc_counter.to_s] + " "
      alloc_counter += 1
    end

    allocation = PeerEvaluationReview.where(:author_id => @author.id, :team_id => @team.id, :question => @@point_allocation).first
    if (allocation.nil?)
      allocation = PeerEvaluationReview.new(
          :author_id => @author.id,
          :team_id => @team.id,
          :question => @@point_allocation,
          :answer => alloc_answer,
          :sequence_number => question_counter
      )
    else
      allocation.answer = alloc_answer
    end
    allocation.save!
  rescue => e
    ex = e
  ensure
    respond_to do |format|
      # html request
      format.html do
        # an exception was thrown, just re-throw the exception because the original code did not provide a user friendly message for exceptions
        unless ex.nil?
          raise ex
        end

        flash[:notice] = "Thank you for completing the peer evaluation form."
        redirect_to(peer_evaluation_path(@team.course, @team.id))
      end

      # ajax request
      format.json do
        unless ex.nil?
          render :json => {:code => "failed", :message => "Automatic save failed."}
        else
          render :json => {:code => "success", :message => ""} # auto-save success message won't be shown by client
        end
      end
    end

  end # begin..rescue..ensure..end
end

#complete_reportObject



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'app/controllers/peer_evaluation_controller.rb', line 237

def complete_report
  if has_permissions_or_redirect(:staff, root_path)
    if params[:commit] == "Save And Email All"
      send_email = true
    else
      send_email = false
    end

    @team = Team.find(params[:id])
    @users = @team.members
    @users.each do |user|
      #Step 1 save feedback
      feedback = params[:peer_evaluation_report][user.id.to_s][:feedback]
      report = PeerEvaluationReport.where(:recipient_id => user.id, :team_id => @team.id).first
      if report.nil?
        report = PeerEvaluationReport.new(:recipient_id => user.id, :team_id => @team.id, :feedback => feedback)
      else
        report.feedback = feedback
      end
      report.save!

      faculty = @team.faculty_email_addresses()
      #Step 2 email feedback
      if send_email
        options = {:to => user.email, :cc => faculty, :subject => "Peer evaluation feedback from team #{@team.name}",
                   :message => feedback.gsub("\n", "<br/>"), :url => "", :url_label => ""}
        GenericMailer.email(options).deliver
        report.email_date = Time.now
        report.save!
      end
    end

    flash[:notice] = "Reports have been successfully saved."
    redirect_to(peer_evaluation_path(@team.course, @team.id))
  end
end

#complete_setupObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/peer_evaluation_controller.rb', line 39

def complete_setup
  if has_permissions_or_redirect(:staff, root_path)
    @team = Team.find(params[:id])

    counter = 0
    @team.members.each do |member|
      if (PeerEvaluationLearningObjective.where(:team_id => @team.id, :user_id => member.id).first.nil?)
        @objective = PeerEvaluationLearningObjective.new(
            :team_id => params[:id],
            :user_id => member.id,
            :learning_objective => params[:peer_evaluation_learning_objective][counter.to_s][:learning_objective]
        )
      else
        @objective = PeerEvaluationLearningObjective.where(:team_id => @team.id, :user_id => member.id).first
        @objective.learning_objective = params[:peer_evaluation_learning_objective][counter.to_s][:learning_objective]
      end

      @objective.save!
      counter += 1
    end

    flash[:notice] = "Learning objectives have been updated."
    redirect_to(peer_evaluation_path(@team.course, @team.id))
  end
end

#edit_evaluationObject



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
# File 'app/controllers/peer_evaluation_controller.rb', line 66

def edit_evaluation
  @questions = @@questions
  @team = Team.find(params[:id])
  @users = @team.members
  @author = User.find(current_user.id)
  @answers = []
  @point_allocations = {}
  @review = PeerEvaluationReview.new

  @on_team = false
  @users.each do |user|
    if (user.human_name == current_user.human_name)
      @on_team = true
    end
  end

  if (@on_team == false)
    if (current_user.is_staff || current_user.is_admin)
      return
    end
    flash[:error] = "You are not on team #{@team.name}"
    redirect_to(peer_evaluation_path(@team.course, @team.id))
    return
  end

  @users.each do |user|
    @questions.each do |question|
      evaluation = PeerEvaluationReview.where(:author_id => @author.id, :recipient_id => user.id, :team_id => @team.id, :question => question).first
      if (evaluation.nil?)
        @answers << ""
      else
        @answers << evaluation.answer
      end
    end
  end

  allocation = PeerEvaluationReview.where(:author_id => @author.id, :team_id => @team.id, :question => @@point_allocation).first
  unless allocation.nil? || allocation.answer.nil?
    match_array = allocation.answer.scan /((\w| )*):(\d*)\s*/
    match_array.each do |match|
      name = match[0]
      points = match[2]
      @point_allocations[name] = points
    end
  end
end

#edit_reportObject



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'app/controllers/peer_evaluation_controller.rb', line 198

def edit_report
  if has_permissions_or_redirect(:staff, root_path)
    @team = Team.find(params[:id])
    @users = @team.members

    @report = PeerEvaluationReport.new

    @incompletes = Array.new
    @team.members.each do |member|
      unless PeerEvaluationReview.is_completed_for?(member.id, @team.id)
        @incompletes << (member)
      end
    end

    @reportArray = Array.new(@users.size)
    user_counter = 0
    @users.each do |user|
      @reportArray[user_counter] = generate_report_for_student(user.id, @team.id)
      user_counter += 1
    end

    @report_allocations = {}
    @point_allocations = Hash.new { |hash, key| hash[key] = {} } #two dimensional hash
    @users.each do |user|
      allocation = PeerEvaluationReview.where(:author_id => user.id, :team_id => @team.id, :question => @@point_allocation).first
      unless allocation.nil?
        @report_allocations[user.human_name] = allocation.answer

        match_array = allocation.answer.scan /((\w| )*):(\d*)\s*/
        match_array.each do |match|
          name = match[0]
          points = match[2]
          @point_allocations[user.human_name][name] = points
        end
      end
    end
  end
end

#edit_setupObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/peer_evaluation_controller.rb', line 20

def edit_setup
  if has_permissions_or_redirect(:staff, root_path)
    @team = Team.find(params[:id])
    @users = @team.members

    @objective = PeerEvaluationLearningObjective.new

    @objectives = []
    @team.members.each do |member|
      objective = PeerEvaluationLearningObjective.where(:team_id => @team.id, :user_id => member.id).first
      if objective.nil?
        @objectives << PeerEvaluationLearningObjective.new
      else
        @objectives << objective
      end
    end
  end
end

#email_reportsObject



275
276
# File 'app/controllers/peer_evaluation_controller.rb', line 275

def email_reports
end

#index_for_courseObject



13
14
15
16
17
18
# File 'app/controllers/peer_evaluation_controller.rb', line 13

def index_for_course
  @course = Course.find(params[:course_id])
  authorize! :peer_evaluation, @course

  @teams = Team.where(:course_id => params[:course_id])
end