gitlab
sw 10 years ago
parent 418f75fd1f
commit 21a9a67bfc

@ -10,158 +10,158 @@ homework_type == 1 文件提交
homework_type == 2 Project homework_type == 2 Project
=end =end
class Bid < ActiveRecord::Base class Bid < ActiveRecord::Base
Enterprise = 1 # Enterprise = 1
Contest = 2 # Contest = 2
Homework = 3 # Homework = 3
HomeworkFile = 1 # HomeworkFile = 1
HomeworkProject = 2 # HomeworkProject = 2
attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password # attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password
include Redmine::SafeAttributes # include Redmine::SafeAttributes
include ApplicationHelper # include ApplicationHelper
has_many_kindeditor_assets :assets, :dependent => :destroy # has_many_kindeditor_assets :assets, :dependent => :destroy
belongs_to :author, :class_name => 'User', :foreign_key => :author_id # belongs_to :author, :class_name => 'User', :foreign_key => :author_id
belongs_to :course # belongs_to :course
has_many :biding_projects, :dependent => :destroy # has_many :biding_projects, :dependent => :destroy
has_many :projects, :through => :biding_projects # has_many :projects, :through => :biding_projects
has_many :courses_member, :class_name => 'User', :through => :courses # has_many :courses_member, :class_name => 'User', :through => :courses
has_many :journals_for_messages, :as => :jour, :dependent => :destroy # has_many :journals_for_messages, :as => :jour, :dependent => :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy # has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :homework_for_courses, :dependent => :destroy # has_many :homework_for_courses, :dependent => :destroy
has_many :courses, :through => :homework_for_courses, :source => :course # has_many :courses, :through => :homework_for_courses, :source => :course
has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy # has_many :homeworks, :class_name => 'HomeworkAttach', :dependent => :destroy
has_many :homework_evaluations, :through => :homeworks # has_many :homework_evaluations, :through => :homeworks
has_many :join_in_contests, :dependent => :destroy # has_many :join_in_contests, :dependent => :destroy
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy # has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
# has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}" # # has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}"
acts_as_attachable # acts_as_attachable
#
NAME_LENGTH_LIMIT = 60 # NAME_LENGTH_LIMIT = 60
DESCRIPTION_LENGTH_LIMIT = 3000 # DESCRIPTION_LENGTH_LIMIT = 3000
validates :name, length: {maximum: NAME_LENGTH_LIMIT}, presence: true # validates :name, length: {maximum: NAME_LENGTH_LIMIT}, presence: true
validates :description, length: {maximum: DESCRIPTION_LENGTH_LIMIT} # validates :description, length: {maximum: DESCRIPTION_LENGTH_LIMIT}
validates :author_id, presence: true # validates :author_id, presence: true
validates :deadline, presence: true, format: {:with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/} # validates :deadline, presence: true, format: {:with => /^[\d]{4}[-][\d]{1,2}[-][\d]{1,2}$/}
validates :name, length: {maximum: NAME_LENGTH_LIMIT} # validates :name, length: {maximum: NAME_LENGTH_LIMIT}
validates :budget, format: { with: ->(p) { if p.reward_type == 1 then /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/ # validates :budget, format: { with: ->(p) { if p.reward_type == 1 then /^(\d+)$|^(\d+).([0-9]{2})|^(\d+).([0-9]{1})$/
elsif p.reward_type == 3 then /^(\d+)$|^(\d+).([0-9]{1})$/ end } } # elsif p.reward_type == 3 then /^(\d+)$|^(\d+).([0-9]{1})$/ end } }
#
validate :validate_user # validate :validate_user
validate :validate_reward_type # validate :validate_reward_type
after_create :act_as_activity # after_create :act_as_activity
after_destroy :delete_kindeditor_assets # after_destroy :delete_kindeditor_assets
scope :visible, lambda {|*args| # scope :visible, lambda {|*args|
nil # nil
} # }
#
scope :like, lambda {|arg| # scope :like, lambda {|arg|
if arg.blank? # if arg.blank?
where(nil) # where(nil)
else # else
pattern = "%#{arg.to_s.strip.downcase}%" # pattern = "%#{arg.to_s.strip.downcase}%"
where("LOWER(id) LIKE :p OR LOWER(name) LIKE :p OR LOWER(description) LIKE :p", :p => pattern) # where("LOWER(id) LIKE :p OR LOWER(name) LIKE :p OR LOWER(description) LIKE :p", :p => pattern)
end # end
} # }
#
scope :course_visible, lambda {|*args| # scope :course_visible, lambda {|*args|
includes(:courses).where(Course.allowed_to_condition(args.shift || User.current, :view_homeworks, *args)) # includes(:courses).where(Course.allowed_to_condition(args.shift || User.current, :view_homeworks, *args))
} # }
#
acts_as_watchable # acts_as_watchable
acts_as_taggable # acts_as_taggable
#
acts_as_event :title => Proc.new {|o| "#{l(:label_course_homework)} ##{o.id}: #{o.name}" }, # acts_as_event :title => Proc.new {|o| "#{l(:label_course_homework)} ##{o.id}: #{o.name}" },
:description => :description, # :description => :description,
:author => :author, # :author => :author,
:url => Proc.new {|o| {:controller => 'bids', :action => 'show', :id => o.id}} # :url => Proc.new {|o| {:controller => 'bids', :action => 'show', :id => o.id}}
#
acts_as_activity_provider :type => 'homeworks', # acts_as_activity_provider :type => 'homeworks',
:author_key => :author_id # :author_key => :author_id
#
acts_as_activity_provider :find_options => {:include => [:projects, :author]}, # acts_as_activity_provider :find_options => {:include => [:projects, :author]},
:author_key => :author_id # :author_key => :author_id
#
safe_attributes 'name',
'description',
'budget',
'deadline',
'homework_type',
'reward_type',
'password'
# safe_attributes 'name', # safe_attributes 'name',
# 'description', # 'description',
# 'deadline' # 'budget',
def add_jour(user, notes, reference_user_id = 0, options = {}) # 'deadline',
if options.count == 0 # 'homework_type',
jfm = JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id) # 'reward_type',
self.journals_for_messages << jfm # 'password'
jfm #
else #
jfm = self.journals_for_messages.build(options) # # safe_attributes 'name',
jfm.save # # 'description',
jfm # # 'deadline'
end # def add_jour(user, notes, reference_user_id = 0, options = {})
end # if options.count == 0
# jfm = JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id)
def self.creat_bids(budget, deadline, name, description=nil, reward_type) # self.journals_for_messages << jfm
self.create(:author_id => User.current.id, :budget => budget, # jfm
:deadline => deadline, :name => name, :description => description, :commit => 0, :reward_type => reward_type) # else
# jfm = self.journals_for_messages.build(options)
# jfm.save
# jfm
# end
# end
#
# def self.creat_bids(budget, deadline, name, description=nil, reward_type)
# self.create(:author_id => User.current.id, :budget => budget,
# :deadline => deadline, :name => name, :description => description, :commit => 0, :reward_type => reward_type)
# # self.acts << Activity.new(:user_id => self.author_id)
# end
#
# def update_bids(budget, deadline, name, description=nil)
# if(User.current.id == self.author_id)
# self.name = name
# self.budget = budget
# self.deadline = deadline
# self.description = description
# self.save
# end
# end
#
# def delete_bids
# unless self.nil?
# if User.current.id == self.author_id
# self.destroy
# end
# end
# end
#
# def set_commit(commit)
# self.update_attribute(:commit, commit)
# end
#
# private
#
# def validate_user
# errors.add :author_id, :invalid if author.nil? || !author.active?
# end
#
# def validate_reward_type
# errors.add :reward_type, :invalid if self.reward_type == 0
# end
#
# def act_as_activity
# self.acts << Activity.new(:user_id => self.author_id) # self.acts << Activity.new(:user_id => self.author_id)
end # end
#
def update_bids(budget, deadline, name, description=nil) # # used to validate weather the user is the creater of the bid
if(User.current.id == self.author_id) # # added by william
self.name = name # def validate_bid_manager(user_id)
self.budget = budget # unless user_id.nil?
self.deadline = deadline # if self.author_id == user_id
self.description = description # return true
self.save # else
end # return false
end # end
# end
def delete_bids # end
unless self.nil? #
if User.current.id == self.author_id # # Time 2015-04-01 14:19:06
self.destroy # # Author lizanle
end # # Description 删除对应课程通知的图片资源
end # def delete_kindeditor_assets
end # delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::BID
# end
def set_commit(commit)
self.update_attribute(:commit, commit)
end
private
def validate_user
errors.add :author_id, :invalid if author.nil? || !author.active?
end
def validate_reward_type
errors.add :reward_type, :invalid if self.reward_type == 0
end
def act_as_activity
self.acts << Activity.new(:user_id => self.author_id)
end
# used to validate weather the user is the creater of the bid
# added by william
def validate_bid_manager(user_id)
unless user_id.nil?
if self.author_id == user_id
return true
else
return false
end
end
end
# Time 2015-04-01 14:19:06
# Author lizanle
# Description 删除对应课程通知的图片资源
def delete_kindeditor_assets
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::BID
end
end end

@ -1,32 +0,0 @@
<!--<div class="inf_user_image">-->
<!--<% for user in @bid.watcher_users %>-->
<!--<ul class="list_watch"><li>-->
<!--<table width="660px" border="0" align="center">-->
<!--<tr>-->
<!--<td colspan="2" valign="top" width="50" ><%= image_tag(url_to_avatar(user), :class => "avatar") %></td>-->
<!--<td><table width="580px" border="0">-->
<!--<tr>-->
<!--<td colspan="2" valign="top"><strong>-->
<%#= content_tag "div", link_to_user(user), :class => "project_avatar_name" %>
<!--</td>-->
<!--</tr>-->
<!--<tr>-->
<!--<td colspan="2" width="580px" ><p class="font_description">-->
<!--<% unless user.memberships.empty? %>-->
<!--<%= l(:label_x_contribute_to, :count => user.memberships.count) %>-->
<!--<% for member in user.memberships %>-->
<!--<%= link_to_project(member.project) %><%= (user.memberships.last == member) ? '' : '' %>-->
<!--<% end %>-->
<!--<% end %>-->
<!--</p></td>-->
<!--</tr>-->
<!--<tr> -->
<!--<td width="200" align="right" class="font_lighter">-->
<%#= l(:label_user_joinin) %><%#= format_date(user.created_on) %>
<!--</td>-->
<!--</tr>-->
<!--</table></td>-->
<!--</tr>-->
<!--</table></li></ul>-->
<!--<% end %>-->
<!--</div>-->
Loading…
Cancel
Save