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.

test_controller.rb 7.4 kB

​
13 years ago
​
13 years ago
12 years ago
​
​
​
​
12 years ago
​
​
​
​
​
​
12 years ago
​
12 years ago
13 years ago
12 years ago
​
12 years ago
​
12 years ago
​
​
​
12 years ago
​
​
12 years ago
12 years ago
12 years ago
​
12 years ago
12 years ago
12 years ago
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. require 'net/http'
  2. class TestController < ApplicationController
  3. helper :UserScore
  4. layout 'bootstrap_base'
  5. def bootstrap; end
  6. def view_office
  7. end
  8. def zip
  9. homeworks_attach_path = []
  10. homework_id = params[:homework_id]
  11. bid = Bid.find_by_id(homework_id)
  12. bid.homeworks.each do |homeattach|
  13. homeattach.attachments.each do |attach|
  14. length = attach.storage_path.length
  15. homeworks_attach_path << attach.diskfile.to_s.slice((length+1)..-1)
  16. end
  17. end
  18. @paths = homeworks_attach_path
  19. zipfile = ziping homeworks_attach_path
  20. send_file zipfile, :filename => filename_for_content_disposition(bid.name),
  21. :type => detect_content_type(zipfile)
  22. rescue Errno::ENOENT => e
  23. logger.error "[Errno::ENOENT] ===> #{e}"
  24. end
  25. def courselist
  26. @courses = paginateHelper Course.includes(:homeworks).all, 10
  27. end
  28. def ziping files_path
  29. ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
  30. folder = "#{Rails.root}/files"
  31. input_filename = files_path
  32. zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip"
  33. Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
  34. Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
  35. input_filename.each do |filename|
  36. zipfile.add(ic.iconv(filename_to_real(File.basename(filename))), folder + '/' + filename)
  37. end
  38. zipfile.get_output_stream("ReadMe"){ |os|
  39. os.write "Homeworks"
  40. }
  41. end
  42. zipfile_name
  43. end
  44. def detect_content_type(name)
  45. content_type = Redmine::MimeType.of(name)
  46. content_type.to_s
  47. end
  48. def filename_to_real name
  49. attach = Attachment.find_by_disk_filename(name)
  50. attach.filename
  51. end
  52. def mailer()
  53. raise unless Rails.env.development?
  54. @user = User.find(params[:user_id])
  55. send_for_user_activities(@user, Time.now,1)
  56. render 'mailer/send_for_user_activities'
  57. end
  58. def send_for_user_activities(user, date_to, days)
  59. date_from = date_to - days.days
  60. subject = "[ #{user.show_name}#{l(:label_day_mail)}]"
  61. @subject = " #{user.show_name}#{l(:label_day_mail)}"
  62. date_from = "#{date_from} 17:59:59"
  63. date_to = "#{date_to} 17:59:59"
  64. # 生成token用于直接点击登录
  65. @user = user
  66. token = Token.new(:user =>user , :action => 'autologin')
  67. token.save
  68. @token = token
  69. # 查询user参加的项目及课程
  70. projects = user.projects
  71. courses = user.courses
  72. project_ids = projects.map{|project| project.id}.join(",")
  73. course_ids = courses.map {|course| course.id}.join(",")
  74. # 查询user的缺陷,包括发布的,跟踪的以及被指派的缺陷
  75. sql = "select DISTINCT i.* from issues i, watchers w
  76. where (i.assigned_to_id = #{user.id} or i.author_id = #{user.id}
  77. or (w.watchable_type = 'Issue' and w.watchable_id = i.id and w.user_id = #{user.id}))
  78. and (i.created_on between '#{date_from}' and '#{date_to}') order by i.created_on desc"
  79. @issues = Issue.find_by_sql(sql)
  80. # @bids 查询课程作业,包括老师发布的作业,以及user提交作业
  81. # @attachments查询课程课件更新
  82. @attachments ||= []
  83. @bids ||= [] # 老师发布的作业
  84. unless courses.first.nil?
  85. count = courses.count
  86. count = count - 1
  87. for i in 0..count do
  88. bids = courses[i].homeworks.where("bids.created_on between '#{date_from}' and '#{date_to}'").order("bids.created_on desc")
  89. attachments = courses[i].attachments.where("attachments.created_on between '#{date_from}' and '#{date_to}'").order('attachments.created_on DESC')
  90. @bids += bids if bids.count > 0
  91. @attachments += attachments if attachments.count > 0
  92. end
  93. end
  94. # user 提交的作业
  95. @homeworks = HomeworkAttach.where("user_id=#{user.id} and (created_at between '#{date_from}' and '#{date_to}')").order("created_at desc")
  96. # 查询user在课程。项目中发布的讨论帖子
  97. messages = Message.find_by_sql("select DISTINCT * from messages where author_id = #{user.id} and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
  98. @course_messages ||= []
  99. @project_messages ||= []
  100. unless messages.first.nil?
  101. messages.each do |msg|
  102. if msg.project
  103. @project_messages << msg
  104. elsif msg.course
  105. @course_messages << msg
  106. end
  107. end
  108. end
  109. # 查询user在课程中发布的通知,项目中发的新闻
  110. @course_news = (course_ids && !course_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n
  111. where n.course_id in (#{course_ids})
  112. and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : []
  113. @project_news = (project_ids && !project_ids.empty?) ? News.find_by_sql("select DISTINCT n.* from news n where n.project_id in (#{project_ids})
  114. and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc") : []
  115. # 查询user在课程及个人中留言
  116. @course_journal_messages = JournalsForMessage.find_by_sql("select DISTINCT * from journals_for_messages where
  117. jour_type='Course' and user_id = #{user.id}
  118. and (created_on between '#{date_from}' and '#{date_to}') order by created_on desc")
  119. @user_journal_messages = user.journals_for_messages.where("m_parent_id IS NULL and (created_on between '#{date_from}' and '#{date_to}')").order('created_on DESC')
  120. # 查询user新建贴吧或发布帖子
  121. @forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc")
  122. @memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id}))
  123. and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc")
  124. has_content = [@issues,@homeworks,@course_messages,@project_messages,@course_news,@project_news,
  125. @course_journal_messages,@user_journal_messages,@forums,@memos,@attachments,@bids].any? {|o|
  126. !o.empty?
  127. }
  128. #有内容才发,没有不发
  129. end
  130. end

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