diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 78ab33477..7e7126173 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -2,8 +2,8 @@ class StudentWorkController < ApplicationController layout "base_courses" include StudentWorkHelper before_filter :find_homework, :only => [:new, :index, :create] - before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score] - before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score] + before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work] + before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work] before_filter :author_of_work, :only => [:edit, :update, :destroy] def index @@ -166,6 +166,22 @@ class StudentWorkController < ApplicationController end end + #为作品点赞 + def praise_student_work + pt = PraiseTread.new + pt.user_id = User.current.id + pt.praise_tread_object_id = @work.id + pt.praise_tread_object_type = "StudentWork" + pt.praise_or_tread = 1 + if pt.save + respond_to do |format| + format.js + end + else + render_404 + end + end + private #获取作业 def find_homework diff --git a/app/helpers/student_work_helper.rb b/app/helpers/student_work_helper.rb index 94da5f152..990a563c4 100644 --- a/app/helpers/student_work_helper.rb +++ b/app/helpers/student_work_helper.rb @@ -50,4 +50,14 @@ module StudentWorkHelper end result end + + #获取赞的总数 + def praise_homework_count obj_id + PraiseTread.where("praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").count + end + + #判断指定用户是不是已经赞过该作业 + def is_praise_homework user_id, obj_id + PraiseTread.where("user_id = #{user_id} AND praise_tread_object_id = #{obj_id} AND praise_tread_object_type = 'StudentWork'").empty? + end end \ No newline at end of file diff --git a/app/views/student_work/_show.html.erb b/app/views/student_work/_show.html.erb index fd5396b7f..97c6125f7 100644 --- a/app/views/student_work/_show.html.erb +++ b/app/views/student_work/_show.html.erb @@ -15,8 +15,8 @@ <% end%> <% if (@homework.homework_type != 1 || @homework.homework_detail_manual.comment_status == 3) && @work.user != User.current%> -