diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 09d357ebf..d10f09ffa 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -18,6 +18,13 @@ class HomeworkAttachController < ApplicationController @project = @homework.bid.courses[0] end + #获取作业的成员 + def get_homework_member homework + @hoemwork_users = users_for_homework(@homework) + @members = members_for_homework(@homework,@hoemwork_users,params[:q]) + @members = paginateHelper @members,10 + end + def index @homeworks = HomeworkAttach.all respond_to do |format| @@ -28,7 +35,7 @@ class HomeworkAttachController < ApplicationController #作业添加成员(参与人员) def add_homework_users - if User.current.admin? || User.current == @homework.user + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) #@homework = HomeworkAttach.find(params[:id]) if params[:membership] if params[:membership][:user_ids] @@ -40,9 +47,7 @@ class HomeworkAttachController < ApplicationController end end @homework.save - @hoemwork_users = users_for_homework(@homework) - @members = members_for_homework(@homework,@hoemwork_users,params[:q]) - @members = paginateHelper @members,10 + get_homework_member @homework respond_to do |format| format.js end @@ -54,12 +59,10 @@ class HomeworkAttachController < ApplicationController #作业删除成员(参与人员) def destory_homework_users #@homework = HomeworkAttach.find(params[:id]) - if User.current.admin? || User.current == @homework.user + if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first homework_user.destroy - @hoemwork_users = users_for_homework(@homework) - @members = members_for_homework(@homework,@hoemwork_users,params[:q]) - @members = paginateHelper @members,10 + get_homework_member @homework respond_to do |format| format.js end @@ -136,11 +139,7 @@ class HomeworkAttachController < ApplicationController @homework = HomeworkAttach.find(params[:bid_id]) course = @homework.bid.courses.first if User.current.admin? || User.current.member_of?(course) - @hoemwork_users = users_for_homework(@homework) - @members = members_for_homework(@homework,@hoemwork_users,params[:q]) - #该课程的学生的集合 - #@members = course.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]}) - @members = paginateHelper @members,10 + get_homework_member @homework else raise "error" end @@ -157,6 +156,7 @@ class HomeworkAttachController < ApplicationController #获取可选成员列表 #homework:作业 #users:该作业所有成员 + #q:模糊匹配的用户的昵称 def members_for_homework homework,users,q homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id not in (:users)", {:role_id => [5, 10],:users => users}).joins(:user).where("users.login like '%#{q}%'") end @@ -165,9 +165,7 @@ class HomeworkAttachController < ApplicationController #@homework = HomeworkAttach.find(params[:id]) if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) #@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]}) - @hoemwork_users = users_for_homework(@homework) - @members = members_for_homework(@homework,@hoemwork_users,params[:q]) - @members = paginateHelper @members,10 + get_homework_member @homework else render_403 :message => :notice_not_authorized end @@ -198,7 +196,7 @@ class HomeworkAttachController < ApplicationController def destroy #@homework = HomeworkAttach.find(params[:id]) - if User.current.admin? || User.current.member_of?(@homework.bid.courses.first) + if User.current.admin? || User.current == @homework if @homework.destroy respond_to do |format| format.html { redirect_to project_for_bid_path @homework.bid } diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index eef630996..0602e52d2 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -177,4 +177,9 @@ module CoursesHelper seem_count = homework.rates(:quality).where("rater_id = ?",User.current).count seem_count > 0 end + + #获取指定作业的所有成员 + def users_for_homework homework + homework.nil? ? [] : (homework.users + [homework.user]) + end end diff --git a/app/models/homework_attach.rb b/app/models/homework_attach.rb index c801885b1..e60d4230b 100644 --- a/app/models/homework_attach.rb +++ b/app/models/homework_attach.rb @@ -14,8 +14,8 @@ class HomeworkAttach < ActiveRecord::Base "user_id" acts_as_attachable - def addjours user_id,message,status = 0,is_comprehensive_evaluation = 0 - jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status,:is_comprehensive_evaluation => is_comprehensive_evaluation) + def addjours user_id,message,status = 0,is_comprehensive_evaluation = 0,reply_id = 0 + jfm = self.journals_for_messages.build(:user_id => user_id,:notes =>message,:status => status,:is_comprehensive_evaluation => is_comprehensive_evaluation,:reply_id => reply_id) jfm.save jfm end diff --git a/app/models/user_score.rb b/app/models/user_score.rb index 3e052f110..bf6f97988 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -122,8 +122,8 @@ class UserScore < ActiveRecord::Base Rails.logger.error "[UserScore#influence] ===> #{operate} is not define." return false end - #rescue => e - #Rails.logger.error "[UserScore#influence] ===> Exception: #{e}." + rescue => e + Rails.logger.error "[UserScore#influence] ===> Exception: #{e}." end # 前略·技术得分 diff --git a/app/views/bids/_homework_list.html.erb b/app/views/bids/_homework_list.html.erb index 0f605d6fa..18778f5e9 100644 --- a/app/views/bids/_homework_list.html.erb +++ b/app/views/bids/_homework_list.html.erb @@ -90,10 +90,12 @@ <% end %>
高校课程实践社区 | +<%= l(:label_user_location) %> : | + +
<%= link_to request.host()+"/courses", :controller => 'projects', :action => 'course'%> | +<%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> > + <%= link_to(@homework.bid.courses.first.name.to_s, homework_project_path(@homework.bid.courses.first)) if @homework.bid.courses.first%> > + <%=link_to(@homework.bid.name, respond_path(@homework.bid)) %> > <%= link_to "修改作业",edit_homework_attach_path(@homework)%> |
+
<%=raw l(:label_edit_homework)%>
高校课程实践社区 | +<%= l(:label_user_location) %> : | + +
<%= link_to request.host()+"/courses", :controller => 'projects', :action => 'course'%> | +<%=link_to "主页", home_path %> > <%=link_to l(:label_course_practice), :controller => 'projects', :action => 'course' %> > + <%= link_to(@bid.courses.first.name.to_s, homework_project_path(@bid.courses.first)) if @bid.courses.first%> > + <%=link_to(@bid.name, respond_path(@bid)) %> > <%= link_to "创建作业", new_homework_attach_path(@bid)%> |
+
<%=h l(:label_new_homework)%>