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.

homework_attach_controller.rb 11 kB

12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. class HomeworkAttachController < ApplicationController
  2. ###############################
  3. #判断当前角色权限时需先找到当前操作的project
  4. before_filter :find_course_by_bid_id, :only => [:new]
  5. before_filter :find_course_by_hoemwork_id, :only => [:edit,:update,:destroy,:show,:add_homework_users,:destory_homework_users]
  6. #判断当前角色是否有操作权限
  7. #勿删 before_filter :authorize, :only => [:new,:edit,:update,:destroy]
  8. def find_course_by_bid_id
  9. @bid = Bid.find(params[:id])
  10. @course = @bid.courses[0]
  11. rescue ActiveRecord::RecordNotFound
  12. render_404
  13. end
  14. def find_course_by_hoemwork_id
  15. @homework = HomeworkAttach.find(params[:id])
  16. @course = @homework.bid.courses[0]
  17. end
  18. #获取作业的成员
  19. def get_homework_member homework
  20. @hoemwork_users = users_for_homework(@homework)
  21. @members = members_for_homework(@homework,@hoemwork_users,params[:q])
  22. @members = paginateHelper @members,10
  23. end
  24. def index
  25. @homeworks = HomeworkAttach.all
  26. respond_to do |format|
  27. format.html # index.html.erb
  28. format.json { render json: @homeworks }
  29. end
  30. end
  31. #作业添加成员(参与人员)
  32. def add_homework_users
  33. if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
  34. #@homework = HomeworkAttach.find(params[:id])
  35. if params[:membership]
  36. if params[:membership][:user_ids]
  37. attrs = params[:membership].dup
  38. user_ids = attrs.delete(:user_ids)
  39. user_ids.each do |user_id|
  40. @homework.homework_users.build(:user_id => user_id)
  41. end
  42. end
  43. end
  44. @homework.save
  45. get_homework_member @homework
  46. respond_to do |format|
  47. format.js
  48. end
  49. else
  50. render_403 :message => :notice_not_authorized
  51. end
  52. end
  53. #作业删除成员(参与人员)
  54. def destory_homework_users
  55. #@homework = HomeworkAttach.find(params[:id])
  56. if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
  57. homework_user = @homework.homework_users.where("user_id = #{params[:user_id]}").first
  58. homework_user.destroy
  59. get_homework_member @homework
  60. respond_to do |format|
  61. format.js
  62. end
  63. else
  64. render_403 :message => :notice_not_authorized
  65. end
  66. end
  67. def create
  68. bid = Bid.find params[:bid_id]
  69. if User.current.admin? || User.current.member_of_course?(bid.courses.first) # modify by nwb
  70. if bid.homeworks.where("user_id = ?",User.current).count == 0
  71. user_id = params[:user_id]
  72. bid_id = params[:bid_id]
  73. sta = 0
  74. name = params[:new_form][:name]
  75. description = params[:new_form][:description]
  76. options = {
  77. :user_id => user_id,
  78. :state => sta,
  79. :name => name,
  80. :description => description,
  81. :bid_id => bid_id
  82. }
  83. #@homework_list = @bid.homeworks
  84. @homework = HomeworkAttach.new(options)
  85. @homework.save_attachments(params[:attachments])
  86. render_attachment_warning_if_needed(@homework)
  87. if @homework.save
  88. respond_to do |format|
  89. format.html { redirect_to course_for_bid_path @homework.bid }
  90. format.json { head :no_content }
  91. end
  92. else
  93. render_403 :message => :notice_not_authorized
  94. end
  95. else
  96. render_403 :message => :notice_has_homework
  97. end
  98. else
  99. render_403 :message => :notice_not_authorized
  100. end
  101. end
  102. def new
  103. @bid = Bid.find(params[:id])
  104. if User.current.admin? || User.current.member_of_course?(@bid.courses.first) #nwb
  105. #该课程的学生的集合(新建不实现功能:添加成员)
  106. #@members = @bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id <> #{User.current.id}", {:role_id => [5, 10]})
  107. #@members = paginateHelper @members,10
  108. #@all_user = []
  109. #@bid.courses.first.members.each do |member|
  110. # @all_user << member.user
  111. #end
  112. @homework = HomeworkAttach.new
  113. #@homework_user = members_for_homework(@homework) + User.current
  114. #@members = @all_user - @homework_user
  115. respond_to do |format|
  116. format.html # new.html.erb
  117. format.json { render json: @homework }
  118. end
  119. else
  120. render_403 :message => :notice_not_authorized
  121. end
  122. end
  123. #获取作业成员的集合
  124. def get_homework_member_list
  125. @homework = HomeworkAttach.find(params[:bid_id])
  126. course = @homework.bid.courses.first
  127. if User.current.admin? || User.current.member_of_course?(course)
  128. get_homework_member @homework
  129. else
  130. raise "error"
  131. end
  132. respond_to do |format|
  133. format.js
  134. end
  135. end
  136. #获取指定作业的所有成员
  137. def users_for_homework homework
  138. homework.nil? ? [] : (homework.users + [homework.user])
  139. end
  140. #获取可选成员列表
  141. #homework:作业
  142. #users:该作业所有成员
  143. #q:模糊匹配的用户的昵称
  144. def members_for_homework homework,users,q
  145. homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id) and user_id not in (:users)", {:role_id => [5, 10],:users => users}).joins(:user).where("users.login like '%#{q}%'")
  146. end
  147. def edit
  148. #@homework = HomeworkAttach.find(params[:id])
  149. if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
  150. #@members = @homework.bid.courses.first.members.joins(:member_roles).where("member_roles.role_id IN (:role_id)", {:role_id => [5, 10]})
  151. get_homework_member @homework
  152. else
  153. render_403 :message => :notice_not_authorized
  154. end
  155. end
  156. def update
  157. #@homework = HomeworkAttach.find(params[:id])
  158. course = @homework.bid.courses.first
  159. if User.current.admin? || User.current.member_of_course?(course)
  160. name = params[:homework_name]
  161. description = params[:homework_description]
  162. @homework.name = name
  163. @homework.description = description
  164. if params[:attachments]
  165. @homework.save_attachments(params[:attachments])
  166. end
  167. if @homework.save
  168. respond_to do |format|
  169. format.html { redirect_to course_for_bid_path @homework.bid }
  170. format.json { head :no_content }
  171. end
  172. else
  173. end
  174. else
  175. render_403 :message => :notice_not_authorized
  176. end
  177. end
  178. def destroy
  179. #@homework = HomeworkAttach.find(params[:id])
  180. if User.current.admin? || User.current == @homework.user
  181. if @homework.destroy
  182. respond_to do |format|
  183. format.html { redirect_to course_for_bid_path @homework.bid }
  184. format.json { head :no_content }
  185. end
  186. else
  187. end
  188. else
  189. render_403 :message => :notice_not_authorized
  190. end
  191. end
  192. #显示作业信息
  193. def show
  194. #@homework = HomeworkAttach.find(params[:id])
  195. if User.current.admin? || User.current.member_of_course?(@homework.bid.courses.first)
  196. # 打分统计
  197. stars_reates = @homework.
  198. rates(:quality)
  199. stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
  200. stars_status = stars_reates.select("stars, count(*) as scount").
  201. group("stars")
  202. @stars_status_map = Hash.new(0.0)
  203. stars_status.each do |star_status|
  204. percent = (star_status.scount * 1.0/ stars_reates_count) * 100.to_f
  205. percent_m = format("%.2f", percent)
  206. @stars_status_map["star#{star_status.stars.to_i}".to_sym] =
  207. percent_m.to_s + "%"
  208. end
  209. #是否已经进行过评价
  210. @has_evaluation = stars_reates.where("rater_id = ?",User.current).count > 0
  211. #是否开启互评功能
  212. @is_evaluation = @homework.bid.is_evaluation == 1 || @homework.bid.is_evaluation == nil
  213. @limit = 10
  214. @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
  215. @feedback_count = @jours.count
  216. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  217. @offset ||= @feedback_pages.offset
  218. @jour = @jours[@offset, @limit]
  219. @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
  220. else
  221. render_403 :message => :notice_not_authorized
  222. end
  223. end
  224. #删除留言
  225. def destroy_jour
  226. @journal_destroyed = JournalsForMessage.delete_message(params[:object_id])
  227. #@homework = HomeworkAttach.find(params[:id])
  228. #@jours = @homework.journals_for_messages.order("created_on DESC")
  229. #@limit = 10
  230. #@feedback_count = @jours.count
  231. #@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  232. #@offset ||= @feedback_pages.offset
  233. #@jour = @jours[@offset, @limit]
  234. respond_to do |format|
  235. format.js
  236. end
  237. end
  238. #添加留言
  239. def addjours
  240. @homework = HomeworkAttach.find(params[:jour_id])
  241. @add_jour = @homework.addjours User.current.id, params[:new_form][:user_message],0,params[:is_comprehensive_evaluation]
  242. @jours = @homework.journals_for_messages.where("is_comprehensive_evaluation is null").order("created_on DESC")
  243. @limit = 10
  244. @feedback_count = @jours.count
  245. @feedback_pages = Paginator.new @feedback_count, @limit, params['page']
  246. @offset ||= @feedback_pages.offset
  247. @jour = @jours[@offset, @limit]
  248. @comprehensive_evaluation = @homework.journals_for_messages.where("is_comprehensive_evaluation is not null").order("created_on DESC")
  249. respond_to do |format|
  250. format.js
  251. end
  252. end
  253. #获取指定作业的平均得分
  254. def score
  255. #stars_reates = @homework.rates(:quality)
  256. #percent = 0
  257. #stars_reates.each do |star_reates|
  258. # percent = percent + star_reates.stars
  259. #end
  260. #stars_reates_count = stars_reates.count == 0 ? 1 : stars_reates.count
  261. #result = percent * 1.0 / stars_reates_count
  262. #result
  263. end
  264. #添加回复
  265. def add_jour_reply
  266. parent_id = params[:reference_id]
  267. author_id = User.current.id
  268. reply_user_id = params[:reference_user_id]
  269. reply_id = params[:reference_message_id] # 暂时不实现
  270. content = params[:user_notes]
  271. options = {:user_id => author_id,
  272. :m_parent_id => parent_id,
  273. :m_reply_id => reply_id,
  274. :reply_id => reply_user_id,
  275. :notes => content,
  276. :is_readed => false}
  277. @jfm = JournalsForMessage.new(options)
  278. @jfm.save
  279. respond_to do |format|
  280. format.js{
  281. @save_succ = true if @jfm.errors.empty?
  282. }
  283. end
  284. end
  285. end

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