2013-08-04 10:59:25 +08:00
|
|
|
## fq
|
2013-08-01 10:33:49 +08:00
|
|
|
class BidingProject < ActiveRecord::Base
|
2013-09-23 20:12:32 +08:00
|
|
|
attr_accessible :bid_id, :project_id, :user_id, :description,:reward
|
2013-08-01 10:33:49 +08:00
|
|
|
|
|
|
|
belongs_to :bid
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
DESCRIPTION_LENGTH_LIMIT = 500
|
|
|
|
|
|
|
|
validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT
|
|
|
|
validates_presence_of :user_id, :bid_id, :project_id
|
|
|
|
validate :validate_user
|
|
|
|
validate :validate_bid
|
|
|
|
validate :validate_project
|
|
|
|
validates_uniqueness_of :bid_id, :scope => :project_id
|
|
|
|
|
|
|
|
def self.cerate_bidding(bid_id, project_id, description = nil)
|
|
|
|
self.create(:user_id => User.current.id, :bid_id => bid_id,
|
|
|
|
:project_id => project_id, :description => description)
|
|
|
|
end
|
|
|
|
|
2013-09-23 20:12:32 +08:00
|
|
|
# used to update the reward ,the value varies from 0,1,2,3,4,5
|
|
|
|
# added by william
|
|
|
|
def update_reward(which)
|
|
|
|
self.update_attribute(:reward,which)
|
|
|
|
end
|
|
|
|
|
|
|
|
# return the reward,the value is a type of string
|
|
|
|
# added by william
|
|
|
|
def get_reward
|
|
|
|
self.reward
|
|
|
|
end
|
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
def cancel_bidding
|
|
|
|
unless self.nil?
|
|
|
|
if User.current.id == self.user_id
|
|
|
|
self.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_user
|
|
|
|
errors.add :user_id, :invalid if user.nil? || !user.active?
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_bid
|
|
|
|
errors.add :bid_id, :invalid if bid.nil?
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_project
|
|
|
|
errors.add :project_id, :invalid if project.nil?
|
|
|
|
end
|
2013-09-23 20:12:32 +08:00
|
|
|
|
2013-08-01 10:33:49 +08:00
|
|
|
end
|
2013-09-23 20:12:32 +08:00
|
|
|
|
|
|
|
|