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.

contests_controller.rb 23 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736
  1. # fq
  2. # class BidsController < ApplicationController
  3. class ContestsController < ApplicationController
  4. layout "contest_base"
  5. menu_item :respond
  6. menu_item :project, :only => :show_project
  7. menu_item :application, :only => :show_softapplication
  8. menu_item :attendingcontests, :only => :show_attendingcontest
  9. menu_item :contestnotifications, :only => :index
  10. before_filter :can_show_contest, :except => [] # modified by alan
  11. # modified by longjun
  12. before_filter :find_contest, :only => [
  13. :show_contest, :show_project, :show_softapplication,
  14. :show_attendingcontest, :index, :set_reward_project,
  15. :set_reward_softapplication, :create, :destroy, :more,
  16. :back, :add, :add_softapplication, :new,:show_results,
  17. :set_reward, :show_contest_project, :show_contest_user, :watcherlist,
  18. :join_in_contest, :unjoin_in_contest, :new_join, :settings
  19. ]
  20. # end longjun
  21. # added by fq
  22. before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
  23. # end
  24. before_filter :require_login,:only => [:set_reward, :destroy, :add, :new ]
  25. helper :watchers
  26. helper :attachments
  27. helper :projects
  28. helper :words
  29. include AttachmentsHelper
  30. include ApplicationHelper
  31. def index
  32. render_404 unless params[:name]
  33. # @contests = Contest.visible
  34. # @contests ||= []
  35. @offset, @limit = api_offset_and_limit(:limit => 10)
  36. #@contests = Contest.visible
  37. #@contests = @contests.like(params[:name]) if params[:name].present?
  38. @is_search = params[:name] ? true:false
  39. @contests = Contest.visible.where("name like '%#{params[:name]}%'")
  40. if params[:contests_search]
  41. (redirect_to contests_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
  42. end
  43. @contest_count = @contests.count
  44. @contest_pages = Paginator.new @contest_count, @limit, params['page']
  45. @offset ||= @contest_pages.reverse_offset
  46. if params[:contest_sort_type].present?
  47. case params[:contest_sort_type]
  48. when '0'
  49. # modified by longjun
  50. # never use unless and else, 将下面重复操作模块化,放在private下
  51. # unless @offset == 0
  52. # if @offset != 0
  53. # @contests = @contests.reorder('contests.commit').offset(@offset).limit(@limit).all.reverse
  54. # else
  55. # limit = @contest_count % @limit
  56. # limit = @limit if limit == 0
  57. # @contests = @contests.reorder('contests.commit').offset(@offset).limit(limit).all.reverse
  58. @contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.commit')
  59. # end
  60. @s_state = 0
  61. when '1'
  62. @contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.created_on')
  63. @s_state = 1
  64. # modified by longjun
  65. # 目前只有 0, 1 两个sort_type
  66. # when '2'
  67. else
  68. # end longjun
  69. @contests = index_page_sort(@offset, @limit, @contest_count, @contests, '')
  70. @s_state = 0
  71. end
  72. else
  73. # modified by longjun
  74. # never use unless and else
  75. # unless @offset == 0
  76. if @offset != 0
  77. @contests = @contests.reorder('contests.created_on').offset(@offset).limit(@limit).all.reverse
  78. else
  79. limit = @contest_count % @limit
  80. limit = @limit if limit == 0
  81. @contests = @contests.reorder('contests.created_on').offset(@offset).limit(limit).all.reverse
  82. end
  83. @s_state = 1
  84. end
  85. end
  86. def search
  87. redirect_to action: 'index',name:params[:name]
  88. end
  89. def homework
  90. @offset, @limit = api_offset_and_limit({:limit => 10})
  91. @bids = @course.homeworks.order('deadline DESC')
  92. @bids = @bids.like(params[:name]) if params[:name].present?
  93. @bid_count = @bids.count
  94. @bid_pages = Paginator.new @bid_count, @limit, params['page']
  95. @offset ||= @bid_pages.reverse_offset
  96. # modified by longjun
  97. # never use unless and else
  98. # unless @offset == 0
  99. if @offset != 0
  100. @bids = @bids.offset(@offset).limit(@limit).all.reverse
  101. else
  102. limit = @bid_count % @limit
  103. @bids = @bids.offset(@offset).limit(limit).all.reverse
  104. end
  105. render :layout => 'base_courses'
  106. end
  107. def show_contest
  108. @user = @contest.author
  109. @jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
  110. #@limit = 10
  111. #@feedback_count = @jours.count
  112. #@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  113. #@offset ||= @feedback_pages.offset
  114. #@jour = @jours[@offset, @limit]
  115. @jour = paginateHelper @jours,10
  116. @state = false
  117. respond_to do |format|
  118. format.html {
  119. render :layout => 'base_newcontest'
  120. }
  121. format.api
  122. end
  123. end
  124. def join_in_contest
  125. if params[:contest_password] == @contest.password
  126. JoinInCompetition.create(:user_id => User.current.id, :competition_id => @contest.id)
  127. @state = 0
  128. else
  129. @state = 1
  130. end
  131. respond_to do |format|
  132. format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
  133. end
  134. end
  135. def unjoin_in_contest
  136. joined = JoinInCompetition.where('competition_id = ? and user_id = ?', @contest.id, User.current.id)
  137. joined.each do |join|
  138. join.delete
  139. end
  140. respond_to do |format|
  141. format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
  142. end
  143. end
  144. def show_participator
  145. render :layout => 'base_newcontest'
  146. end
  147. def settings
  148. if @contest.author.id == User.current.id
  149. @contest = Contest.find(params[:id])
  150. render :layout => 'base_newcontest'
  151. else
  152. render_403 :message => :notice_not_contest_setting_authorized
  153. end
  154. end
  155. # Added by Longjun
  156. def destroy_contest
  157. @contest = Contest.find(params[:id])
  158. if @contest.author_id == User.current.id || User.current.admin?
  159. @contest.destroy
  160. redirect_to welcome_contest_url
  161. else
  162. render_403 :message => :notice_not_contest_delete_authorized
  163. end
  164. end
  165. # end
  166. def show_contest_project
  167. contests = Contest.where('parent_id = ?', @contest.id)
  168. @projects = []
  169. # Modified by longjun
  170. # 用 arr.each 替换 for [ according to the style guide ]
  171. # for contest in contests
  172. # @projects += contest.contesting_projects
  173. # end
  174. contests.each do |contest|
  175. @projects += contest.contesting_projects
  176. end
  177. # end
  178. respond_to do |format|
  179. format.html {
  180. render :layout => 'base_newcontest'
  181. }
  182. format.api
  183. end
  184. end
  185. def show_contest_softapplication
  186. contests = Contest.where('parent_id = ?', @contest.id)
  187. @softapplications = []
  188. # Modified by Longjun
  189. # for contest in contests
  190. # @softapplications += contest.contesting_softapplications
  191. contests.each do |contest|
  192. @softapplications += contest.contesting_softapplications
  193. end
  194. # end
  195. respond_to do |format|
  196. format.html {
  197. render :layout => 'base_newcontest'
  198. }
  199. format.api
  200. end
  201. end
  202. def show_contest_user
  203. contests = Contest.find(:all)
  204. @users = []
  205. # Modified by Longjun
  206. # for contest in contests
  207. # for project in contest.projects
  208. # @users += project.users
  209. # end
  210. contests.each do |contest|
  211. contest.projects.each do |project|
  212. @users += project.users
  213. end
  214. end
  215. # end
  216. respond_to do |format|
  217. format.html {
  218. render :layout => 'base_newcontest'
  219. }
  220. format.api
  221. end
  222. end
  223. #显示参赛的项目
  224. def show_project
  225. @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  226. @option = []
  227. # @contesting_project_count = @contesting_project_all.count
  228. # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
  229. @membership.each do |membership|
  230. # Modified by Longjun
  231. # 将两个判断语句合并
  232. # unless membership.project.project_type==1
  233. # if User.current.allowed_to?(:quote_project, membership.project)
  234. # @option << membership.project
  235. # end
  236. # end
  237. if membership.project.project_type != 1 && User.current.allowed_to?(:quote_project, membership.project)
  238. @option << membership.project
  239. end
  240. # end
  241. end
  242. @user = @contest.author
  243. @contesting_project = @contest.contesting_projects.all
  244. if params[:student_id].present?
  245. @temp = []
  246. @contesting_project.each do |pro|
  247. if pro.project && pro.project.project_status
  248. if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  249. @temp << pro
  250. end
  251. end
  252. @temp
  253. end
  254. @contesting_project = @temp
  255. else
  256. @temp = []
  257. @contesting_project.each do |pro|
  258. # modified by longjun
  259. # if pro.project && pro.project.project_status
  260. # @temp << pro
  261. # end
  262. @temp << pro if pro.project && pro.project.project_status
  263. # end longjun
  264. @temp
  265. end
  266. if @temp.size > 0
  267. @contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
  268. end
  269. end
  270. @contesting_project = paginateHelper(@contesting_project)
  271. respond_to do |format|
  272. format.html {
  273. render :layout => 'base_newcontest'
  274. }
  275. format.api
  276. end
  277. end
  278. ############
  279. ##显示参赛的应用
  280. def show_softapplication
  281. # @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  282. # @option = []
  283. # @user = @contest.user
  284. @softapplication = Softapplication.all
  285. @contesting_softapplication = @contest.contesting_softapplications
  286. @contesting_softapplication = paginateHelper(@contesting_softapplication, 10)
  287. # @temp = []
  288. # @softapplicationt.each do |pro|
  289. # if pro.project && pro.project.project_status
  290. # @temp << pro
  291. # end
  292. # @temp
  293. # if @temp.size > 0
  294. # @contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
  295. # end
  296. # end
  297. # respond_to do |format|
  298. # format.html {
  299. # render :layout => 'base_newcontest'
  300. # }
  301. # format.api
  302. # end
  303. ##########################
  304. @contest = Contest.find_by_id(params[:id])
  305. respond_to do |format|
  306. format.html {
  307. render :layout => 'base_newcontest'
  308. }
  309. format.api
  310. end
  311. end
  312. ###我要参赛
  313. def show_attendingcontest
  314. ##取出参赛项目--项目列表
  315. @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  316. @option = []
  317. # @contesting_project_count = @contesting_project_all.count
  318. # @contesting_project_pages = Paginator.new @contesting_project_count, per_page_option, params['page']
  319. @membership.each do |membership|
  320. unless membership.project.project_type==1
  321. #拥有编辑项目权限的可将该项目参赛
  322. if User.current.allowed_to?(:quote_project, membership.project)
  323. @option << membership.project
  324. end
  325. end
  326. end
  327. @user = @contest.author
  328. @contesting_project = @contest.contesting_projects.all
  329. if params[:student_id].present?
  330. @temp = []
  331. @contesting_project.each do |pro|
  332. if pro.project && pro.project.project_status
  333. if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  334. @temp << pro
  335. end
  336. end
  337. @temp
  338. end
  339. @contesting_project = @temp
  340. else
  341. @temp = []
  342. @contesting_project.each do |pro|
  343. # modified by longjun
  344. # if pro.project && pro.project.project_status
  345. # @temp << pro
  346. # end
  347. @temp << pro if pro.project && pro.project.project_status
  348. # end longjun
  349. @temp
  350. end
  351. if @temp.size > 0
  352. @contesting_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
  353. end
  354. end
  355. # 取出参赛应用 --应用列表
  356. @softapplication = Softapplication.all
  357. @contesting_softapplication = @contest.contesting_softapplications.
  358. joins("LEFT JOIN softapplications ON contesting_softapplications.softapplication_id=softapplications.id").
  359. joins("LEFT JOIN (
  360. SELECT * FROM seems_rateable_cached_ratings
  361. WHERE cacheable_type='Softapplication' AND DIMENSION = 'quality') AS cached
  362. ON cached.cacheable_id=softapplications.id").
  363. order("cached.avg").reverse_order
  364. @contesting_softapplication = paginateHelper @contesting_softapplication, 10
  365. #引用base_newcontest整体样式
  366. @contest = Contest.find_by_id(params[:id])
  367. respond_to do |format|
  368. format.html {
  369. render :layout => 'base_newcontest'
  370. }
  371. format.api
  372. end
  373. end
  374. ###end
  375. def show_notification
  376. @contest = Contest.find_by_id(params[:id])
  377. respond_to do |format|
  378. format.html {
  379. render :layout => 'base_newcontest'
  380. }
  381. format.api
  382. end
  383. end
  384. def set_reward_project
  385. @c_p = nil
  386. @contesting_project_id = nil
  387. if params[:set_reward_project][:reward]&&((User.current.id==@contest.author_id)||User.current.admin)
  388. # @bid_id = params[:id]
  389. @contesting_project_id = params[:set_reward_project][:c_id]
  390. @c_p = ContestingProject.find_by_id(@contesting_project_id)
  391. # 把字段存进表中
  392. @c_p.update_reward(params[:set_reward_project][:reward].to_s)
  393. end
  394. respond_to do |format|
  395. format.js
  396. end
  397. end
  398. def set_reward_softapplication
  399. @c_sa = nil
  400. @contesting_softapplication_id = nil
  401. if params[:set_reward_softapplication][:reward]&&((User.current.id==@contest.author_id)||User.current.admin)
  402. # @bid_id = params[:id]
  403. @contesting_softapplication_id = params[:set_reward_softapplication][:c_id]
  404. @c_sa = ContestingSoftapplication.find_by_id(@contesting_softapplication_id)
  405. # 把字段存进表中
  406. @c_sa.update_reward(params[:set_reward_softapplication][:reward].to_s)
  407. end
  408. respond_to do |format|
  409. format.js
  410. end
  411. end
  412. ###添加已创建的参赛项目
  413. def add
  414. project = Project.find(params[:contest])
  415. contest_message = params[:contest_for_save][:contest_message]
  416. if ContestingProject.where("project_id = ? and contest_id = ?", project.id, @contest.id).size == 0
  417. # modified by longjun, create 写错了
  418. # if ContestingProject.cerate_contesting(@contest.id, project.id, contest_message)
  419. if ContestingProject.create_contesting(@contest.id, project.id, contest_message)
  420. # end longjun
  421. flash.now[:notice] = l(:label_bidding_contest_succeed)
  422. end
  423. else
  424. flash.now[:error] = l(:label_bidding_fail)
  425. end
  426. @contesting_project = paginateHelper @contest.contesting_projects
  427. respond_to do |format|
  428. format.html { redirect_to :back }
  429. format.js
  430. end
  431. end
  432. ###添加已发布的参赛应用
  433. def add_softapplication
  434. softapplication = Softapplication.find(params[:contest])
  435. contest_message = params[:contest_for_save][:contest_message]
  436. if ContestingSoftapplication.where("softapplication_id = ? and contest_id = ?", softapplication.id, @contest.id).size == 0
  437. if ContestingSoftapplication.create_softapplication_contesting(@contest.id, softapplication.id, contest_message)
  438. flash.now[:notice] = l(:label_release_add_contest_succeed)
  439. end
  440. else
  441. flash.now[:error] = l(:label_add_contest_succeed_fail)
  442. end
  443. @contesting_softapplication = paginateHelper @contest.contesting_softapplications
  444. respond_to do |format|
  445. format.html { redirect_to :back }
  446. format.js
  447. end
  448. end
  449. ## 新建留言
  450. def create
  451. if params[:contest_message][:message].size>0
  452. if params[:reference_content]
  453. message = params[:contest_message][:message] + "\n" + params[:reference_content]
  454. else
  455. message = params[:contest_message][:message]
  456. end
  457. refer_user_id = params[:contest_message][:reference_user_id].to_i
  458. @contest.add_jour(User.current, message, refer_user_id)
  459. end
  460. @user = @contest.author
  461. @jours = @contest.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
  462. @limit = 10
  463. @feedback_count = @jours.count
  464. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  465. @offset ||= @feedback_pages.offset
  466. @jour = @jours[@offset, @limit]
  467. @contest.set_commit(@feedback_count)
  468. respond_to do |format|
  469. format.js
  470. end
  471. end
  472. ##删除留言
  473. def destroy
  474. @user = @contest.author
  475. if User.current.admin? || User.current.id == @user.id
  476. JournalsForMessage.delete_message(params[:object_id])
  477. end
  478. @jours = @contest.journals_for_messages.reverse
  479. @limit = 10
  480. @feedback_count = @jours.count
  481. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  482. @offset ||= @feedback_pages.offset
  483. @jour = @jours[@offset, @limit]
  484. @contest.set_commit(@feedback_count)
  485. respond_to do |format|
  486. format.js
  487. end
  488. end
  489. ##引用留言
  490. def new
  491. @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
  492. if @jour
  493. user = @jour.user
  494. text = @jour.notes
  495. else
  496. user = @contest.author
  497. text = @contest.description
  498. end
  499. text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
  500. @content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
  501. @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
  502. @id = user.id
  503. rescue ActiveRecord::RecordNotFound
  504. render_404
  505. end
  506. ##新建竞赛
  507. def new_contest
  508. @contest = Contest.new
  509. @contest.safe_attributes = params[:contest]
  510. end
  511. ##提交创建的竞赛
  512. def create_contest
  513. @contest = Contest.new
  514. @contest.name = params[:contest][:name]
  515. @contest.description = params[:contest][:description]
  516. @contest.budget = params[:contest][:budget]
  517. @contest.deadline = params[:contest][:deadline]
  518. @contest.password = params[:contest][:password]
  519. @contest.author_id = User.current.id
  520. @contest.commit = 0
  521. if @contest.save
  522. unless @contest.watched_by?(User.current)
  523. if @contest.add_watcher(User.current)
  524. flash[:notice] = l(:label_contesting_created_succeed)
  525. end
  526. end
  527. redirect_to show_contest_contest_url(@contest)
  528. else
  529. @contest.safe_attributes = params[:contest]
  530. render :action => 'new_contest'
  531. end
  532. end
  533. ##更新竞赛配置信息
  534. def update_contest
  535. @contest = Contest.find(params[:id])
  536. @contest.name = params[:contest][:name]
  537. @contest.description = params[:contest][:description]
  538. @contest.budget = params[:contest][:budget]
  539. @contest.deadline = params[:contest][:deadline]
  540. @contest.password = params[:contest][:password]
  541. @contest.author_id = User.current.id
  542. @contest.commit = 0
  543. if @contest.save
  544. unless @contest.watched_by?(User.current)
  545. if @contest.add_watcher(User.current)
  546. flash[:notice] = l(:label_contesting_updated_succeed)
  547. end
  548. end
  549. redirect_to show_contest_contest_url(@contest)
  550. else
  551. @contest.safe_attributes = params[:contest]
  552. render :action => 'new_contest'
  553. end
  554. end
  555. def more
  556. @jour = @contest.journals_for_messages
  557. @jour.each_with_index {|j,i| j.indice = i+1}
  558. @state = true
  559. respond_to do |format|
  560. format.html { redirect_to :back }
  561. format.js
  562. #format.api { render_api_ok }
  563. end
  564. end
  565. def back
  566. @jour = @contest.journals_for_messages
  567. @jour.each_with_index {|j,i| j.indice = i+1}
  568. @state = false
  569. respond_to do |format|
  570. format.html { redirect_to :back }
  571. format.js
  572. #format.api { render_api_ok }
  573. end
  574. end
  575. def set_reward
  576. @b_p = nil
  577. @contesting_project_id = nil
  578. if params[:set_reward][:reward]&&((User.current.id==@contest.author_id)||User.current.admin)
  579. # @contest_id = params[:id]
  580. @contesting_project_id = params[:set_reward][:b_id] #[:b_id]???
  581. @b_p = ContestingProject.find_by_id(@contesting_project_id)
  582. # 把字段存进表中
  583. @b_p.update_reward(params[:set_reward][:reward].to_s)
  584. end
  585. respond_to do |format|
  586. format.js
  587. end
  588. end
  589. def watcherlist
  590. render :layout => 'base_newcontest'
  591. end
  592. private
  593. def find_contest
  594. if params[:id]
  595. @contest = Contest.find(params[:id])
  596. @user = @contest.author
  597. end
  598. rescue
  599. render_404
  600. end
  601. #验证是否显示竞赛
  602. def can_show_contest
  603. @first_page = FirstPage.find_by_page_type('project')
  604. if @first_page.show_contest == 2
  605. render_404
  606. end
  607. end
  608. # added by longjun
  609. # 将index页面中分页排序的方法抽离出来
  610. def index_page_sort(offset, limit, contest_count, contests, contest_sort_by)
  611. # modified by longjun
  612. # never use unless and else
  613. # unless @offset == 0
  614. if offset != 0
  615. contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse
  616. else
  617. limit = contest_count % limit
  618. limit = limit if limit == 0
  619. contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse
  620. end
  621. contests
  622. end
  623. end

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