|
|
|
@ -7,13 +7,12 @@ class BidsController < ApplicationController
|
|
|
|
|
menu_item :homework_statistics, :only => :homework_statistics
|
|
|
|
|
#Ended by young
|
|
|
|
|
before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork, :show_course]
|
|
|
|
|
before_filter :require_login,:only => [:set_reward]
|
|
|
|
|
|
|
|
|
|
before_filter :require_login,:only => [:set_reward]
|
|
|
|
|
|
|
|
|
|
helper :watchers
|
|
|
|
|
helper :attachments
|
|
|
|
|
include AttachmentsHelper
|
|
|
|
|
helper :projects
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
@project_type = params[:project_type]
|
|
|
|
|
# Modified by nie
|
|
|
|
@ -22,11 +21,11 @@ class BidsController < ApplicationController
|
|
|
|
|
if @project_type == '1'
|
|
|
|
|
@bids = Bid.visible.where('reward_type = ?', 3)
|
|
|
|
|
# elsif
|
|
|
|
|
# @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
|
|
|
|
|
# @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
|
|
|
|
|
else
|
|
|
|
|
@bids = Bid.visible.where('reward_type = ?', 1)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bids = @bids.like(params[:name]) if params[:name].present?
|
|
|
|
|
@bid_count = @bids.count
|
|
|
|
|
@bid_pages = Paginator.new @bid_count, @limit, params['page']
|
|
|
|
@ -65,28 +64,28 @@ class BidsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
unless @offset == 0
|
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
|
limit = @limit if limit == 0
|
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
@s_state = 1
|
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
|
limit = @limit if limit == 0
|
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
@s_state = 1
|
|
|
|
|
end
|
|
|
|
|
#end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#huang
|
|
|
|
|
def contest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Modified by nie
|
|
|
|
|
# @requirement_title = "4"
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
|
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
|
|
|
|
|
|
@bids = Bid.visible.where('reward_type = ?', 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# elsif
|
|
|
|
|
# @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
|
|
|
|
|
# @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
|
|
|
|
|
@bids = @bids.like(params[:name]) if params[:name].present?
|
|
|
|
|
@bid_count = @bids.count
|
|
|
|
|
@bid_pages = Paginator.new @bid_count, @limit, params['page']
|
|
|
|
@ -125,27 +124,27 @@ class BidsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
unless @offset == 0
|
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
|
limit = @limit if limit == 0
|
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
@s_state = 1
|
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @bid_count % @limit
|
|
|
|
|
limit = @limit if limit == 0
|
|
|
|
|
@bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
@s_state = 1
|
|
|
|
|
end
|
|
|
|
|
#end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fork
|
|
|
|
|
@courses = []
|
|
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
|
@membership.each do |membership|
|
|
|
|
|
if membership.project.project_type == 1
|
|
|
|
|
@courses << membership.project
|
|
|
|
|
@courses << membership.project
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_fork
|
|
|
|
|
@homework = Bid.new
|
|
|
|
|
@homework.name = params[:bid][:name]
|
|
|
|
@ -171,10 +170,10 @@ class BidsController < ApplicationController
|
|
|
|
|
else
|
|
|
|
|
@bid.safe_attributes = params[:bid]
|
|
|
|
|
@courses = []
|
|
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
|
@membership.each do |membership|
|
|
|
|
|
if membership.project.project_type == 1
|
|
|
|
|
@courses << membership.project
|
|
|
|
|
@courses << membership.project
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
render :action => 'fork'
|
|
|
|
@ -192,39 +191,39 @@ class BidsController < ApplicationController
|
|
|
|
|
@state = false
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
}
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
format.api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def show_course
|
|
|
|
|
bids = Bid.where('parent_id = ?', @bid.id)
|
|
|
|
|
@courses = []
|
|
|
|
|
for bid in bids
|
|
|
|
|
@courses << bid.courses.first
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
}
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
format.api
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -233,10 +232,10 @@ class BidsController < ApplicationController
|
|
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
|
@option = []
|
|
|
|
|
@membership.each do |membership|
|
|
|
|
|
unless(membership.project.project_type==1)
|
|
|
|
|
unless(membership.project.project_type==1)
|
|
|
|
|
membership.member_roles.each{|role|
|
|
|
|
|
if(role.role_id == 3)
|
|
|
|
|
@option << membership.project
|
|
|
|
|
@option << membership.project
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
@ -251,23 +250,22 @@ class BidsController < ApplicationController
|
|
|
|
|
@homework_list = @bid.homeworks
|
|
|
|
|
end
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
}
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
format.api
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##### by huang
|
|
|
|
|
def show_project_homework
|
|
|
|
|
# flash[:notice] = ""
|
|
|
|
|
# flash[:notice] = ""
|
|
|
|
|
@membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
|
|
|
|
|
@option = []
|
|
|
|
|
@membership.each do |membership|
|
|
|
|
@ -277,19 +275,19 @@ class BidsController < ApplicationController
|
|
|
|
|
@user = @bid.author
|
|
|
|
|
@bidding_project = @bid.biding_projects
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
}
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
format.html {
|
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
render :layout => 'base_bids'
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
format.api
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###添加应标项目
|
|
|
|
|
def add
|
|
|
|
|
project = Project.where('name = ?', params[:bid]).first
|
|
|
|
@ -299,10 +297,10 @@ class BidsController < ApplicationController
|
|
|
|
|
flash[:notice] = l(:label_bidding_succeed)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
flash[:error] = l(:label_bidding_homework_fail)
|
|
|
|
|
if @bid.reward_type == 3
|
|
|
|
|
flash[:error] = l(:label_bidding_homework_fail)
|
|
|
|
|
else
|
|
|
|
|
flash[:error] = l(:label_bidding_fail)
|
|
|
|
|
flash[:error] = l(:label_bidding_fail)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
@bidding_project = @bid.biding_projects
|
|
|
|
@ -371,6 +369,19 @@ class BidsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#删除作业
|
|
|
|
|
#by xianbo
|
|
|
|
|
def homework_destroy
|
|
|
|
|
@bid_to_destroy = Bid.find params[:course_id]
|
|
|
|
|
@bid_to_destroy.destroy
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
format.html { redirect_to :back }
|
|
|
|
|
format.js
|
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#end by xianbo
|
|
|
|
|
##引用
|
|
|
|
|
def new
|
|
|
|
|
@jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
|
|
|
|
@ -395,8 +406,9 @@ class BidsController < ApplicationController
|
|
|
|
|
@bid = Bid.new
|
|
|
|
|
@bid.safe_attributes = params[:bid]
|
|
|
|
|
end
|
|
|
|
|
#huang
|
|
|
|
|
def create_contest
|
|
|
|
|
|
|
|
|
|
#huang
|
|
|
|
|
def create_contest
|
|
|
|
|
@bid = Bid.new
|
|
|
|
|
@bid.name = params[:bid][:name]
|
|
|
|
|
@bid.description = params[:bid][:description]
|
|
|
|
@ -417,8 +429,7 @@ class BidsController < ApplicationController
|
|
|
|
|
render :action => 'new_bid'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#huang
|
|
|
|
|
def new_contest
|
|
|
|
|
@bid = Bid.new
|
|
|
|
@ -446,7 +457,7 @@ class BidsController < ApplicationController
|
|
|
|
|
render :action => 'new_bid'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_homework
|
|
|
|
|
@bid = Bid.new
|
|
|
|
|
@bid.name = params[:bid][:name]
|
|
|
|
@ -473,7 +484,7 @@ class BidsController < ApplicationController
|
|
|
|
|
render :action => 'new_bid'
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_homework
|
|
|
|
|
# homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
|
|
|
|
|
# homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
|
|
|
|
@ -483,29 +494,29 @@ class BidsController < ApplicationController
|
|
|
|
|
@homework.save_attachments(params[:attachments])
|
|
|
|
|
@homework.save
|
|
|
|
|
@homework_list = @bid.homeworks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 作业统计
|
|
|
|
|
def homework_statistics
|
|
|
|
|
@course = @bid.courses.first
|
|
|
|
|
@member = []
|
|
|
|
|
@course.memberships.each do |member|
|
|
|
|
|
unless (member.roles && Role.where('id = ? ', 3)).empty?
|
|
|
|
|
@member.push member
|
|
|
|
|
@member.push member
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if @bid.homework_type = 1
|
|
|
|
|
if @bid.homework_type = 1
|
|
|
|
|
@student = User.where("id in (select DISTINCT user_id from #{HomeworkAttach.table_name} where bid_id = ? )", @bid.id)
|
|
|
|
|
@homework_type = true
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@homework_type = false
|
|
|
|
|
end
|
|
|
|
|
@user = @bid.author
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def homework_respond
|
|
|
|
|
@user = @bid.author
|
|
|
|
|
render :layout => 'base_homework'
|
|
|
|
@ -522,7 +533,6 @@ class BidsController < ApplicationController
|
|
|
|
|
#format.api { render_api_ok }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def back
|
|
|
|
|
@jour = @bid.journals_for_messages
|
|
|
|
@ -541,12 +551,12 @@ class BidsController < ApplicationController
|
|
|
|
|
def set_reward
|
|
|
|
|
@b_p = nil
|
|
|
|
|
@biding_project_id = nil
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if params[:set_reward][:reward]
|
|
|
|
|
# @bid_id = params[:id]
|
|
|
|
|
@biding_project_id = params[:set_reward][:b_id]
|
|
|
|
|
@b_p = BidingProject.find_by_id(@biding_project_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 把字段存进表中
|
|
|
|
|
@b_p.update_reward(params[:set_reward][:reward].to_s)
|
|
|
|
|
end
|
|
|
|
@ -556,7 +566,6 @@ class BidsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# added by william
|
|
|
|
|
# used to manage the bid and end the bid
|
|
|
|
|
def manage
|
|
|
|
|