Mercurial > hg > soundsoftware-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
1464:261b3d9a4903 | 1484:51364c0cd58f |
---|---|
1 class Author < ActiveRecord::Base | |
2 unloadable | |
3 | |
4 has_many :authorships, :dependent => :destroy | |
5 has_many :publications, :through => :authorships | |
6 | |
7 belongs_to :user | |
8 | |
9 def <=>(author) | |
10 name.downcase <=> author.name.downcase | |
11 end | |
12 | |
13 # todo: review usage of scope --lf.20130108 | |
14 scope :like, lambda {|q| | |
15 s = "%#{q.to_s.strip.downcase}%" | |
16 {:conditions => ["LOWER(name) LIKE :s", {:s => s}], | |
17 :order => 'name' | |
18 } | |
19 } | |
20 | |
21 def institution | |
22 if self.authorships.first.nil? | |
23 "" | |
24 else | |
25 self.authorships.first.institution | |
26 end | |
27 end | |
28 | |
29 def mail | |
30 if self.authorships.first.nil? | |
31 "" | |
32 else | |
33 self.authorships.first.mail | |
34 end | |
35 end | |
36 | |
37 # todo: need to fix the name getter | |
38 def name | |
39 if self.authorships.first.nil? | |
40 "" | |
41 else | |
42 self.authorships.first.name | |
43 end | |
44 end | |
45 | |
46 end |