diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 633160c1..5fc89326 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -450,78 +450,82 @@ class BidsController < ApplicationController # 显示作业课程 # add by nwb def show_courseEx - # flash[:notice] = "" - @membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current)) - @option = [] - @membership.each do |membership| - membership.member_roles.each{|role| - if(role.role_id == 3) - @option << membership.course - end - } - end - - @user = @bid.author - @bidding_project = @bid.biding_projects.all - - if params[:student_id].present? - @temp = [] - @bidding_project.each do |pro| - if pro.project && pro.project.project_status - if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id - @temp << pro - end - end - @temp + if (User.current.logged? && User.current.member_of_course?(@bid.courses.first)) + # flash[:notice] = "" + @membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current)) + @option = [] + @membership.each do |membership| + membership.member_roles.each{|role| + if(role.role_id == 3) + @option << membership.course + end + } end - @bidding_project = @temp - else - #added by nie - @temp = [] - @bidding_project.each do |pro| - if pro.project && pro.project.project_status - @temp << pro - end - @temp - end - if @temp.size > 0 - @bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} - end - #ended - end - if @bid.homework_type == 1 - @homework = HomeworkAttach.new - #@homework_list = @bid.homeworks - #增加作业按评分排序, - @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC") + @user = @bid.author + @bidding_project = @bid.biding_projects.all + if params[:student_id].present? @temp = [] - @homework_list.each do |pro| - if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id + @bidding_project.each do |pro| + if pro.project && pro.project.project_status + if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id + @temp << pro + end + end + @temp + end + @bidding_project = @temp + else + #added by nie + @temp = [] + @bidding_project.each do |pro| + if pro.project && pro.project.project_status @temp << pro end @temp end - @homework_list = @temp + if @temp.size > 0 + @bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade} + end + #ended end - end - respond_to do |format| - if @bid.reward_type == 3 - format.html { - render :layout => 'base_homework' - } - elsif @bid.reward_type == 1 - format.html { - render :layout => 'base_bids' - } - else - format.html { - render :layout => 'base_contest' - } + if @bid.homework_type == 1 + @homework = HomeworkAttach.new + #@homework_list = @bid.homeworks + #增加作业按评分排序, + @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC") + if params[:student_id].present? + @temp = [] + @homework_list.each do |pro| + if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id + @temp << pro + end + @temp + end + @homework_list = @temp + end end - format.api + + respond_to do |format| + if @bid.reward_type == 3 + format.html { + render :layout => 'base_homework' + } + elsif @bid.reward_type == 1 + format.html { + render :layout => 'base_bids' + } + else + format.html { + render :layout => 'base_contest' + } + end + format.api + end + else + render_403 :message => :notice_not_authorized end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f14a637d..7660c050 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -39,7 +39,9 @@ module ApplicationHelper # REVIEW: 目测menu的机制,貌似不是很需要转换,再说 def link_class(label) labels = label.is_a?(Array) ? label : ([] << label) + #a = current_menu_item labels.include?(current_menu_item) ? 'selected' : '' + end #Ended by young # Return true if user is authorized for controller/action, otherwise false diff --git a/app/views/layouts/base_homework.html.erb b/app/views/layouts/base_homework.html.erb index 6fb6e71c..1af01f26 100644 --- a/app/views/layouts/base_homework.html.erb +++ b/app/views/layouts/base_homework.html.erb @@ -214,10 +214,9 @@ <% if User.current.member_of_course? course %>