Mercurial > hg > soundsoftware-site
diff plugins/redmine_bibliography/app/models/author.rb @ 1484:51364c0cd58f redmine-2.4-integration
Merge from live branch. Still need to merge manually in files overridden by plugins.
author | Chris Cannam |
---|---|
date | Wed, 15 Jan 2014 09:59:14 +0000 |
parents | b688fe79f593 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/redmine_bibliography/app/models/author.rb Wed Jan 15 09:59:14 2014 +0000 @@ -0,0 +1,46 @@ +class Author < ActiveRecord::Base + unloadable + + has_many :authorships, :dependent => :destroy + has_many :publications, :through => :authorships + + belongs_to :user + + def <=>(author) + name.downcase <=> author.name.downcase + end + + # todo: review usage of scope --lf.20130108 + scope :like, lambda {|q| + s = "%#{q.to_s.strip.downcase}%" + {:conditions => ["LOWER(name) LIKE :s", {:s => s}], + :order => 'name' + } + } + + def institution + if self.authorships.first.nil? + "" + else + self.authorships.first.institution + end + end + + def mail + if self.authorships.first.nil? + "" + else + self.authorships.first.mail + end + end + + # todo: need to fix the name getter + def name + if self.authorships.first.nil? + "" + else + self.authorships.first.name + end + end + +end