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.

open_source_project.rb 5.0 kB

12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. class OpenSourceProject < ActiveRecord::Base
  2. attr_accessible :name
  3. include Redmine::SafeAttributes
  4. has_many :applies, :class_name => "ApplyProjectMaster", :as => :apply, :dependent => :delete_all
  5. has_many :relation_topics, :class_name => 'RelativeMemoToOpenSourceProject', :foreign_key => 'osp_id', :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy
  6. # has_many :topics, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :conditions => "#{RelativeMemo.table_name}.parent_id IS NULL", :order => "#{RelativeMemo.table_name}.created_at DESC", :dependent => :destroy
  7. has_many :topics, :through => :relation_topics, :class_name => 'RelativeMemo'
  8. # has_many :relative_memos, :class_name => 'RelativeMemo', :foreign_key => 'osp_id', :dependent => :destroy
  9. has_many :tags, :through => :project_tags, :class_name => 'Tag'
  10. has_many :project_tags, :class_name => 'ProjectTags'
  11. has_many :masters, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 2"
  12. has_many :admin, :through => :masters, :class_name => 'User'
  13. has_many :apply_tips, :class_name => 'ApplyProjectMaster', :as => :apply, :dependent => :delete_all, :conditions => "#{ApplyProjectMaster.table_name}.status = 1"
  14. has_many :applicants, :class_name => 'User', :through => :apply_tips, :source => :user
  15. has_many :bugs_to_osp, :class_name => 'BugToOsp', :foreign_key => 'osp_id', :dependent => :destroy
  16. has_many :bugs, :through => :bugs_to_osp, :class_name => "RelativeMemo", :order => "#{RelativeMemo.table_name}.created_at DESC"
  17. validates_uniqueness_of :name
  18. acts_as_taggable
  19. scope :applied_by, lambda { |user_id|
  20. { :include => :apply_project_master,
  21. :conditions => ["#{ApplyProjectMaster.table_name}.user_id = ?", user_id]
  22. }
  23. }
  24. scope :like, lambda {|arg|
  25. if arg.blank?
  26. where(nil)
  27. else
  28. pattern = "%#{arg.to_s.strip.downcase}%"
  29. where("LOWER(name) LIKE :p OR LOWER(description) LIKE :p ", :p => pattern)
  30. end
  31. }
  32. def filter(app_dir, language, created_at)
  33. filter_app_dir(app_dir).filter_language(language).filter_time(created_at)
  34. end
  35. def self.filter(app_dir, language, created_at)
  36. self.filter_app_dir(app_dir).filter_language(language).filter_time(created_at)
  37. end
  38. scope :filter_app_dir, lambda {|args|
  39. nil
  40. }
  41. scope :filter_language, lambda {|*arg|
  42. if arg[0].nil?
  43. where(nil)
  44. else
  45. tagged_with(arg).order('updated_at desc')
  46. end
  47. }
  48. scope :filter_time, lambda {|args|
  49. where("YEAR(#{OpenSourceProject.table_name}.created_at) = ?", args) unless args.nil?
  50. }
  51. # def filter_app_dir(app_dir)
  52. # nil
  53. # end
  54. #
  55. # def self.filter_app_dir(app_dir)
  56. # nil
  57. # end
  58. #
  59. # def filter_language(language)
  60. # nil
  61. # end
  62. #
  63. # def self.filter_language(language)
  64. # nil
  65. # end
  66. #
  67. # def filter_time(created_at)
  68. # nil
  69. # end
  70. #
  71. # def self.filter_time(created_at)
  72. # nil
  73. # end
  74. def short_description(length = 255)
  75. description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
  76. end
  77. def applied_by?(user)
  78. self.applies.each do |apply|
  79. if apply.user_id == user.id
  80. return true
  81. end
  82. end
  83. false
  84. end
  85. def allowed?(user)
  86. self.applies.each do |apply|
  87. if apply.user_id == user.id and apply.status == 2
  88. return true
  89. end
  90. end
  91. false
  92. end
  93. def set_apply(user, flag=true)
  94. flag ? set_filter(user) : remove_filter(user)
  95. end
  96. def set_filter(user)
  97. self.applies << ApplyProjectMaster.new(:user => user, :status => 1)
  98. end
  99. def remove_filter(user)
  100. return nil unless user && user.is_a?(User)
  101. ApplyProjectMaster.delete_all "apply_type = '#{self.class}' AND apply_id = #{self.id} AND user_id = #{user.id}"
  102. end
  103. def admin?(user)
  104. if user.admin? or ApplyProjectMaster.find(:all, :conditions => ["user_id = ? and apply_type = 'OpenSourceProject' and apply_id = ? and status = ?", user.id, self.id, 2]).present?
  105. return true
  106. else
  107. return false
  108. end
  109. end
  110. def reset_counters!
  111. self.class.reset_counters!(id)
  112. end
  113. def self.reset_counters!(id)
  114. osp_id = id.to_i
  115. # update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NULL)," +
  116. # " memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," +
  117. # " last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})",
  118. # ["id = ?", osp_id])
  119. update_all("topic_count = (SELECT COUNT(*) FROM #{RelativeMemoToOpenSourceProject.table_name} WHERE osp_id=#{osp_id})",
  120. # +
  121. # " memo_count = (SELECT COUNT(*) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id} AND parent_id IS NOT NULL)," +
  122. # " last_memo_id = (SELECT MAX(id) FROM #{RelativeMemo.table_name} WHERE osp_id=#{osp_id})",
  123. ["id = ?", osp_id])
  124. end
  125. end

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