| 10 |
10 |
validates_presence_of :name_on_paper
|
| 11 |
11 |
|
| 12 |
12 |
attr_accessor :search_author_class, :search_author_id, :search_name, :search_results, :identify_author
|
| 13 |
|
before_save :associate_author_user
|
| 14 |
13 |
|
| 15 |
|
acts_as_list
|
|
14 |
before_create :associate_author_user
|
|
15 |
before_update :delete_publication_cache
|
|
16 |
|
|
17 |
# tod: review scope of ordering
|
|
18 |
acts_as_list :column => 'auth_order'
|
| 16 |
19 |
|
| 17 |
20 |
# todo: review usage of scope --lf.20130108
|
| 18 |
21 |
scope :like_unique, lambda {|q|
|
| ... | ... | |
| 44 |
47 |
end
|
| 45 |
48 |
|
| 46 |
49 |
protected
|
|
50 |
|
|
51 |
def delete_publication_cache
|
|
52 |
publication = Publication.find(self.publication_id)
|
|
53 |
Rails.cache.delete "publication-#{publication.id}-ieee"
|
|
54 |
Rails.cache.delete "publication-#{publication.id}-bibtex"
|
|
55 |
end
|
|
56 |
|
| 47 |
57 |
def associate_author_user
|
| 48 |
58 |
case self.search_author_class
|
| 49 |
|
when "User"
|
| 50 |
|
author = Author.new
|
| 51 |
|
author.save
|
| 52 |
|
self.author_id = author.id
|
|
59 |
when ""
|
|
60 |
logger.debug { "Unknown Author to be added..." }
|
|
61 |
when "User"
|
|
62 |
author = Author.new
|
|
63 |
author.save
|
|
64 |
self.author_id = author.id
|
|
65 |
|
|
66 |
when "Author"
|
|
67 |
selected = self.search_results
|
|
68 |
selected_classname = Kernel.const_get(self.search_author_class)
|
|
69 |
selected_id = self.search_author_id
|
|
70 |
object = selected_classname.find(selected_id)
|
|
71 |
|
|
72 |
if object.respond_to? :name_on_paper
|
|
73 |
# Authorship
|
|
74 |
self.author_id = object.author.id
|
| 53 |
75 |
else
|
| 54 |
|
selected = self.search_results
|
| 55 |
|
selected_classname = Kernel.const_get(self.search_author_class)
|
| 56 |
|
selected_id = self.search_author_id
|
| 57 |
|
object = selected_classname.find(selected_id)
|
| 58 |
|
|
| 59 |
|
if object.respond_to? :name_on_paper
|
| 60 |
|
# Authorship
|
|
76 |
# User
|
|
77 |
unless object.author.nil?
|
| 61 |
78 |
self.author_id = object.author.id
|
| 62 |
79 |
else
|
| 63 |
|
# User
|
| 64 |
|
unless object.author.nil?
|
| 65 |
|
self.author_id = object.author.id
|
| 66 |
|
else
|
| 67 |
|
author = Author.new
|
| 68 |
|
object.author = author
|
| 69 |
|
object.save
|
| 70 |
|
self.author_id = object.author.id
|
| 71 |
|
end
|
|
80 |
author = Author.new
|
|
81 |
object.author = author
|
|
82 |
object.save
|
|
83 |
self.author_id = object.author.id
|
| 72 |
84 |
end
|
|
85 |
end
|
| 73 |
86 |
end
|
| 74 |
87 |
end
|
| 75 |
88 |
end
|