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 36 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  1. # # fq
  2. #Bid功能已经废弃,代码参考用
  3. # class BidsController < ApplicationController
  4. # #Added by young
  5. # menu_item l(:label_homework), :only => [:edit, :udpate]
  6. # menu_item :respond
  7. # menu_item :course, :only => :show_courseEx
  8. # menu_item :project, :only => [:show_project,:show_results, :new_submit_homework]
  9. # menu_item :homework_respond, :only => :homework_respond
  10. # menu_item :homework_statistics, :only => :homework_statistics
  11. # menu_item :edit, :only => :edit
  12. #
  13. # before_filter :auth_login1, :only => [:show_courseEx]
  14. #
  15. # before_filter :can_show_course,only: []
  16. # before_filter :can_show_contest,only: []
  17. # #Ended by young
  18. # before_filter :find_bid, :only => [:show, :show_project, :create,:destroy,:more,:back,:add,:delete,:new,:show_results,:set_reward, :add_homework, :fork, :create_fork,
  19. # :show_course, :show_courseEx,:show_bid_project, :show_bid_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
  20. # # added by fq
  21. # before_filter :require_login, :only => [:join_in_contest, :unjoin_in_contest]
  22. # # end
  23. # before_filter :require_login,:only => [:set_reward, :destroy, :add, :new, ]
  24. #
  25. # #before_filter :memberAccess, only: :show_project
  26. #
  27. # helper :watchers
  28. # helper :attachments
  29. # include AttachmentsHelper
  30. # include ApplicationHelper
  31. # include BidsHelper
  32. #
  33. # helper :projects
  34. # helper :words
  35. # helper :welcome
  36. # helper :project_score
  37. #
  38. # def find_project_by_bid_id
  39. # @bid = Bid.find(params[:id])
  40. # @project = @bid.courses[0]
  41. # rescue ActiveRecord::RecordNotFound
  42. # render_404
  43. # end
  44. #
  45. # def homework_ajax_modal
  46. # @bid = Bid.find_by_id(params[:id])
  47. # # find_bid
  48. # respond_to do |format|
  49. # format.js
  50. # end
  51. # end
  52. #
  53. #
  54. # def index
  55. # @project_type = params[:project_type]
  56. # # Modified by nie
  57. # # @requirement_title = "4"
  58. # @offset, @limit = api_offset_and_limit({:limit => 10})
  59. # if @project_type == '1'
  60. # @bids = Bid.visible.where('reward_type = ?', 3)
  61. # # elsif
  62. # # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
  63. # else
  64. # @bids = Bid.visible.where('reward_type = ?', 1)
  65. # end
  66. #
  67. # @bids = @bids.like(params[:name]) if params[:name].present?
  68. # @bid_count = @bids.count
  69. # @bid_pages = Paginator.new @bid_count, @limit, params['page']
  70. #
  71. # @offset ||= @bid_pages.reverse_offset
  72. # #added by nie
  73. # if params[:bid_sort_type].present?
  74. # case params[:bid_sort_type]
  75. # when '0'
  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. # when '1'
  85. # unless @offset == 0
  86. # @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
  87. # else
  88. # limit = @bid_count % @limit
  89. # limit = @limit if limit == 0
  90. # @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
  91. # end
  92. # @s_state = 1
  93. # when '2'
  94. # unless @offset == 0
  95. # @bids = @bids.offset(@offset).limit(@limit).all.reverse
  96. # else
  97. # limit = @bid_count % @limit
  98. # limit = @limit if limit == 0
  99. # @bids = @bids.offset(@offset).limit(@limit).all.reverse
  100. # end
  101. # @s_state = 0
  102. # end
  103. # else
  104. # unless @offset == 0
  105. # @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
  106. # else
  107. # limit = @bid_count % @limit
  108. # limit = @limit if limit == 0
  109. # @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
  110. # end
  111. # @s_state = 1
  112. # end
  113. # #end
  114. # end
  115. # #huang
  116. # def contest
  117. #
  118. # # Modified by nie
  119. # # @requirement_title = "4"
  120. # @offset, @limit = api_offset_and_limit({:limit => 10})
  121. #
  122. # @bids = Bid.visible.where('reward_type = ?', 2)
  123. #
  124. # # elsif
  125. # # @bids = Bid.visible.where('reward_type = ? or reward_type = ?', 4)
  126. # @bids = @bids.like(params[:name]) if params[:name].present?
  127. # @bid_count = @bids.count
  128. # @bid_pages = Paginator.new @bid_count, @limit, params['page']
  129. #
  130. # @offset ||= @bid_pages.reverse_offset
  131. # #added by nie
  132. # if params[:contest_sort_type].present?
  133. # case params[:contest_sort_type]
  134. # when '0'
  135. # unless @offset == 0
  136. # @bids = @bids.offset(@offset).limit(@limit).all.reverse
  137. # else
  138. # limit = @bid_count % @limit
  139. # limit = @limit if limit == 0
  140. # @bids = @bids.offset(@offset).limit(limit).all.reverse
  141. # end
  142. # @s_state = 0
  143. # when '1'
  144. # unless @offset == 0
  145. # @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
  146. # else
  147. # limit = @bid_count % @limit
  148. # limit = @limit if limit == 0
  149. # @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
  150. # end
  151. # @s_state = 1
  152. # when '2'
  153. # unless @offset == 0
  154. # @bids = @bids.offset(@offset).limit(@limit).all.reverse
  155. # else
  156. # limit = @bid_count % @limit
  157. # limit = @limit if limit == 0
  158. # @bids = @bids.offset(@offset).limit(@limit).all.reverse
  159. # end
  160. # @s_state = 0
  161. # end
  162. # else
  163. # unless @offset == 0
  164. # @bids = @bids.reorder('bids.commit').offset(@offset).limit(@limit).all.reverse
  165. # else
  166. # limit = @bid_count % @limit
  167. # limit = @limit if limit == 0
  168. # @bids = @bids.reorder('bids.commit').offset(@offset).limit(limit).all.reverse
  169. # end
  170. # @s_state = 1
  171. # end
  172. # #end
  173. # end
  174. #
  175. # def fork
  176. # @courses = []
  177. # @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  178. # @membership.each do |membership|
  179. # if membership.project.project_type == 1
  180. # @courses << membership.project
  181. # end
  182. # end
  183. # end
  184. #
  185. # #将某个企业外包需求选为作业,目前此功能已放弃
  186. # def create_fork
  187. # @homework = Bid.new
  188. # @homework.name = params[:bid][:name]
  189. # @homework.description = params[:bid][:description]
  190. # @homework.reward_type = 3
  191. # # @bid.budget = params[:bid][:budget]
  192. # @homework.deadline = params[:bid][:deadline]
  193. # @homework.budget = 0
  194. # @homework.author_id = User.current.id
  195. # @homework.commit = 0
  196. # @homework.homework_type = 1
  197. # @homework.is_evaluation = params[:bid][:is_evaluation]
  198. # @homework.parent_id = @bid.id
  199. # @homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
  200. # # @bid.
  201. # if @homework.save
  202. # HomeworkForCourse.create(:course_id => params[:course], :bid_id => @homework.id)
  203. # unless @bid.watched_by?(User.current)
  204. # if @bid.add_watcher(User.current)
  205. # flash[:notice] = l(:label_bid_succeed)
  206. # end
  207. # end
  208. # redirect_to course_for_bid_path(@homework)
  209. # else
  210. # @bid.safe_attributes = params[:bid]
  211. # @courses = []
  212. # @membership = User.current.coursememberships.all#(:conditions => Project.visible_condition(User.current))
  213. # @membership.each do |membership|
  214. # @courses << membership.course
  215. # end
  216. # render :action => 'fork'
  217. # end
  218. # end
  219. #
  220. # #有两个路由链接到此方法:/bids/:id /calls/:id但是貌似这两个路由都不能访问。。方法作用有待确认
  221. # def show
  222. # @user = @bid.author
  223. # @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
  224. # @limit = 10
  225. # @feedback_count = @jours.count
  226. # @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  227. # @offset ||= @feedback_pages.offset
  228. # @jour = @jours[@offset, @limit]
  229. # @state = false
  230. #
  231. # respond_to do |format|
  232. # layout_file = ''
  233. # case @bid.reward_type
  234. # when 3
  235. # html_title(l(:label_question_student))
  236. # layout_file = 'base_homework'
  237. # when 1
  238. # layout_file = 'base_bids'
  239. # else
  240. # layout_file = 'base_contest'
  241. # end
  242. # format.html {
  243. # render :layout => layout_file
  244. # }
  245. # format.api
  246. # end
  247. # end
  248. #
  249. # def join_in_contest
  250. # if @bid.reward_type == 2 && params[:course_password] == @bid.password
  251. # JoinInContest.create(:user_id => User.current.id, :bid_id => @bid.id)
  252. # @state = 0
  253. # else
  254. # @state = 1
  255. # end
  256. # respond_to do |format|
  257. # format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
  258. # end
  259. # end
  260. #
  261. # def unjoin_in_contest
  262. # joined = JoinInContest.where('bid_id = ? and user_id = ?', @bid.id, User.current.id)
  263. # joined.each do |join|
  264. # join.delete
  265. # end
  266. # respond_to do |format|
  267. # format.js { render :partial => 'set_join', :locals => {:user => User.current, :object_id => params[:id]} }
  268. # end
  269. # end
  270. #
  271. # def new_join
  272. #
  273. # end
  274. #
  275. # # added by bai 增加了参与者和竞赛设置
  276. # def show_participator
  277. # render :layout => 'base_contest'
  278. # end
  279. #
  280. # #配置竞赛
  281. # def settings
  282. # if @bid.author.id == User.current.id
  283. # if @bid.reward_type == 2
  284. # @contest = Bid.find_by_reward_type(@bid.reward_type)
  285. # render :layout => 'base_contest'
  286. # end
  287. # else
  288. # render_403 :message => :notice_not_contest_setting_authorized
  289. # end
  290. # end
  291. # #end
  292. #
  293. # # 显示课程作业,但是好像已经废弃
  294. # def show_course
  295. # bids = Bid.where('parent_id = ?', @bid.id)
  296. # @courses = []
  297. # for bid in bids
  298. # @courses << bid.courses.first
  299. # end
  300. #
  301. # respond_to do |format|
  302. # if @bid.reward_type == 3
  303. # format.html {
  304. # render :layout => 'base_homework'
  305. # }
  306. # elsif @bid.reward_type == 1
  307. # format.html {
  308. # render :layout => 'base_bids'
  309. # }
  310. # else
  311. # format.html {
  312. # render :layout => 'base_contest'
  313. # }
  314. # end
  315. # format.api
  316. #
  317. # end
  318. # end
  319. #
  320. # def show_bid_project
  321. # bids = Bid.where('parent_id = ?', @bid.id)
  322. # @projects = []
  323. # for bid in bids
  324. # @projects += bid.biding_projects
  325. # end
  326. #
  327. # respond_to do |format|
  328. # if @bid.reward_type == 3
  329. # format.html {
  330. # render :layout => 'base_homework'
  331. # }
  332. # elsif @bid.reward_type == 1
  333. # format.html {
  334. # render :layout => 'base_bids'
  335. # }
  336. # else
  337. # format.html {
  338. # render :layout => 'base_contest'
  339. # }
  340. # end
  341. # format.api
  342. #
  343. # end
  344. # end
  345. #
  346. # def show_bid_user
  347. # bids = Bid.where('parent_id = ?', @bid.id)
  348. # @users = []
  349. # for bid in bids
  350. # for project in bid.projects
  351. # @users += project.users
  352. # end
  353. # end
  354. #
  355. # respond_to do |format|
  356. # if @bid.reward_type == 3
  357. # format.html {
  358. # render :layout => 'base_homework'
  359. # }
  360. # elsif @bid.reward_type == 1
  361. # format.html {
  362. # render :layout => 'base_bids'
  363. # }
  364. # else
  365. # format.html {
  366. # render :layout => 'base_contest'
  367. # }
  368. # end
  369. # format.api
  370. #
  371. # end
  372. # end
  373. #
  374. # def show_project
  375. # # flash[:notice] = ""
  376. # @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  377. # @option = []
  378. # @membership.each do |membership|
  379. # unless(membership.project.project_type==1)
  380. # if membership.user.allowed_to?(:quote_project,membership.project)
  381. # @option << membership.project
  382. # end
  383. # end
  384. # end
  385. #
  386. # # a = [1]
  387. # # @project = Project.where("id in []", a)
  388. # @user = @bid.author
  389. # @bidding_project = @bid.biding_projects.all
  390. # if params[:student_id].present?
  391. # @temp = []
  392. # @bidding_project.each do |pro|
  393. # if pro.project && pro.project.project_status
  394. # if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  395. # @temp << pro
  396. # end
  397. # end
  398. # @temp
  399. # end
  400. # @bidding_project = @temp
  401. # else
  402. # #added by nie
  403. # @temp = []
  404. # @bidding_project.each do |pro|
  405. # if pro.project && pro.project.project_status
  406. # @temp << pro
  407. # end
  408. # @temp
  409. # end
  410. # if @temp.size > 0
  411. # @bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
  412. # end
  413. # #ended
  414. # end
  415. #
  416. # if @bid.homework_type == 1
  417. # @homework = HomeworkAttach.new
  418. # #@homework_list = @bid.homeworks
  419. # #增加作业按评分排序,
  420. # @homework_list = @bid.homeworks.eager_load(:rate_averages, :user, :attachments).order('seems_rateable_cached_ratings.avg DESC').order("#{HomeworkAttach.table_name}.created_at ASC")
  421. # if params[:student_id].present?
  422. # @temp = []
  423. # @homework_list.each do |pro|
  424. # if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  425. # @temp << pro
  426. # end
  427. # @temp
  428. # end
  429. # @homework_list = @temp
  430. # end
  431. # end
  432. #
  433. # respond_to do |format|
  434. # if @bid.reward_type == 3
  435. # format.html {
  436. # render :layout => 'base_homework'
  437. # }
  438. # elsif @bid.reward_type == 1
  439. # format.html {
  440. # render :layout => 'base_bids'
  441. # }
  442. # else
  443. # format.html {
  444. # render :layout => 'base_contest'
  445. # }
  446. # end
  447. # format.api
  448. # end
  449. # end
  450. #
  451. # # 显示作业课程
  452. # # add by nwb
  453. # def show_courseEx
  454. #
  455. # if (User.current.logged? && (User.current.member_of_course?(@bid.courses.first) || User.current.admin?))
  456. # @membership = User.current.coursememberships.all(:conditions => Course.visible_condition(User.current))
  457. # @user = @bid.author
  458. # @bidding_project = @bid.biding_projects.all
  459. #
  460. # if params[:student_id].present?
  461. # @temp = []
  462. # @bidding_project.each do |pro|
  463. # if pro.project && pro.project.project_status
  464. # if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  465. # @temp << pro
  466. # end
  467. # end
  468. # @temp
  469. # end
  470. # @bidding_project = @temp
  471. # else
  472. # #added by nie
  473. # @temp = []
  474. # @bidding_project.each do |pro|
  475. # if pro.project && pro.project.project_status
  476. # @temp << pro
  477. # end
  478. # @temp
  479. # end
  480. # if @temp.size > 0
  481. # @bidding_project = @temp.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
  482. # end
  483. # #ended
  484. # end
  485. #
  486. # if @bid.homework_type
  487. # @homework = HomeworkAttach.new
  488. # @is_teacher = is_course_teacher(User.current,@bid.courses.first)
  489. # if @is_teacher
  490. # all_homework_list = HomeworkAttach.find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
  491. # (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score,
  492. # (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score
  493. # FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1
  494. # WHERE table1.t_score IS NULL")
  495. # @not_batch_homework = true
  496. # @cur_type = 1
  497. # else
  498. # all_homework_list = HomeworkAttach.find_by_sql("SELECT homework_attaches.*,
  499. # (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 1 AND stars IS NOT NULL ORDER BY updated_at DESC limit 0,1) AS t_score,
  500. # (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND is_teacher_score = 0) AS s_score,
  501. # (SELECT stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id = #{User.current.id} AND is_teacher_score = #{@is_teacher ? 1 : 0}) AS m_score
  502. # FROM homework_attaches
  503. # INNER JOIN homework_evaluations ON homework_evaluations.homework_attach_id = homework_attaches.id
  504. # WHERE homework_attaches.bid_id = #{@bid.id} AND homework_evaluations.user_id = #{User.current.id} ORDER BY s_score DESC")
  505. # @is_student_batch_homework = true
  506. # @cur_type = 4
  507. # end
  508. #
  509. # @cur_page = params[:page] || 1
  510. # # @homework_list = paginateHelper all_homework_list,10
  511. # @homework_list = all_homework_list
  512. # @jours_count = @bid.journals_for_messages.where('m_parent_id IS NULL').count
  513. # if params[:student_id].present?
  514. # @temp = []
  515. # @homework_list.each do |pro|
  516. # if /#{params[:student_id]}/ =~ pro.user.user_extensions.student_id
  517. # @temp << pro
  518. # end
  519. # @temp
  520. # end
  521. # @homework_list = @temp
  522. # end
  523. # end
  524. #
  525. # respond_to do |format|
  526. # if @bid.reward_type == 3
  527. # format.html {
  528. # html_title(l(:label_homework_info))
  529. # render :layout => 'base_homework'
  530. # }
  531. # elsif @bid.reward_type == 1
  532. # format.html {
  533. # render :layout => 'base_bids'
  534. # }
  535. # else
  536. # format.html {
  537. # render :layout => 'base_contest'
  538. # }
  539. # end
  540. # format.api
  541. # end
  542. # else
  543. # render_403 :message => :notice_not_authorized
  544. # end
  545. # end
  546. #
  547. # ##### by huang
  548. # def show_project_homework
  549. # # flash[:notice] = ""
  550. # @membership = User.current.memberships.all(:conditions => Project.visible_condition(User.current))
  551. # @option = []
  552. # @membership.each do |membership|
  553. # end
  554. # # a = [1]
  555. # # @project = Project.where("id in []", a)
  556. # @user = @bid.author
  557. # @bidding_project = @bid.biding_projects
  558. # respond_to do |format|
  559. # if @bid.reward_type == 3
  560. # format.html {
  561. # render :layout => 'base_homework'
  562. # }
  563. # elsif @bid.reward_type == 1
  564. # format.html {
  565. # render :layout => 'base_bids'
  566. # }
  567. # else
  568. # format.html {
  569. # render :layout => 'base_contest'
  570. # }
  571. # end
  572. # format.api
  573. # end
  574. # end
  575. #
  576. # ###添加应标项目
  577. # def add
  578. # project = Project.find(params[:bid])
  579. # bid_message = params[:bid_for_save][:bid_message]
  580. # if BidingProject.where("project_id = ? and bid_id = ?", project.id, @bid.id).size == 0
  581. # if BidingProject.cerate_bidding(@bid.id, project.id, bid_message)
  582. #
  583. # # added by bai type ==1 需求,type==2 竞赛, type==3 作业
  584. # if @bid.reward_type == 1
  585. # flash.now[:notice] = l(:label_bidding_succeed)
  586. #
  587. # elsif @bid.reward_type == 2
  588. # flash.now[:notice] = l(:label_bidding_contest_succeed)
  589. #
  590. # else @bid.reward_type == 3
  591. # flash.now[:notice] = l(:label_bidding_homework_succeed)
  592. # end
  593. # # end
  594. #
  595. # end
  596. # else
  597. # if @bid.reward_type == 3
  598. # flash.now[:error] = l(:label_bidding_homework_fail)
  599. # else
  600. # flash.now[:error] = l(:label_bidding_fail)
  601. # end
  602. # end
  603. # @bidding_project = @bid.biding_projects
  604. # respond_to do |format|
  605. # # format.html { redirect_to_referer_or {render :text => 'Watcher added.', :layout => true}}
  606. # # format.html
  607. # format.html { redirect_to :back }
  608. # format.js
  609. # #format.api { render_api_ok }
  610. # end
  611. # end
  612. #
  613. # #删除已提交的项目作业(不删项目)
  614. # def delete
  615. # binding_project = params[:binding_project]
  616. # if can_delete_project_homework(BidingProject.find(binding_project),User.current)
  617. # if BidingProject.delete(binding_project)
  618. # redirect_to project_for_bid_url
  619. # else
  620. # render_403;
  621. # end
  622. # end
  623. # end
  624. # ## 新建留言
  625. # def create
  626. #
  627. # if params[:bid_message][:message].size>0
  628. # if params[:reference_content]
  629. # message = params[:bid_message][:message] + "\n" + params[:reference_content]
  630. # else
  631. # message = params[:bid_message][:message]
  632. # @m = message
  633. # end
  634. # refer_user_id = params[:bid_message][:reference_user_id].to_i
  635. # @bid.add_jour(User.current, message, refer_user_id)
  636. # end
  637. # @user = @bid.author
  638. # @jours = @bid.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
  639. # @jour = paginateHelper @jours,10
  640. # @bid.set_commit(@feedback_count)
  641. # respond_to do |format|
  642. # format.js
  643. # #format.api { render_api_ok }
  644. # end
  645. #
  646. # end
  647. #
  648. # ##删除留言
  649. # def destroy
  650. # @user = @bid.author
  651. # if User.current.admin? || User.current.id == @user.id
  652. # JournalsForMessage.delete_message(params[:object_id])
  653. # end
  654. # @jours = @bid.journals_for_messages.reverse
  655. # @limit = 10
  656. # @feedback_count = @jours.count
  657. # @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  658. # @offset ||= @feedback_pages.offset
  659. # @jour = @jours[@offset, @limit]
  660. #
  661. # @bid.set_commit(@feedback_count)
  662. # # if a_message.size > 5
  663. # # @message = a_message[-5, 5]
  664. # # else
  665. # # @message = a_message
  666. # # end
  667. # # @message_count = a_message.count
  668. #
  669. # respond_to do |format|
  670. # # format.html
  671. # format.js
  672. # #format.api { render_api_ok }
  673. # end
  674. # end
  675. #
  676. # #删除作业
  677. # #by xianbo
  678. # def homework_destroy
  679. # @bid_to_destroy = Bid.find params[:id]
  680. # course_url = course_homework_path(@bid_to_destroy.courses.first)
  681. # (render_403; return false) unless User.current.admin?||User.current.id==@bid_to_destroy.author_id
  682. # @bid_to_destroy.destroy
  683. # respond_to do |format|
  684. # format.html { redirect_to course_url }
  685. # format.js
  686. # #format.api { render_api_ok }
  687. # end
  688. # end
  689. #
  690. # #end by xianbo
  691. # ##引用
  692. # def new
  693. # @jour = JournalsForMessage.find(params[:journal_id]) if params[:journal_id]
  694. # if @jour
  695. # user = @jour.user
  696. # text = @jour.notes
  697. # else
  698. # user = @bid.author
  699. # text = @bid.description
  700. # end
  701. # # Replaces pre blocks with [...]
  702. # text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
  703. # @content = "> #{ll(User.current.language, :text_user_wrote, user)}\n> "
  704. # @content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
  705. # @id = user.id
  706. # rescue ActiveRecord::RecordNotFound
  707. # render_404
  708. # end
  709. #
  710. # ##新建需求
  711. # def new_bid
  712. # @bid = Bid.new
  713. # @bid.safe_attributes = params[:bid]
  714. # end
  715. #
  716. # #huang
  717. # def create_contest
  718. # @bid = Bid.new
  719. # @bid.name = params[:bid][:name]
  720. # @bid.description = params[:bid][:description]
  721. # @bid.reward_type = 2
  722. # @bid.budget = params[:bid][:budget]
  723. # @bid.deadline = params[:bid][:deadline]
  724. # @bid.password = params[:bid][:password] #added by bai
  725. # @bid.author_id = User.current.id
  726. # @bid.commit = 0
  727. # if @bid.save
  728. # unless @bid.watched_by?(User.current)
  729. # if @bid.add_watcher(User.current)
  730. # flash[:notice] = l(:label_bid_succeed)
  731. # end
  732. # end
  733. # redirect_to respond_url(@bid)
  734. # else
  735. # @bid.safe_attributes = params[:bid]
  736. # render :action => 'new_bid'
  737. # end
  738. # end
  739. #
  740. # # added by bai
  741. # def update_contest
  742. # @bid = Bid.find(params[:id])
  743. # @bid.name = params[:bid][:name]
  744. # @bid.description = params[:bid][:description]
  745. # @bid.reward_type = 2
  746. # @bid.budget = params[:bid][:budget]
  747. # @bid.deadline = params[:bid][:deadline]
  748. # @bid.password = params[:bid][:password]
  749. # @bid.author_id = User.current.id
  750. # @bid.commit = 0
  751. # if @bid.save
  752. # unless @bid.watched_by?(User.current)
  753. # if @bid.add_watcher(User.current)
  754. # flash[:notice] = l(:label_bid_succeed)
  755. # end
  756. # end
  757. # redirect_to respond_url(@bid)
  758. # else
  759. # @bid.safe_attributes = params[:bid]
  760. # render :action => 'new_bid'
  761. # end
  762. # end
  763. # #huang
  764. # def new_contest
  765. # @bid = Bid.new
  766. # @bid.safe_attributes = params[:bid]
  767. # end
  768. #
  769. # def create_bid
  770. # @bid = Bid.new
  771. # @bid.name = params[:bid][:name]
  772. # @bid.description = params[:bid][:description]
  773. # @bid.reward_type = 1
  774. # @bid.budget = params[:bid][:budget]
  775. # @bid.deadline = params[:bid][:deadline]
  776. # @bid.author_id = User.current.id
  777. # @bid.commit = 0
  778. # if @bid.save
  779. # unless @bid.watched_by?(User.current)
  780. # if @bid.add_watcher(User.current)
  781. # flash[:notice] = l(:label_bid_succeed)
  782. # end
  783. # end
  784. # redirect_to respond_url(@bid)
  785. # else
  786. # @bid.safe_attributes = params[:bid]
  787. # render :action => 'new_bid'
  788. # end
  789. # end
  790. #
  791. # def create_homework
  792. # @bid = Bid.new
  793. # @bid.name = params[:bid][:name]
  794. # @bid.description = params[:bid][:description]
  795. # @bid.is_evaluation = params[:bid][:is_evaluation]
  796. # @bid.proportion = params[:bid][:proportion]
  797. # @bid.evaluation_num = params[:bid][:evaluation_num]
  798. # params[:bid][:open_anonymous_evaluation] ? @bid.open_anonymous_evaluation = 1 : @bid.open_anonymous_evaluation = 0
  799. # @bid.reward_type = 3
  800. # # @bid.budget = params[:bid][:budget]
  801. # @bid.deadline = params[:bid][:deadline]
  802. # @bid.budget = 0
  803. # @bid.author_id = User.current.id
  804. # @bid.commit = 0
  805. # @bid.homework_type = 1
  806. # @bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
  807. # # @bid.
  808. # if @bid.save
  809. # HomeworkForCourse.create(:course_id => params[:course_id], :bid_id => @bid.id)
  810. # unless @bid.watched_by?(User.current)
  811. # if @bid.add_watcher(User.current)
  812. # flash[:notice] = l(:label_bid_succeed)
  813. # end
  814. # end
  815. # redirect_to course_homework_url(params[:course_id])
  816. # else
  817. # @bid.safe_attributes = params[:bid]
  818. # @homework = @bid
  819. # @course = Course.find_by_id(params[:course_id])
  820. # @course_id = @course.id
  821. # #respond_to do |format|
  822. # # format.html { redirect_to new_homework_course_path(params[:course_id]),:layout => 'base_courses'}
  823. # # format.api { render_validation_errors(@bid) }
  824. # #end
  825. # render file: 'courses/new_homework', layout: 'base_courses'
  826. # end
  827. # end
  828. #
  829. # # modify by nwb\
  830. # # 编辑作业
  831. # def edit
  832. # @bid = Bid.find(params[:bid_id])
  833. # if (User.current.admin?||User.current.allowed_to?(:as_teacher,@bid.courses.first))
  834. # @course_id = params[:course_id]
  835. # respond_to do |format|
  836. # format.html {
  837. # @course = Course.find(params[:course_id])
  838. # @user= User.find(User.current.id)
  839. # render :layout => 'base_courses'
  840. # }
  841. # end
  842. # else
  843. # render_403
  844. # end
  845. # end
  846. #
  847. # def update
  848. # @bid = Bid.find(params[:id])
  849. # @course = @bid.courses.first#Project.find(params[:course_id])
  850. # @bid.name = params[:bid][:name]
  851. # @bid.description = params[:bid][:description]
  852. # @bid.is_evaluation = params[:bid][:is_evaluation]
  853. # @bid.proportion = params[:bid][:proportion]
  854. # @bid.evaluation_num = params[:bid][:evaluation_num]
  855. # params[:bid][:open_anonymous_evaluation] ? @bid.open_anonymous_evaluation = 1 : @bid.open_anonymous_evaluation = 0
  856. # @bid.reward_type = 3
  857. # @bid.deadline = params[:bid][:deadline]
  858. # @bid.budget = 0
  859. # #@bid.author_id = User.current.id
  860. # @bid.commit = 0
  861. # @bid.homework_type = 1
  862. # @bid.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
  863. # if @bid.save
  864. # flash[:notice] = l(:label_update_homework_succeed)
  865. # redirect_to course_homework_url(@course)
  866. # else
  867. # @bid.safe_attributes = params[:bid]
  868. # render :action => 'edit', :layout =>'base_courses'
  869. # end
  870. # end
  871. #
  872. # def new_submit_homework
  873. # #render html to prepare create submit homework
  874. # find_bid
  875. # find_bid
  876. # render :layout => 'base_homework'
  877. # end
  878. #
  879. # def add_homework
  880. # 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)
  881. # # homework = HomeworkAttach.create(:bid_id => @bid.id, :user_id => User.current.id)
  882. # # homework.save_attachments(params[:attachments] || (params[:bid] && params[:bid][:uploads]))
  883. #
  884. # if hadcommittedhomework(User.current.id, @bid.id) == true
  885. # @homework_flag = l(:label_bidding_homework_committed)
  886. # else
  887. # @homework = HomeworkAttach.new
  888. # @homework.safe_attributes = params[:homeworkattach]
  889. # @homework.bid_id = @bid.id
  890. # @homework.user_id = User.current.id
  891. # @homework.save_attachments(params[:attachments])
  892. #
  893. # render_attachment_warning_if_needed(@homework)
  894. #
  895. # @homework_flag = if @homework.save
  896. # l(:label_bidding_homework_succeed)
  897. # else
  898. # l(:label_bidding_homework_failed)
  899. # end
  900. #
  901. # if @homework.attachments.empty?
  902. # @homework.delete
  903. # #flash[:error] = l(:no_attachmens_allowed)
  904. # @homework_flag = l(:no_attachmens_allowed)
  905. # # else
  906. # end
  907. # end
  908. # end
  909. #
  910. # @homework_list = @bid.homeworks
  911. # respond_to do |format|
  912. # format.html{
  913. # #redirect_to project_for_bid_path, notice: @homework_flag.to_s
  914. # flash[:notice] = @homework_flag.to_s
  915. # redirect_back_or_default(project_for_bid_path)
  916. # }
  917. # format.js
  918. # end
  919. #
  920. # end
  921. #
  922. # # 作业统计
  923. # def homework_statistics
  924. # @course = @bid.courses.first
  925. # @member = []
  926. # @course.memberships.each do |member|
  927. # unless (member.roles && Role.where('id = ? ', 3)).empty?
  928. # @member.push member
  929. # end
  930. # end
  931. # if @bid.homework_type = 1
  932. # @student = User.where("id in (select DISTINCT user_id from #{HomeworkAttach.table_name} where bid_id = ? )", @bid.id)
  933. # @homework_type = true
  934. # else
  935. #
  936. # @homework_type = false
  937. # end
  938. # @user = @bid.author
  939. # render :layout => 'base_homework'
  940. # end
  941. #
  942. # def homework_respond
  943. # @user = @bid.author
  944. # render :layout => 'base_homework'
  945. # end
  946. #
  947. # def more
  948. # @jour = @bid.journals_for_messages
  949. # @jour.each_with_index {|j,i| j.indice = i+1}
  950. # @state = true
  951. #
  952. # respond_to do |format|
  953. # format.html { redirect_to :back }
  954. # format.js
  955. # #format.api { render_api_ok }
  956. # end
  957. # end
  958. #
  959. # def back
  960. # @jour = @bid.journals_for_messages
  961. # @jour.each_with_index {|j,i| j.indice = i+1}
  962. # @state = false
  963. #
  964. # respond_to do |format|
  965. # format.html { redirect_to :back }
  966. # format.js
  967. # #format.api { render_api_ok }
  968. # end
  969. # end
  970. #
  971. # #added by william
  972. # #used to set the bidding project reward
  973. # def set_reward
  974. # @b_p = nil
  975. # @biding_project_id = nil
  976. #
  977. # if params[:set_reward][:reward]&&((User.current.id==@bid.author_id)||User.current.admin)
  978. # # @bid_id = params[:id]
  979. # @biding_project_id = params[:set_reward][:b_id]
  980. # @b_p = BidingProject.find_by_id(@biding_project_id)
  981. #
  982. # # 把字段存进表中
  983. # @b_p.update_reward(params[:set_reward][:reward].to_s)
  984. # end
  985. #
  986. # respond_to do |format|
  987. # format.js
  988. # end
  989. # end
  990. #
  991. # # added by william
  992. # # used to manage the bid and end the bid
  993. # def manage
  994. #
  995. # end
  996. #
  997. # # 启动匿评
  998. # def start_anonymous_comment
  999. # @bid = Bid.find(params[:id])
  1000. # @course = @bid.courses.first
  1001. # if(@bid.comment_status == 0)
  1002. # homeworks = @bid.homeworks
  1003. # if(homeworks && homeworks.size >= 2)
  1004. # homeworks.each_with_index do |homework, index|
  1005. # user = homework.user
  1006. # n = @bid.evaluation_num
  1007. # n = n < homeworks.size ? n : homeworks.size - 1
  1008. # assigned_homeworks = get_assigned_homeworks(homeworks, n, index)
  1009. # assigned_homeworks.each do |h|
  1010. # @homework_evaluation = HomeworkEvaluation.new(user_id: user.id, homework_attach_id: h.id)
  1011. # @homework_evaluation.save
  1012. # end
  1013. # end
  1014. # @bid.update_column('comment_status', 1)
  1015. # @statue = 1
  1016. # else
  1017. # @statue = 2
  1018. # end
  1019. # else
  1020. # @statue = 3
  1021. # end
  1022. #
  1023. # respond_to do |format|
  1024. # format.js
  1025. # end
  1026. # end
  1027. #
  1028. # def stop_anonymous_comment
  1029. # @bid = Bid.find(params[:id])
  1030. #
  1031. # @bid.update_column('comment_status', 2)
  1032. #
  1033. # respond_to do |format|
  1034. # format.js
  1035. # end
  1036. # end
  1037. #
  1038. # def alert_anonymous_comment
  1039. # @bid = Bid.find params[:id]
  1040. # @course = @bid.courses.first
  1041. # @cur_size = 0
  1042. # @totle_size = 0
  1043. # if @bid.comment_status == 0
  1044. # @totle_size = searchStudent(@course).size
  1045. # @cur_size = @bid.homeworks.size
  1046. # elsif @bid.comment_status == 1
  1047. # @bid.homeworks.map { |homework| @totle_size += homework.homework_evaluations.count}
  1048. # @cur_size = 0
  1049. # @bid.homeworks.map { |homework| @cur_size += homework.rates(:quality).where("seems_rateable_rates.is_teacher_score = 0").count}
  1050. # end
  1051. # @percent = format("%.2f",(@cur_size.to_f / ( @totle_size == 0 ? 1 : @totle_size)) * 100)
  1052. # respond_to do |format|
  1053. # format.js
  1054. # end
  1055. # end
  1056. #
  1057. # private
  1058. #
  1059. # def get_assigned_homeworks(homeworks, n, index)
  1060. # homeworks += homeworks
  1061. # homeworks[index + 1 .. index + n]
  1062. # end
  1063. #
  1064. # def find_bid
  1065. # if params[:id]
  1066. # @bid = Bid.find(params[:id], :include => [{:homeworks => :user}])
  1067. # @user = @bid.author
  1068. # end
  1069. # rescue
  1070. # render_404
  1071. # end
  1072. #
  1073. # def memberAccess
  1074. # # 是课程,则判断当前用户是否参加了课程
  1075. # return true if current_user.admin?
  1076. # #return 0 if @bid.courses.first.project_type == Project::ProjectType_project
  1077. # currentUser = User.current
  1078. # render_403 unless currentUser.member_of_course?(@bid.courses.first)
  1079. # end
  1080. #
  1081. # #验证是否显示课程
  1082. # def can_show_course
  1083. # @first_page = FirstPage.find_by_page_type('project')
  1084. # if @first_page.show_course == 2
  1085. # render_404
  1086. # end
  1087. # end
  1088. #
  1089. # #验证是否显示竞赛
  1090. # def can_show_contest
  1091. # @first_page = FirstPage.find_by_page_type('project')
  1092. # if @first_page.show_contest == 2
  1093. # render_404
  1094. # end
  1095. # end
  1096. # end
  1097. #

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