2013-08-04 10:59:25 +08:00
# fq
2013-08-01 10:33:49 +08:00
class BidsController < ApplicationController
2013-08-10 10:25:30 +08:00
#Added by young
2013-10-30 22:17:16 +08:00
menu_item l ( :label_homework ) , :only = > [ :edit , :udpate ]
2013-08-10 10:25:30 +08:00
menu_item :respond
2013-12-19 15:59:10 +08:00
menu_item :project , :only = > [ :show_project , :show_results , :new_submit_homework ]
2013-09-13 21:52:24 +08:00
menu_item :homework_respond , :only = > :homework_respond
2013-09-22 16:11:39 +08:00
menu_item :homework_statistics , :only = > :homework_statistics
2013-08-10 10:25:30 +08:00
#Ended by young
2014-05-15 10:50:46 +08:00
before_filter :find_bid , :only = > [ :show , :show_project , :create , :destroy , :more , :back , :add , :delete , :new , :show_results , :set_reward , :add_homework , :fork , :create_fork ,
2013-11-19 15:15:54 +08:00
:show_course , :show_bid_project , :show_bid_user , :join_in_contest , :unjoin_in_contest , :new_join , :show_participator , :settings ]
2013-11-14 15:55:56 +08:00
# added by fq
before_filter :require_login , :only = > [ :join_in_contest , :unjoin_in_contest ]
# end
2013-10-30 22:17:16 +08:00
before_filter :require_login , :only = > [ :set_reward , :destroy , :add , :new , ]
2013-10-11 20:32:44 +08:00
2014-05-21 17:33:02 +08:00
before_filter :memberAccess , only : :show_project
2013-08-01 10:33:49 +08:00
helper :watchers
2013-09-13 21:52:24 +08:00
helper :attachments
include AttachmentsHelper
2014-01-17 16:42:31 +08:00
include ApplicationHelper
2014-05-15 19:16:36 +08:00
include BidsHelper
2013-09-26 09:06:29 +08:00
helper :projects
2014-01-02 17:29:46 +08:00
helper :words
2014-04-09 11:06:13 +08:00
helper :welcome
2014-06-05 17:39:48 +08:00
def find_project_by_bid_id
@bid = Bid . find ( params [ :id ] )
@project = @bid . courses [ 0 ]
rescue ActiveRecord :: RecordNotFound
render_404
end
2014-04-09 11:06:13 +08:00
def homework_ajax_modal
@bid = Bid . find_by_id ( params [ :id ] )
# find_bid
respond_to do | format |
format . js
end
end
2013-08-01 10:33:49 +08:00
def index
2013-09-29 19:46:59 +08:00
@project_type = params [ :project_type ]
2013-08-06 21:43:06 +08:00
# Modified by nie
# @requirement_title = "4"
2013-08-15 18:50:44 +08:00
@offset , @limit = api_offset_and_limit ( { :limit = > 10 } )
2013-09-29 19:46:59 +08:00
if @project_type == '1'
@bids = Bid . visible . where ( 'reward_type = ?' , 3 )
2013-10-07 22:23:42 +08:00
# elsif
2013-10-11 20:32:44 +08:00
# @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
2013-09-29 19:46:59 +08:00
else
2013-10-08 22:12:17 +08:00
@bids = Bid . visible . where ( 'reward_type = ?' , 1 )
2013-09-29 19:46:59 +08:00
end
2013-10-11 20:32:44 +08:00
2013-08-06 21:43:06 +08:00
@bids = @bids . like ( params [ :name ] ) if params [ :name ] . present?
@bid_count = @bids . count
2013-08-04 10:11:38 +08:00
@bid_pages = Paginator . new @bid_count , @limit , params [ 'page' ]
2013-08-28 20:16:40 +08:00
2013-08-05 22:47:01 +08:00
@offset || = @bid_pages . reverse_offset
2013-08-28 20:16:40 +08:00
#added by nie
if params [ :bid_sort_type ] . present?
case params [ :bid_sort_type ]
when '0'
unless @offset == 0
@bids = @bids . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @bid_count % @limit
2013-10-07 22:23:42 +08:00
limit = @limit if limit == 0
2013-08-28 20:16:40 +08:00
@bids = @bids . offset ( @offset ) . limit ( limit ) . all . reverse
end
2013-09-02 12:49:17 +08:00
@s_state = 0
2013-08-28 20:16:40 +08:00
when '1'
unless @offset == 0
@bids = @bids . reorder ( 'bids.commit' ) . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @bid_count % @limit
2013-10-07 22:23:42 +08:00
limit = @limit if limit == 0
2013-08-28 20:16:40 +08:00
@bids = @bids . reorder ( 'bids.commit' ) . offset ( @offset ) . limit ( limit ) . all . reverse
end
2013-09-02 12:49:17 +08:00
@s_state = 1
2013-08-28 20:16:40 +08:00
when '2'
unless @offset == 0
@bids = @bids . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @bid_count % @limit
2013-10-07 22:23:42 +08:00
limit = @limit if limit == 0
2013-08-28 20:16:40 +08:00
@bids = @bids . offset ( @offset ) . limit ( @limit ) . all . reverse
end
2013-09-02 12:49:17 +08:00
@s_state = 0
2013-08-28 20:16:40 +08:00
end
2013-08-05 22:47:01 +08:00
else
2013-08-28 20:16:40 +08:00
unless @offset == 0
2013-10-11 20:32:44 +08:00
@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
2013-08-05 22:47:01 +08:00
end
2013-08-28 20:16:40 +08:00
#end
2013-08-01 10:33:49 +08:00
end
2013-10-09 16:14:11 +08:00
#huang
2013-10-08 22:12:17 +08:00
def contest
2013-10-11 20:32:44 +08:00
2013-10-08 22:12:17 +08:00
# Modified by nie
# @requirement_title = "4"
2013-10-11 20:32:44 +08:00
@offset , @limit = api_offset_and_limit ( { :limit = > 10 } )
2013-10-08 22:12:17 +08:00
@bids = Bid . visible . where ( 'reward_type = ?' , 2 )
2013-10-11 20:32:44 +08:00
2013-10-08 22:12:17 +08:00
# elsif
2013-10-11 20:32:44 +08:00
# @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
2013-10-08 22:12:17 +08:00
@bids = @bids . like ( params [ :name ] ) if params [ :name ] . present?
@bid_count = @bids . count
@bid_pages = Paginator . new @bid_count , @limit , params [ 'page' ]
@offset || = @bid_pages . reverse_offset
#added by nie
2013-10-09 17:27:42 +08:00
if params [ :contest_sort_type ] . present?
case params [ :contest_sort_type ]
2013-10-08 22:12:17 +08:00
when '0'
unless @offset == 0
@bids = @bids . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids . offset ( @offset ) . limit ( limit ) . all . reverse
end
@s_state = 0
when '1'
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
when '2'
unless @offset == 0
@bids = @bids . offset ( @offset ) . limit ( @limit ) . all . reverse
else
limit = @bid_count % @limit
limit = @limit if limit == 0
@bids = @bids . offset ( @offset ) . limit ( @limit ) . all . reverse
end
@s_state = 0
end
else
unless @offset == 0
2013-10-11 20:32:44 +08:00
@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
2013-10-09 16:14:11 +08:00
end
#end
2013-10-08 22:12:17 +08:00
end
2013-10-11 20:32:44 +08:00
2013-09-26 09:06:29 +08:00
def fork
@courses = [ ]
2013-10-11 20:32:44 +08:00
@membership = User . current . memberships . all ( :conditions = > Project . visible_condition ( User . current ) )
2013-09-26 09:06:29 +08:00
@membership . each do | membership |
if membership . project . project_type == 1
2013-10-11 20:32:44 +08:00
@courses << membership . project
2013-09-26 09:06:29 +08:00
end
end
end
2013-10-11 20:32:44 +08:00
2013-09-26 09:06:29 +08:00
def create_fork
@homework = Bid . new
@homework . name = params [ :bid ] [ :name ]
@homework . description = params [ :bid ] [ :description ]
@homework . reward_type = 3
# @bid.budget = params[:bid][:budget]
@homework . deadline = params [ :bid ] [ :deadline ]
@homework . budget = 0
@homework . author_id = User . current . id
@homework . commit = 0
2014-06-05 14:00:18 +08:00
@homework . homework_type = 1
@homework . is_evaluation = params [ :bid ] [ :is_evaluation ]
2013-09-26 09:06:29 +08:00
@homework . parent_id = @bid . id
@homework . save_attachments ( params [ :attachments ] || ( params [ :bid ] && params [ :bid ] [ :uploads ] ) )
# @bid.
if @homework . save
2014-06-09 14:23:31 +08:00
HomeworkForCourse . create ( :course_id = > params [ :course ] , :bid_id = > @homework . id )
2013-09-26 09:06:29 +08:00
unless @bid . watched_by? ( User . current )
if @bid . add_watcher ( User . current )
flash [ :notice ] = l ( :label_bid_succeed )
end
end
redirect_to respond_path ( @homework )
else
2013-09-28 23:08:24 +08:00
@bid . safe_attributes = params [ :bid ]
@courses = [ ]
2014-06-09 14:23:31 +08:00
@membership = User . current . coursememberships . all #(:conditions => Project.visible_condition(User.current))
2013-09-28 23:08:24 +08:00
@membership . each do | membership |
2014-06-09 14:23:31 +08:00
@courses << membership . course
2013-09-28 23:08:24 +08:00
end
2013-09-26 09:06:29 +08:00
render :action = > 'fork'
end
end
2013-08-01 10:33:49 +08:00
def show
@user = @bid . author
2014-01-02 17:29:46 +08:00
@jours = @bid . journals_for_messages . where ( 'm_parent_id IS NULL' ) . order ( 'created_on DESC' )
2013-08-15 09:54:08 +08:00
@limit = 10
@feedback_count = @jours . count
@feedback_pages = Paginator . new @feedback_count , @limit , params [ 'page' ]
@offset || = @feedback_pages . offset
@jour = @jours [ @offset , @limit ]
@state = false
2013-08-01 10:33:49 +08:00
respond_to do | format |
2014-01-02 17:29:46 +08:00
layout_file = ''
case @bid . reward_type
when 3
layout_file = 'base_homework'
when 1
layout_file = 'base_bids'
2013-10-12 10:45:48 +08:00
else
2014-01-02 17:29:46 +08:00
layout_file = 'base_contest'
2013-10-31 21:44:10 +08:00
end
2014-01-02 17:29:46 +08:00
format . html {
render :layout = > layout_file
}
2013-10-10 23:02:15 +08:00
format . api
end
end
2013-11-14 15:55:56 +08:00
def join_in_contest
if @bid . reward_type == 2 && params [ :course_password ] == @bid . password
JoinInContest . create ( :user_id = > User . current . id , :bid_id = > @bid . id )
@state = 0
else
@state = 1
end
respond_to do | format |
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
# TO_DO
format . js { render :partial = > 'set_join' , :locals = > { :user = > User . current , :object_id = > params [ :id ] } }
end
end
def unjoin_in_contest
joined = JoinInContest . where ( 'bid_id = ? and user_id = ?' , @bid . id , User . current . id )
joined . each do | join |
join . delete
end
respond_to do | format |
# format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
format . js { render :partial = > 'set_join' , :locals = > { :user = > User . current , :object_id = > params [ :id ] } }
end
end
def new_join
# added by fq
end
2013-11-14 17:01:06 +08:00
2013-11-19 16:05:52 +08:00
# added by bai 增加了参与者和竞赛设置
2013-11-14 17:01:06 +08:00
def show_participator
render :layout = > 'base_contest'
end
2013-11-19 15:15:54 +08:00
def settings
if @bid . author . id == User . current . id
if @bid . reward_type == 2
@contest = Bid . find_by_reward_type ( @bid . reward_type )
render :layout = > 'base_contest'
end
else
render_403 :message = > :notice_not_contest_setting_authorized
end
end
2013-11-14 17:01:06 +08:00
#end
2013-10-11 20:32:44 +08:00
2013-10-10 23:02:15 +08:00
def show_course
bids = Bid . where ( 'parent_id = ?' , @bid . id )
@courses = [ ]
for bid in bids
@courses << bid . courses . first
end
2013-10-11 20:32:44 +08:00
2013-10-10 23:02:15 +08:00
respond_to do | format |
2013-10-11 20:32:44 +08:00
if @bid . reward_type == 3
format . html {
render :layout = > 'base_homework'
}
2013-10-12 10:45:48 +08:00
elsif @bid . reward_type == 1
2013-09-13 10:11:36 +08:00
format . html {
2013-10-12 10:45:48 +08:00
render :layout = > 'base_bids'
}
else
format . html {
render :layout = > 'base_contest'
}
2013-10-31 21:44:10 +08:00
end
2013-08-01 10:33:49 +08:00
format . api
2013-10-11 20:32:44 +08:00
2013-08-01 10:33:49 +08:00
end
end
2013-10-31 21:44:10 +08:00
2013-10-19 09:35:14 +08:00
def show_bid_project
bids = Bid . where ( 'parent_id = ?' , @bid . id )
@projects = [ ]
for bid in bids
@projects += bid . biding_projects
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'
}
2013-10-31 21:44:10 +08:00
end
2013-10-19 09:35:14 +08:00
format . api
end
end
2013-10-31 21:44:10 +08:00
2013-10-19 09:35:14 +08:00
def show_bid_user
bids = Bid . where ( 'parent_id = ?' , @bid . id )
@users = [ ]
for bid in bids
for project in bid . projects
@users += project . users
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'
}
2013-10-31 21:44:10 +08:00
end
2013-10-19 09:35:14 +08:00
format . api
end
end
2013-08-01 10:33:49 +08:00
def show_project
2013-08-08 22:27:58 +08:00
# flash[:notice] = ""
2013-08-01 20:47:00 +08:00
@membership = User . current . memberships . all ( :conditions = > Project . visible_condition ( User . current ) )
@option = [ ]
@membership . each do | membership |
2013-10-11 20:32:44 +08:00
unless ( membership . project . project_type == 1 )
2013-10-10 15:05:27 +08:00
membership . member_roles . each { | role |
if ( role . role_id == 3 )
2014-06-17 11:32:41 +08:00
@option << membership . project
2013-10-10 15:05:27 +08:00
end
}
2013-10-10 10:22:32 +08:00
end
2013-08-01 20:47:00 +08:00
end
2013-10-10 15:05:27 +08:00
2013-08-01 20:47:00 +08:00
# a = [1]
# @project = Project.where("id in []", a)
2013-08-01 10:33:49 +08:00
@user = @bid . author
2013-10-21 09:42:09 +08:00
@bidding_project = @bid . biding_projects . all
2013-10-31 21:44:10 +08:00
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
end
@bidding_project = @temp
else
2014-06-17 11:32:41 +08:00
#added by nie
@temp = [ ]
@bidding_project . each do | pro |
if pro . project && pro . project . project_status
@temp << pro
end
@temp
2013-10-30 10:45:37 +08:00
end
2014-06-17 11:32:41 +08:00
if @temp . size > 0
2013-10-31 21:44:10 +08:00
@bidding_project = @temp . sort { | a , b | b . project . project_status . grade < = > a . project . project_status . grade }
2014-06-17 11:32:41 +08:00
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 " )
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
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
end
# 显示作业课程
# add by nwb
def show_course
# 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
}
2013-10-30 10:45:37 +08:00
end
2014-06-17 11:32:41 +08:00
@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
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
2013-10-31 21:44:10 +08:00
end
2013-09-13 21:52:24 +08:00
if @bid . homework_type == 1
@homework = HomeworkAttach . new
2014-06-05 10:47:22 +08:00
#@homework_list = @bid.homeworks
2014-06-05 14:00:18 +08:00
#增加作业按评分排序,
2014-06-10 09:56:00 +08:00
@homework_list = @bid . homeworks . eager_load ( :rate_averages , :user , :attachments ) . order ( 'seems_rateable_cached_ratings.avg DESC' ) . order ( " #{ HomeworkAttach . table_name } .created_at ASC " )
2013-11-07 15:58:15 +08:00
if params [ :student_id ] . present?
2013-11-14 15:55:56 +08:00
@temp = [ ]
@homework_list . each do | pro |
2014-06-17 11:32:41 +08:00
if / #{ params [ :student_id ] } / =~ pro . user . user_extensions . student_id
@temp << pro
end
2013-11-14 15:55:56 +08:00
@temp
end
2013-11-07 15:58:15 +08:00
@homework_list = @temp
end
2013-09-13 21:52:24 +08:00
end
2013-10-21 09:42:09 +08:00
2013-08-01 10:33:49 +08:00
respond_to do | format |
2013-10-11 20:32:44 +08:00
if @bid . reward_type == 3
2014-06-17 11:32:41 +08:00
format . html {
render :layout = > 'base_homework'
}
2013-10-12 10:45:48 +08:00
elsif @bid . reward_type == 1
2013-10-11 20:32:44 +08:00
format . html {
2014-06-17 11:32:41 +08:00
render :layout = > 'base_bids'
}
2013-09-13 10:11:36 +08:00
else
2014-06-17 11:32:41 +08:00
format . html {
render :layout = > 'base_contest'
}
2013-10-31 21:44:10 +08:00
end
2013-08-01 10:33:49 +08:00
format . api
end
end
2013-09-13 16:36:36 +08:00
##### by huang
def show_project_homework
2013-10-11 20:32:44 +08:00
# flash[:notice] = ""
2013-09-13 16:36:36 +08:00
@membership = User . current . memberships . all ( :conditions = > Project . visible_condition ( User . current ) )
@option = [ ]
@membership . each do | membership |
end
# a = [1]
# @project = Project.where("id in []", a)
@user = @bid . author
@bidding_project = @bid . biding_projects
respond_to do | format |
2013-10-11 20:32:44 +08:00
if @bid . reward_type == 3
format . html {
render :layout = > 'base_homework'
}
2013-10-12 10:45:48 +08:00
elsif @bid . reward_type == 1
2013-09-13 16:36:36 +08:00
format . html {
2013-10-12 10:45:48 +08:00
render :layout = > 'base_bids'
}
else
format . html {
render :layout = > 'base_contest'
}
2013-10-31 21:44:10 +08:00
end
2013-09-13 16:36:36 +08:00
format . api
2013-10-11 20:32:44 +08:00
end
2013-09-13 16:36:36 +08:00
end
2013-10-11 20:32:44 +08:00
2013-08-08 10:04:44 +08:00
###添加应标项目
2013-08-01 10:33:49 +08:00
def add
2013-12-20 09:52:10 +08:00
project = Project . find ( params [ :bid ] )
2013-08-01 10:33:49 +08:00
bid_message = params [ :bid_for_save ] [ :bid_message ]
2013-08-08 22:27:58 +08:00
if BidingProject . where ( " project_id = ? and bid_id = ? " , project . id , @bid . id ) . size == 0
if BidingProject . cerate_bidding ( @bid . id , project . id , bid_message )
2013-10-30 21:46:40 +08:00
# added by bai type ==1 需求, type==2 竞赛, type==3 作业
if @bid . reward_type == 1
2014-04-03 22:15:19 +08:00
flash . now [ :notice ] = l ( :label_bidding_succeed )
2013-10-30 21:46:40 +08:00
elsif @bid . reward_type == 2
2014-04-03 22:15:19 +08:00
flash . now [ :notice ] = l ( :label_bidding_contest_succeed )
2013-10-30 21:46:40 +08:00
else @bid . reward_type == 3
2014-04-03 22:15:19 +08:00
flash . now [ :notice ] = l ( :label_bidding_homework_succeed )
2013-10-30 21:46:40 +08:00
end
# end
2013-08-08 22:27:58 +08:00
end
else
2013-10-11 20:32:44 +08:00
if @bid . reward_type == 3
2014-04-03 22:15:19 +08:00
flash . now [ :error ] = l ( :label_bidding_homework_fail )
2013-09-23 08:44:48 +08:00
else
2014-04-03 22:15:19 +08:00
flash . now [ :error ] = l ( :label_bidding_fail )
2013-09-23 08:44:48 +08:00
end
2013-08-08 22:27:58 +08:00
end
2013-08-01 10:33:49 +08:00
@bidding_project = @bid . biding_projects
respond_to do | format |
# format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
2013-08-08 22:27:58 +08:00
# format.html
format . html { redirect_to :back }
2013-08-01 10:33:49 +08:00
format . js
#format.api { render_api_ok }
end
end
2014-05-15 10:50:46 +08:00
#删除已提交的项目作业(不删项目)
def delete
binding_project = params [ :binding_project ]
2014-05-15 19:16:36 +08:00
if can_delete_project_homework ( BidingProject . find ( binding_project ) , User . current )
if BidingProject . delete ( binding_project )
redirect_to project_for_bid_path
else
redirect_to 403 ;
end
2014-05-15 10:50:46 +08:00
end
end
2013-08-08 10:04:44 +08:00
## 新建留言
2013-08-01 10:33:49 +08:00
def create
2013-08-08 10:04:44 +08:00
2013-08-15 09:54:08 +08:00
if params [ :bid_message ] [ :message ] . size > 0
if params [ :reference_content ]
2013-08-28 15:29:18 +08:00
message = params [ :bid_message ] [ :message ] + " \n " + params [ :reference_content ]
2013-08-15 09:54:08 +08:00
else
message = params [ :bid_message ] [ :message ]
2014-06-05 17:39:48 +08:00
@m = message
2013-08-15 09:54:08 +08:00
end
2013-08-06 22:26:52 +08:00
refer_user_id = params [ :bid_message ] [ :reference_user_id ] . to_i
@bid . add_jour ( User . current , message , refer_user_id )
2013-08-01 10:33:49 +08:00
end
2013-08-15 09:54:08 +08:00
@user = @bid . author
2014-01-02 20:18:39 +08:00
@jours = @bid . journals_for_messages . where ( 'm_parent_id IS NULL' ) . order ( 'created_on DESC' )
2013-08-15 09:54:08 +08:00
@limit = 10
@feedback_count = @jours . count
@feedback_pages = Paginator . new @feedback_count , @limit , params [ 'page' ]
@offset || = @feedback_pages . offset
@jour = @jours [ @offset , @limit ]
@bid . set_commit ( @feedback_count )
2013-08-01 10:33:49 +08:00
respond_to do | format |
format . js
#format.api { render_api_ok }
end
2013-08-08 10:04:44 +08:00
2013-08-01 10:33:49 +08:00
end
2013-08-08 10:04:44 +08:00
##删除留言
2013-08-01 10:33:49 +08:00
def destroy
2013-08-15 09:54:08 +08:00
@user = @bid . author
2013-08-28 15:29:18 +08:00
if User . current . admin? || User . current . id == @user . id
JournalsForMessage . delete_message ( params [ :object_id ] )
end
2013-08-15 09:54:08 +08:00
@jours = @bid . journals_for_messages . reverse
@limit = 10
@feedback_count = @jours . count
@feedback_pages = Paginator . new @feedback_count , @limit , params [ 'page' ]
@offset || = @feedback_pages . offset
@jour = @jours [ @offset , @limit ]
@bid . set_commit ( @feedback_count )
2013-08-01 10:33:49 +08:00
# if a_message.size > 5
# @message = a_message[-5, 5]
# else
# @message = a_message
# end
# @message_count = a_message.count
respond_to do | format |
2013-08-05 22:47:01 +08:00
# format.html
2013-08-01 10:33:49 +08:00
format . js
#format.api { render_api_ok }
end
end
2013-10-11 20:32:44 +08:00
#删除作业
#by xianbo
def homework_destroy
@bid_to_destroy = Bid . find params [ :course_id ]
2013-10-12 10:08:45 +08:00
( render_403 ; return false ) unless User . current . admin? || User . current . id == @bid_to_destroy . author_id
2013-10-11 20:32:44 +08:00
@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
2013-08-08 10:04:44 +08:00
##引用
2013-08-01 10:33:49 +08:00
def new
@jour = JournalsForMessage . find ( params [ :journal_id ] ) if params [ :journal_id ]
if @jour
user = @jour . user
text = @jour . notes
else
user = @bid . author
text = @bid . description
end
# Replaces pre blocks with [...]
text = text . to_s . strip . gsub ( %r{ <pre>((.| \ s)*?)</pre> }m , '[...]' )
2013-10-19 15:39:53 +08:00
@content = " > #{ ll ( User . current . language , :text_user_wrote , user ) } \n > "
2013-08-01 10:33:49 +08:00
@content << text . gsub ( / ( \ r? \ n| \ r \ n?) / , " \n > " ) + " \n \n "
2013-08-06 22:26:52 +08:00
@id = user . id
2013-08-01 10:33:49 +08:00
rescue ActiveRecord :: RecordNotFound
render_404
end
2013-08-02 08:53:07 +08:00
2013-08-08 10:04:44 +08:00
##新建需求
2013-08-01 10:33:49 +08:00
def new_bid
2013-08-20 16:32:45 +08:00
@bid = Bid . new
@bid . safe_attributes = params [ :bid ]
end
2013-10-11 20:32:44 +08:00
#huang
def create_contest
2013-10-08 22:12:17 +08:00
@bid = Bid . new
@bid . name = params [ :bid ] [ :name ]
@bid . description = params [ :bid ] [ :description ]
2013-10-09 17:27:42 +08:00
@bid . reward_type = 2
2013-10-08 22:12:17 +08:00
@bid . budget = params [ :bid ] [ :budget ]
@bid . deadline = params [ :bid ] [ :deadline ]
2013-11-14 15:55:56 +08:00
@bid . password = params [ :bid ] [ :password ] #added by bai
2013-10-08 22:12:17 +08:00
@bid . author_id = User . current . id
@bid . commit = 0
if @bid . save
unless @bid . watched_by? ( User . current )
if @bid . add_watcher ( User . current )
flash [ :notice ] = l ( :label_bid_succeed )
end
end
redirect_to respond_path ( @bid )
else
@bid . safe_attributes = params [ :bid ]
render :action = > 'new_bid'
end
end
2013-10-11 20:32:44 +08:00
2013-11-20 08:57:37 +08:00
# added by bai
2013-11-19 16:05:52 +08:00
def update_contest
@bid = Bid . find ( params [ :id ] )
@bid . name = params [ :bid ] [ :name ]
@bid . description = params [ :bid ] [ :description ]
@bid . reward_type = 2
@bid . budget = params [ :bid ] [ :budget ]
@bid . deadline = params [ :bid ] [ :deadline ]
@bid . password = params [ :bid ] [ :password ]
@bid . author_id = User . current . id
@bid . commit = 0
if @bid . save
unless @bid . watched_by? ( User . current )
if @bid . add_watcher ( User . current )
flash [ :notice ] = l ( :label_bid_succeed )
end
end
redirect_to respond_path ( @bid )
else
@bid . safe_attributes = params [ :bid ]
render :action = > 'new_bid'
end
end
2013-10-08 22:12:17 +08:00
#huang
def new_contest
@bid = Bid . new
@bid . safe_attributes = params [ :bid ]
end
2013-08-28 20:16:40 +08:00
2013-08-20 16:32:45 +08:00
def create_bid
@bid = Bid . new
@bid . name = params [ :bid ] [ :name ]
@bid . description = params [ :bid ] [ :description ]
2013-10-10 21:56:27 +08:00
@bid . reward_type = 1
2013-08-20 16:32:45 +08:00
@bid . budget = params [ :bid ] [ :budget ]
@bid . deadline = params [ :bid ] [ :deadline ]
@bid . author_id = User . current . id
@bid . commit = 0
if @bid . save
2013-08-22 20:26:56 +08:00
unless @bid . watched_by? ( User . current )
if @bid . add_watcher ( User . current )
flash [ :notice ] = l ( :label_bid_succeed )
end
end
2013-08-20 16:32:45 +08:00
redirect_to respond_path ( @bid )
2013-08-20 17:34:33 +08:00
else
@bid . safe_attributes = params [ :bid ]
render :action = > 'new_bid'
2013-08-04 10:11:38 +08:00
end
2013-08-01 10:33:49 +08:00
end
2013-10-11 20:32:44 +08:00
2013-09-12 10:41:15 +08:00
def create_homework
@bid = Bid . new
@bid . name = params [ :bid ] [ :name ]
@bid . description = params [ :bid ] [ :description ]
2014-06-05 14:00:18 +08:00
@bid . is_evaluation = params [ :bid ] [ :is_evaluation ]
2013-09-12 10:41:15 +08:00
@bid . reward_type = 3
# @bid.budget = params[:bid][:budget]
@bid . deadline = params [ :bid ] [ :deadline ]
@bid . budget = 0
@bid . author_id = User . current . id
@bid . commit = 0
2014-06-04 10:32:44 +08:00
@bid . homework_type = 1
2013-09-13 21:52:24 +08:00
@bid . save_attachments ( params [ :attachments ] || ( params [ :bid ] && params [ :bid ] [ :uploads ] ) )
2013-09-12 10:41:15 +08:00
# @bid.
if @bid . save
2014-06-09 14:23:31 +08:00
HomeworkForCourse . create ( :course_id = > params [ :course_id ] , :bid_id = > @bid . id )
2013-09-12 10:41:15 +08:00
unless @bid . watched_by? ( User . current )
if @bid . add_watcher ( User . current )
flash [ :notice ] = l ( :label_bid_succeed )
end
end
redirect_to respond_path ( @bid )
else
@bid . safe_attributes = params [ :bid ]
2014-05-12 15:06:34 +08:00
@homework = @bid
2014-06-09 14:23:31 +08:00
@course = Course . find_by_id ( params [ :course_id ] )
@course_id = @course . id
render file : 'courses/new_homework' , layout : 'base_courses'
2013-09-12 10:41:15 +08:00
end
2013-09-13 21:52:24 +08:00
end
2014-06-17 11:32:41 +08:00
# modify by nwb\
# 编辑作业
2013-10-30 22:17:16 +08:00
def edit
2013-10-31 16:33:15 +08:00
@bid = Bid . find ( params [ :bid_id ] )
2013-11-08 17:19:57 +08:00
if ( User . current . admin? || User . current . id == @bid . author_id )
2014-06-17 11:32:41 +08:00
@course_id = params [ :course_id ]
2013-10-30 22:17:16 +08:00
respond_to do | format |
format . html {
2014-06-17 11:32:41 +08:00
@course = Course . find ( params [ :course_id ] )
2013-10-30 22:17:16 +08:00
@user = User . find ( User . current . id )
render :layout = > 'base_courses'
}
2013-10-31 16:33:15 +08:00
end
else
render 403
2013-10-30 22:17:16 +08:00
end
end
def update
@bid = Bid . find ( params [ :id ] )
2014-06-17 11:32:41 +08:00
@course = @bid . courses . first #Project.find(params[:course_id])
2014-05-17 10:44:01 +08:00
@bid . save_attachments ( params [ :attachments ] || ( params [ :bid ] && params [ :bid ] [ :uploads ] ) )
if @bid . update_attributes ( params [ :bid ] ) && @bid . save
2013-10-30 22:17:16 +08:00
flash [ :notice ] = l ( :label_update_homework_succeed )
2014-06-17 11:32:41 +08:00
redirect_to course_homework_path ( @course )
2013-10-30 22:17:16 +08:00
else
@bid . safe_attributes = params [ :bid ]
2014-05-14 09:35:44 +08:00
render :action = > 'edit' , :layout = > 'base_courses'
2013-10-30 22:17:16 +08:00
end
end
2013-12-19 15:59:10 +08:00
def new_submit_homework
#render html to prepare create submit homework
find_bid
render :layout = > 'base_homework'
end
2013-10-30 22:17:16 +08:00
2013-09-13 21:52:24 +08:00
def add_homework
2013-11-21 09:44:54 +08:00
if User . current . logged? && ( ! Member . where ( 'user_id = ? and project_id = ?' , User . current . id , @bid . courses . first . id ) . first . nil? && ( Member . where ( 'user_id = ? and project_id = ?' , User . current . id , @bid . courses . first . id ) . first . roles & Role . where ( 'id = ? or id = ? or id =?' , 5 , 10 , 7 ) ) . size > 0 )
# homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
# homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
2014-01-17 16:42:31 +08:00
if hadcommittedhomework ( User . current . id , @bid . id ) == true
@homework_flag = l ( :label_bidding_homework_committed )
2013-12-19 15:59:10 +08:00
else
2014-01-17 16:42:31 +08:00
@homework = HomeworkAttach . new
@homework . safe_attributes = params [ :homeworkattach ]
@homework . bid_id = @bid . id
@homework . user_id = User . current . id
@homework . save_attachments ( params [ :attachments ] )
render_attachment_warning_if_needed ( @homework )
2014-04-08 14:53:11 +08:00
@homework_flag = if @homework . save
l ( :label_bidding_homework_succeed )
else
l ( :label_bidding_homework_failed )
end
2014-01-17 16:42:31 +08:00
if @homework . attachments . empty?
@homework . delete
#flash[:error] = l(:no_attachmens_allowed)
@homework_flag = l ( :no_attachmens_allowed )
# else
end
end
2013-11-21 09:44:54 +08:00
end
2014-01-17 16:42:31 +08:00
2013-09-13 21:52:24 +08:00
@homework_list = @bid . homeworks
2013-12-19 15:59:10 +08:00
respond_to do | format |
format . html {
2014-04-08 14:53:11 +08:00
#redirect_to project_for_bid_path, notice: @homework_flag.to_s
flash [ :notice ] = @homework_flag . to_s
redirect_back_or_default ( project_for_bid_path )
2013-12-19 15:59:10 +08:00
}
format . js
end
2013-10-11 20:32:44 +08:00
2013-09-12 10:41:15 +08:00
end
2013-10-11 20:32:44 +08:00
2013-09-22 16:11:39 +08:00
# 作业统计
def homework_statistics
@course = @bid . courses . first
@member = [ ]
@course . memberships . each do | member |
unless ( member . roles && Role . where ( 'id = ? ' , 3 ) ) . empty?
2013-10-11 20:32:44 +08:00
@member . push member
2013-09-22 16:11:39 +08:00
end
end
2013-10-11 20:32:44 +08:00
if @bid . homework_type = 1
2013-09-22 16:11:39 +08:00
@student = User . where ( " id in (select DISTINCT user_id from #{ HomeworkAttach . table_name } where bid_id = ? ) " , @bid . id )
@homework_type = true
else
2013-10-11 20:32:44 +08:00
2013-09-22 16:11:39 +08:00
@homework_type = false
end
@user = @bid . author
render :layout = > 'base_homework'
end
2013-10-11 20:32:44 +08:00
2013-09-13 21:52:24 +08:00
def homework_respond
@user = @bid . author
render :layout = > 'base_homework'
end
2013-08-01 10:33:49 +08:00
def more
@jour = @bid . journals_for_messages
@jour . each_with_index { | j , i | j . indice = i + 1 }
@state = true
respond_to do | format |
format . html { redirect_to :back }
format . js
#format.api { render_api_ok }
end
end
def back
@jour = @bid . journals_for_messages
@jour . each_with_index { | j , i | j . indice = i + 1 }
@state = false
respond_to do | format |
format . html { redirect_to :back }
format . js
#format.api { render_api_ok }
end
end
2013-09-23 20:12:32 +08:00
#added by william
#used to set the bidding project reward
def set_reward
@b_p = nil
@biding_project_id = nil
2013-10-11 20:32:44 +08:00
2013-10-24 20:36:57 +08:00
if params [ :set_reward ] [ :reward ] && ( ( User . current . id == @bid . author_id ) || User . current . admin )
2013-09-23 20:12:32 +08:00
# @bid_id = params[:id]
@biding_project_id = params [ :set_reward ] [ :b_id ]
@b_p = BidingProject . find_by_id ( @biding_project_id )
2013-10-11 20:32:44 +08:00
2013-09-23 20:12:32 +08:00
# 把字段存进表中
@b_p . update_reward ( params [ :set_reward ] [ :reward ] . to_s )
end
respond_to do | format |
format . js
end
end
# added by william
# used to manage the bid and end the bid
def manage
end
2013-08-01 10:33:49 +08:00
private
def find_bid
2013-08-05 22:47:01 +08:00
if params [ :id ]
2014-06-05 15:14:51 +08:00
@bid = Bid . find ( params [ :id ] , :include = > [ { :homeworks = > :user } ] )
2013-09-26 09:06:29 +08:00
@user = @bid . author
2013-08-01 10:33:49 +08:00
end
rescue
render_404
2014-05-21 17:33:02 +08:00
end
def memberAccess
# 是课程,则判断当前用户是否参加了课程
2014-05-30 15:52:34 +08:00
return true if current_user . admin?
2014-05-21 17:33:02 +08:00
return 0 if @bid . courses . first . project_type == Project :: ProjectType_project
currentUser = User . current
render_403 unless currentUser . member_of? ( @bid . courses . first )
end
2013-08-01 10:33:49 +08:00
end