You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

bids_controller.rb 28 kB

13 years ago
13 years ago
13 years ago
​
​
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
13 years ago
​
13 years ago
13 years ago
13 years ago
13 years ago
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
13 years ago
​
​
​
​
​
13 years ago
​
13 years ago
​
​
​
​
​
​
13 years ago
13 years ago
13 years ago
13 years ago
​
13 years ago
​
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
13 years ago
13 years ago
​
13 years ago
​
13 years ago
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
13 years ago
13 years ago
​
​
​
13 years ago
​
​
​
​
​
13 years ago
13 years ago
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
13 years ago
13 years ago
​
13 years ago
​
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
13 years ago
​
13 years ago
​
​
13 years ago
​
​
​
13 years ago
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
13 years ago
​
​
​
13 years ago
​
​
​
​
​
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
​
​
​
​
​
​
​
​
13 years ago
13 years ago
13 years ago
13 years ago
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
13 years ago
​
​
​
​
​
13 years ago
​
​
​
​
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
13 years ago
​
​
​
​
13 years ago
​
​
​
13 years ago
13 years ago
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
​
​
13 years ago
​
​
13 years ago
​
​
13 years ago
​
​
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
13 years ago
​
​
​
13 years ago
​
​
​
​
​
13 years ago
​
13 years ago
​
​
​
​
​
​
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
13 years ago
13 years ago
13 years ago
​
​
​
​
​
13 years ago
13 years ago
​
13 years ago
13 years ago
​
​
13 years ago
13 years ago
​
​
​
​
13 years ago
​
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
13 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
13 years ago
​
​
13 years ago
​
​
​
​
​
13 years ago
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  1. # fq
  2. class BidsController < ApplicationController
  3. #Added by young
  4. menu_item l(:label_homework), :only => [:edit, :udpate]
  5. menu_item :respond
  6. menu_item :project, :only => [:show_project,:show_results, :new_submit_homework]
  7. menu_item :homework_respond, :only => :homework_respond
  8. menu_item :homework_statistics, :only => :homework_statistics
  9. #Ended by young
  10. before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
  11. :show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
  12. # added by fq
  13. before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
  14. # end
  15. before_filter :require_login,:only => [:set_reward, :destroy, :add, :new, ]
  16. before_filter :memberAccess, only: :show_project
  17. helper :watchers
  18. helper :attachments
  19. include AttachmentsHelper
  20. include ApplicationHelper
  21. include BidsHelper
  22. helper :projects
  23. helper :words
  24. helper :welcome
  25. def find_project_by_bid_id
  26. @bid = Bid.find(params[:id])
  27. @project = @bid.courses[0]
  28. rescue ActiveRecord::RecordNotFound
  29. render_404
  30. end
  31. def homework_ajax_modal
  32. @bid = Bid.find_by_id(params[:id])
  33. # find_bid
  34. respond_to do |format|
  35. format.js
  36. end
  37. end
  38. def index
  39. @project_type = params[:project_type]
  40. # Modified by nie
  41. # @requirement_title = "4"
  42. @offset, @limit = api_offset_and_limit({:limit => 10})
  43. if @project_type == '1'
  44. @bids = Bid.visible.where('reward_type = ?', 3)
  45. # elsif
  46. # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
  47. else
  48. @bids = Bid.visible.where('reward_type = ?', 1)
  49. end
  50. @bids = @bids.like(params[:name]) if params[:name].present?
  51. @bid_count = @bids.count
  52. @bid_pages = Paginator.new @bid_count, @limit, params['page']
  53. @offset ||= @bid_pages.reverse_offset
  54. #added by nie
  55. if params[:bid_sort_type].present?
  56. case params[:bid_sort_type]
  57. when '0'
  58. unless @offset == 0
  59. @bids = @bids.offset(@offset).limit(@limit).all.reverse
  60. else
  61. limit = @bid_count % @limit
  62. limit = @limit if limit == 0
  63. @bids = @bids.offset(@offset).limit(limit).all.reverse
  64. end
  65. @s_state = 0
  66. when '1'
  67. unless @offset == 0
  68. @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
  69. else
  70. limit = @bid_count % @limit
  71. limit = @limit if limit == 0
  72. @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
  73. end
  74. @s_state = 1
  75. when '2'
  76. unless @offset == 0
  77. @bids = @bids.offset(@offset).limit(@limit).all.reverse
  78. else
  79. limit = @bid_count % @limit
  80. limit = @limit if limit == 0
  81. @bids = @bids.offset(@offset).limit(@limit).all.reverse
  82. end
  83. @s_state = 0
  84. end
  85. else
  86. unless @offset == 0
  87. @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
  88. else
  89. limit = @bid_count % @limit
  90. limit = @limit if limit == 0
  91. @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
  92. end
  93. @s_state = 1
  94. end
  95. #end
  96. end
  97. #huang
  98. def contest
  99. # Modified by nie
  100. # @requirement_title = "4"
  101. @offset, @limit = api_offset_and_limit({:limit => 10})
  102. @bids = Bid.visible.where('reward_type = ?', 2)
  103. # elsif
  104. # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
  105. @bids = @bids.like(params[:name]) if params[:name].present?
  106. @bid_count = @bids.count
  107. @bid_pages = Paginator.new @bid_count, @limit, params['page']
  108. @offset ||= @bid_pages.reverse_offset
  109. #added by nie
  110. if params[:contest_sort_type].present?
  111. case params[:contest_sort_type]
  112. when '0'
  113. unless @offset == 0
  114. @bids = @bids.offset(@offset).limit(@limit).all.reverse
  115. else
  116. limit = @bid_count % @limit
  117. limit = @limit if limit == 0
  118. @bids = @bids.offset(@offset).limit(limit).all.reverse
  119. end
  120. @s_state = 0
  121. when '1'
  122. unless @offset == 0
  123. @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
  124. else
  125. limit = @bid_count % @limit
  126. limit = @limit if limit == 0
  127. @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
  128. end
  129. @s_state = 1
  130. when '2'
  131. unless @offset == 0
  132. @bids = @bids.offset(@offset).limit(@limit).all.reverse
  133. else
  134. limit = @bid_count % @limit
  135. limit = @limit if limit == 0
  136. @bids = @bids.offset(@offset).limit(@limit).all.reverse
  137. end
  138. @s_state = 0
  139. end
  140. else
  141. unless @offset == 0
  142. @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
  143. else
  144. limit = @bid_count % @limit
  145. limit = @limit if limit == 0
  146. @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
  147. end
  148. @s_state = 1
  149. end
  150. #end
  151. end
  152. def fork
  153. @courses = []
  154. @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  155. @membership.each do |membership|
  156. if membership.project.project_type == 1
  157. @courses << membership.project
  158. end
  159. end
  160. end
  161. def create_fork
  162. @homework = Bid.new
  163. @homework.name = params[:bid][:name]
  164. @homework.description = params[:bid][:description]
  165. @homework.reward_type = 3
  166. # @bid.budget = params[:bid][:budget]
  167. @homework.deadline = params[:bid][:deadline]
  168. @homework.budget = 0
  169. @homework.author_id = User.current.id
  170. @homework.commit = 0
  171. @homework.homework_type = 1
  172. @homework.is_evaluation = params[:bid][:is_evaluation]
  173. @homework.parent_id = @bid.id
  174. @homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
  175. # @bid.
  176. if @homework.save
  177. HomeworkForCourse.create(:course_id => params[:course], :bid_id => @homework.id)
  178. unless @bid.watched_by?(User.current)
  179. if @bid.add_watcher(User.current)
  180. flash[:notice] = l(:label_bid_succeed)
  181. end
  182. end
  183. redirect_to respond_path(@homework)
  184. else
  185. @bid.safe_attributes = params[:bid]
  186. @courses = []
  187. @membership = User.current.coursememberships.all#(:conditions => Project.visible_condition(User.current))
  188. @membership.each do |membership|
  189. @courses << membership.course
  190. end
  191. render :action => 'fork'
  192. end
  193. end
  194. def show
  195. @user = @bid.author
  196. @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
  197. @limit = 10
  198. @feedback_count = @jours.count
  199. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  200. @offset ||= @feedback_pages.offset
  201. @jour = @jours[@offset, @limit]
  202. @state = false
  203. respond_to do |format|
  204. layout_file = ''
  205. case @bid.reward_type
  206. when 3
  207. layout_file = 'base_homework'
  208. when 1
  209. layout_file = 'base_bids'
  210. else
  211. layout_file = 'base_contest'
  212. end
  213. format.html {
  214. render :layout => layout_file
  215. }
  216. format.api
  217. end
  218. end
  219. def join_in_contest
  220. if @bid.reward_type == 2 && params[:course_password] == @bid.password
  221. JoinInContest.create(:user_id => User.current.id, :bid_id => @bid.id)
  222. @state = 0
  223. else
  224. @state = 1
  225. end
  226. respond_to do |format|
  227. # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
  228. # TO_DO
  229. format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
  230. end
  231. end
  232. def unjoin_in_contest
  233. joined = JoinInContest.where('bid_id = ? and user_id = ?', @bid.id, User.current.id)
  234. joined.each do |join|
  235. join.delete
  236. end
  237. respond_to do |format|
  238. # format.html { redirect_to_referer_or {render :text => (watching ? 'Watcher added.' : 'Watcher removed.'), :layout => true}}
  239. format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
  240. end
  241. end
  242. def new_join
  243. # added by fq
  244. end
  245. # added by bai 增加了参与者和竞赛设置
  246. def show_participator
  247. render :layout => 'base_contest'
  248. end
  249. def settings
  250. if @bid.author.id == User.current.id
  251. if @bid.reward_type == 2
  252. @contest = Bid.find_by_reward_type(@bid.reward_type)
  253. render :layout => 'base_contest'
  254. end
  255. else
  256. render_403 :message => :notice_not_contest_setting_authorized
  257. end
  258. end
  259. #end
  260. # 显示课程
  261. def show_course
  262. bids = Bid.where('parent_id = ?', @bid.id)
  263. @courses = []
  264. for bid in bids
  265. @courses << bid.courses.first
  266. end
  267. respond_to do |format|
  268. if @bid.reward_type == 3
  269. format.html {
  270. render :layout => 'base_homework'
  271. }
  272. elsif @bid.reward_type == 1
  273. format.html {
  274. render :layout => 'base_bids'
  275. }
  276. else
  277. format.html {
  278. render :layout => 'base_contest'
  279. }
  280. end
  281. format.api
  282. end
  283. end
  284. def show_bid_project
  285. bids = Bid.where('parent_id = ?', @bid.id)
  286. @projects = []
  287. for bid in bids
  288. @projects += bid.biding_projects
  289. end
  290. respond_to do |format|
  291. if @bid.reward_type == 3
  292. format.html {
  293. render :layout => 'base_homework'
  294. }
  295. elsif @bid.reward_type == 1
  296. format.html {
  297. render :layout => 'base_bids'
  298. }
  299. else
  300. format.html {
  301. render :layout => 'base_contest'
  302. }
  303. end
  304. format.api
  305. end
  306. end
  307. def show_bid_user
  308. bids = Bid.where('parent_id = ?', @bid.id)
  309. @users = []
  310. for bid in bids
  311. for project in bid.projects
  312. @users += project.users
  313. end
  314. end
  315. respond_to do |format|
  316. if @bid.reward_type == 3
  317. format.html {
  318. render :layout => 'base_homework'
  319. }
  320. elsif @bid.reward_type == 1
  321. format.html {
  322. render :layout => 'base_bids'
  323. }
  324. else
  325. format.html {
  326. render :layout => 'base_contest'
  327. }
  328. end
  329. format.api
  330. end
  331. end
  332. def show_project
  333. # flash[:notice] = ""
  334. @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  335. @option = []
  336. @membership.each do |membership|
  337. unless(membership.project.project_type==1)
  338. membership.member_roles.each{|role|
  339. if(role.role_id == 3)
  340. @option << membership.project
  341. end
  342. }
  343. end
  344. end
  345. # a = [1]
  346. # @project = Project.where("id in []", a)
  347. @user = @bid.author
  348. @bidding_project = @bid.biding_projects.all
  349. if params[:student_id].present?
  350. @temp = []
  351. @bidding_project.each do |pro|
  352. if pro.project && pro.project.project_status
  353. if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  354. @temp << pro
  355. end
  356. end
  357. @temp
  358. end
  359. @bidding_project = @temp
  360. else
  361. #added by nie
  362. @temp = []
  363. @bidding_project.each do |pro|
  364. if pro.project && pro.project.project_status
  365. @temp << pro
  366. end
  367. @temp
  368. end
  369. if @temp.size > 0
  370. @bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
  371. end
  372. #ended
  373. end
  374. if @bid.homework_type == 1
  375. @homework = HomeworkAttach.new
  376. #@homework_list = @bid.homeworks
  377. #增加作业按评分排序,
  378. @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
  379. if params[:student_id].present?
  380. @temp = []
  381. @homework_list.each do |pro|
  382. if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  383. @temp << pro
  384. end
  385. @temp
  386. end
  387. @homework_list = @temp
  388. end
  389. end
  390. respond_to do |format|
  391. if @bid.reward_type == 3
  392. format.html {
  393. render :layout => 'base_homework'
  394. }
  395. elsif @bid.reward_type == 1
  396. format.html {
  397. render :layout => 'base_bids'
  398. }
  399. else
  400. format.html {
  401. render :layout => 'base_contest'
  402. }
  403. end
  404. format.api
  405. end
  406. end
  407. # 显示作业课程
  408. # add by nwb
  409. def show_courseEx
  410. # flash[:notice] = ""
  411. @membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current))
  412. @option = []
  413. @membership.each do |membership|
  414. membership.member_roles.each{|role|
  415. if(role.role_id == 3)
  416. @option << membership.course
  417. end
  418. }
  419. end
  420. @user = @bid.author
  421. @bidding_project = @bid.biding_projects.all
  422. if params[:student_id].present?
  423. @temp = []
  424. @bidding_project.each do |pro|
  425. if pro.project && pro.project.project_status
  426. if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  427. @temp << pro
  428. end
  429. end
  430. @temp
  431. end
  432. @bidding_project = @temp
  433. else
  434. #added by nie
  435. @temp = []
  436. @bidding_project.each do |pro|
  437. if pro.project && pro.project.project_status
  438. @temp << pro
  439. end
  440. @temp
  441. end
  442. if @temp.size > 0
  443. @bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
  444. end
  445. #ended
  446. end
  447. if @bid.homework_type == 1
  448. @homework = HomeworkAttach.new
  449. #@homework_list = @bid.homeworks
  450. #增加作业按评分排序,
  451. @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
  452. if params[:student_id].present?
  453. @temp = []
  454. @homework_list.each do |pro|
  455. if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  456. @temp << pro
  457. end
  458. @temp
  459. end
  460. @homework_list = @temp
  461. end
  462. end
  463. respond_to do |format|
  464. if @bid.reward_type == 3
  465. format.html {
  466. render :layout => 'base_homework'
  467. }
  468. elsif @bid.reward_type == 1
  469. format.html {
  470. render :layout => 'base_bids'
  471. }
  472. else
  473. format.html {
  474. render :layout => 'base_contest'
  475. }
  476. end
  477. format.api
  478. end
  479. end
  480. ##### by huang
  481. def show_project_homework
  482. # flash[:notice] = ""
  483. @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  484. @option = []
  485. @membership.each do |membership|
  486. end
  487. # a = [1]
  488. # @project = Project.where("id in []", a)
  489. @user = @bid.author
  490. @bidding_project = @bid.biding_projects
  491. respond_to do |format|
  492. if @bid.reward_type == 3
  493. format.html {
  494. render :layout => 'base_homework'
  495. }
  496. elsif @bid.reward_type == 1
  497. format.html {
  498. render :layout => 'base_bids'
  499. }
  500. else
  501. format.html {
  502. render :layout => 'base_contest'
  503. }
  504. end
  505. format.api
  506. end
  507. end
  508. ###添加应标项目
  509. def add
  510. project = Project.find(params[:bid])
  511. bid_message = params[:bid_for_save][:bid_message]
  512. if BidingProject.where("project_id = ? and bid_id = ?", project.id, @bid.id).size == 0
  513. if BidingProject.cerate_bidding(@bid.id, project.id, bid_message)
  514. # added by bai type ==1 需求,type==2 竞赛, type==3 作业
  515. if @bid.reward_type == 1
  516. flash.now[:notice] = l(:label_bidding_succeed)
  517. elsif @bid.reward_type == 2
  518. flash.now[:notice] = l(:label_bidding_contest_succeed)
  519. else @bid.reward_type == 3
  520. flash.now[:notice] = l(:label_bidding_homework_succeed)
  521. end
  522. # end
  523. end
  524. else
  525. if @bid.reward_type == 3
  526. flash.now[:error] = l(:label_bidding_homework_fail)
  527. else
  528. flash.now[:error] = l(:label_bidding_fail)
  529. end
  530. end
  531. @bidding_project = @bid.biding_projects
  532. respond_to do |format|
  533. # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
  534. # format.html
  535. format.html { redirect_to :back }
  536. format.js
  537. #format.api { render_api_ok }
  538. end
  539. end
  540. #删除已提交的项目作业(不删项目)
  541. def delete
  542. binding_project = params[:binding_project]
  543. if can_delete_project_homework(BidingProject.find(binding_project),User.current)
  544. if BidingProject.delete(binding_project)
  545. redirect_to project_for_bid_path
  546. else
  547. redirect_to 403;
  548. end
  549. end
  550. end
  551. ## 新建留言
  552. def create
  553. if params[:bid_message][:message].size>0
  554. if params[:reference_content]
  555. message = params[:bid_message][:message] + "\n" + params[:reference_content]
  556. else
  557. message = params[:bid_message][:message]
  558. @m = message
  559. end
  560. refer_user_id = params[:bid_message][:reference_user_id].to_i
  561. @bid.add_jour(User.current, message, refer_user_id)
  562. end
  563. @user = @bid.author
  564. @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
  565. @limit = 10
  566. @feedback_count = @jours.count
  567. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  568. @offset ||= @feedback_pages.offset
  569. @jour = @jours[@offset, @limit]
  570. @bid.set_commit(@feedback_count)
  571. respond_to do |format|
  572. format.js
  573. #format.api { render_api_ok }
  574. end
  575. end
  576. ##删除留言
  577. def destroy
  578. @user = @bid.author
  579. if User.current.admin? || User.current.id == @user.id
  580. JournalsForMessage.delete_message(params[:object_id])
  581. end
  582. @jours = @bid.journals_for_messages.reverse
  583. @limit = 10
  584. @feedback_count = @jours.count
  585. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  586. @offset ||= @feedback_pages.offset
  587. @jour = @jours[@offset, @limit]
  588. @bid.set_commit(@feedback_count)
  589. # if a_message.size > 5
  590. # @message = a_message[-5, 5]
  591. # else
  592. # @message = a_message
  593. # end
  594. # @message_count = a_message.count
  595. respond_to do |format|
  596. # format.html
  597. format.js
  598. #format.api { render_api_ok }
  599. end
  600. end
  601. #删除作业
  602. #by xianbo
  603. def homework_destroy
  604. @bid_to_destroy = Bid.find params[:course_id]
  605. (render_403; return false) unless User.current.admin?||User.current.id==@bid_to_destroy.author_id
  606. @bid_to_destroy.destroy
  607. respond_to do |format|
  608. format.html { redirect_to :back }
  609. format.js
  610. #format.api { render_api_ok }
  611. end
  612. end
  613. #end by xianbo
  614. ##引用
  615. def new
  616. @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
  617. if @jour
  618. user = @jour.user
  619. text = @jour.notes
  620. else
  621. user = @bid.author
  622. text = @bid.description
  623. end
  624. # Replaces pre blocks with [...]
  625. text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
  626. @content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
  627. @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
  628. @id = user.id
  629. rescue ActiveRecord::RecordNotFound
  630. render_404
  631. end
  632. ##新建需求
  633. def new_bid
  634. @bid = Bid.new
  635. @bid.safe_attributes = params[:bid]
  636. end
  637. #huang
  638. def create_contest
  639. @bid = Bid.new
  640. @bid.name = params[:bid][:name]
  641. @bid.description = params[:bid][:description]
  642. @bid.reward_type = 2
  643. @bid.budget = params[:bid][:budget]
  644. @bid.deadline = params[:bid][:deadline]
  645. @bid.password = params[:bid][:password] #added by bai
  646. @bid.author_id = User.current.id
  647. @bid.commit = 0
  648. if @bid.save
  649. unless @bid.watched_by?(User.current)
  650. if @bid.add_watcher(User.current)
  651. flash[:notice] = l(:label_bid_succeed)
  652. end
  653. end
  654. redirect_to respond_path(@bid)
  655. else
  656. @bid.safe_attributes = params[:bid]
  657. render :action => 'new_bid'
  658. end
  659. end
  660. # added by bai
  661. def update_contest
  662. @bid = Bid.find(params[:id])
  663. @bid.name = params[:bid][:name]
  664. @bid.description = params[:bid][:description]
  665. @bid.reward_type = 2
  666. @bid.budget = params[:bid][:budget]
  667. @bid.deadline = params[:bid][:deadline]
  668. @bid.password = params[:bid][:password]
  669. @bid.author_id = User.current.id
  670. @bid.commit = 0
  671. if @bid.save
  672. unless @bid.watched_by?(User.current)
  673. if @bid.add_watcher(User.current)
  674. flash[:notice] = l(:label_bid_succeed)
  675. end
  676. end
  677. redirect_to respond_path(@bid)
  678. else
  679. @bid.safe_attributes = params[:bid]
  680. render :action => 'new_bid'
  681. end
  682. end
  683. #huang
  684. def new_contest
  685. @bid = Bid.new
  686. @bid.safe_attributes = params[:bid]
  687. end
  688. def create_bid
  689. @bid = Bid.new
  690. @bid.name = params[:bid][:name]
  691. @bid.description = params[:bid][:description]
  692. @bid.reward_type = 1
  693. @bid.budget = params[:bid][:budget]
  694. @bid.deadline = params[:bid][:deadline]
  695. @bid.author_id = User.current.id
  696. @bid.commit = 0
  697. if @bid.save
  698. unless @bid.watched_by?(User.current)
  699. if @bid.add_watcher(User.current)
  700. flash[:notice] = l(:label_bid_succeed)
  701. end
  702. end
  703. redirect_to respond_path(@bid)
  704. else
  705. @bid.safe_attributes = params[:bid]
  706. render :action => 'new_bid'
  707. end
  708. end
  709. def create_homework
  710. @bid = Bid.new
  711. @bid.name = params[:bid][:name]
  712. @bid.description = params[:bid][:description]
  713. @bid.is_evaluation = params[:bid][:is_evaluation]
  714. @bid.reward_type = 3
  715. # @bid.budget = params[:bid][:budget]
  716. @bid.deadline = params[:bid][:deadline]
  717. @bid.budget = 0
  718. @bid.author_id = User.current.id
  719. @bid.commit = 0
  720. @bid.homework_type = 1
  721. @bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
  722. # @bid.
  723. if @bid.save
  724. HomeworkForCourse.create(:course_id => params[:course_id], :bid_id => @bid.id)
  725. unless @bid.watched_by?(User.current)
  726. if @bid.add_watcher(User.current)
  727. flash[:notice] = l(:label_bid_succeed)
  728. end
  729. end
  730. redirect_to respond_path(@bid)
  731. else
  732. @bid.safe_attributes = params[:bid]
  733. @homework = @bid
  734. @course = Course.find_by_id(params[:course_id])
  735. @course_id = @course.id
  736. render file: 'courses/new_homework', layout: 'base_courses'
  737. end
  738. end
  739. # modify by nwb\
  740. # 编辑作业
  741. def edit
  742. @bid = Bid.find(params[:bid_id])
  743. if (User.current.admin?||User.current.id==@bid.author_id)
  744. @course_id = params[:course_id]
  745. respond_to do |format|
  746. format.html {
  747. @course = Course.find(params[:course_id])
  748. @user= User.find(User.current.id)
  749. render :layout => 'base_courses'
  750. }
  751. end
  752. else
  753. render 403
  754. end
  755. end
  756. def update
  757. @bid = Bid.find(params[:id])
  758. @course = @bid.courses.first#Project.find(params[:course_id])
  759. @bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
  760. if @bid.update_attributes(params[:bid]) && @bid.save
  761. flash[:notice] = l(:label_update_homework_succeed)
  762. redirect_to course_homework_path(@course)
  763. else
  764. @bid.safe_attributes = params[:bid]
  765. render :action => 'edit', :layout =>'base_courses'
  766. end
  767. end
  768. def new_submit_homework
  769. #render html to prepare create submit homework
  770. find_bid
  771. render :layout => 'base_homework'
  772. end
  773. def add_homework
  774. 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)
  775. # homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
  776. # homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
  777. if hadcommittedhomework(User.current.id, @bid.id) == true
  778. @homework_flag = l(:label_bidding_homework_committed)
  779. else
  780. @homework = HomeworkAttach.new
  781. @homework.safe_attributes = params[:homeworkattach]
  782. @homework.bid_id = @bid.id
  783. @homework.user_id = User.current.id
  784. @homework.save_attachments(params[:attachments])
  785. render_attachment_warning_if_needed(@homework)
  786. @homework_flag = if @homework.save
  787. l(:label_bidding_homework_succeed)
  788. else
  789. l(:label_bidding_homework_failed)
  790. end
  791. if @homework.attachments.empty?
  792. @homework.delete
  793. #flash[:error] = l(:no_attachmens_allowed)
  794. @homework_flag = l(:no_attachmens_allowed)
  795. # else
  796. end
  797. end
  798. end
  799. @homework_list = @bid.homeworks
  800. respond_to do |format|
  801. format.html{
  802. #redirect_to project_for_bid_path, notice: @homework_flag.to_s
  803. flash[:notice] = @homework_flag.to_s
  804. redirect_back_or_default(project_for_bid_path)
  805. }
  806. format.js
  807. end
  808. end
  809. # 作业统计
  810. def homework_statistics
  811. @course = @bid.courses.first
  812. @member = []
  813. @course.memberships.each do |member|
  814. unless (member.roles && Role.where('id = ? ', 3)).empty?
  815. @member.push member
  816. end
  817. end
  818. if @bid.homework_type = 1
  819. @student = User.where("id in (select DISTINCT user_id from #{HomeworkAttach.table_name} where bid_id = ? )", @bid.id)
  820. @homework_type = true
  821. else
  822. @homework_type = false
  823. end
  824. @user = @bid.author
  825. render :layout => 'base_homework'
  826. end
  827. def homework_respond
  828. @user = @bid.author
  829. render :layout => 'base_homework'
  830. end
  831. def more
  832. @jour = @bid.journals_for_messages
  833. @jour.each_with_index {|j,i| j.indice = i+1}
  834. @state = true
  835. respond_to do |format|
  836. format.html { redirect_to :back }
  837. format.js
  838. #format.api { render_api_ok }
  839. end
  840. end
  841. def back
  842. @jour = @bid.journals_for_messages
  843. @jour.each_with_index {|j,i| j.indice = i+1}
  844. @state = false
  845. respond_to do |format|
  846. format.html { redirect_to :back }
  847. format.js
  848. #format.api { render_api_ok }
  849. end
  850. end
  851. #added by william
  852. #used to set the bidding project reward
  853. def set_reward
  854. @b_p = nil
  855. @biding_project_id = nil
  856. if params[:set_reward][:reward]&&((User.current.id==@bid.author_id)||User.current.admin)
  857. # @bid_id = params[:id]
  858. @biding_project_id = params[:set_reward][:b_id]
  859. @b_p = BidingProject.find_by_id(@biding_project_id)
  860. # 把字段存进表中
  861. @b_p.update_reward(params[:set_reward][:reward].to_s)
  862. end
  863. respond_to do |format|
  864. format.js
  865. end
  866. end
  867. # added by william
  868. # used to manage the bid and end the bid
  869. def manage
  870. end
  871. private
  872. def find_bid
  873. if params[:id]
  874. @bid = Bid.find(params[:id], :include => [{:homeworks => :user}])
  875. @user = @bid.author
  876. end
  877. rescue
  878. render_404
  879. end
  880. def memberAccess
  881. # 是课程,则判断当前用户是否参加了课程
  882. return true if current_user.admin?
  883. #return 0 if @bid.courses.first.project_type == Project::ProjectType_project
  884. currentUser = User.current
  885. render_403 unless currentUser.member_of_cousrse?(@bid.courses.first)
  886. end
  887. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...