Revision 1395:0e4c6c2f400e plugins/redmine_bibliography/app
| plugins/redmine_bibliography/app/models/authorship.rb | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
validates_presence_of :name_on_paper |
| 11 | 11 |
|
| 12 |
attr_writer :search_author_id, :search_author_class |
|
| 12 |
attr_writer :search_author_id , :search_author_class
|
|
| 13 | 13 |
attr_writer :search_author_tie |
| 14 | 14 |
|
| 15 | 15 |
### attr_accessor :search_results, :identify_author |
| 16 | 16 |
## attr_writer :search_author_class |
| 17 | 17 |
|
| 18 |
before_create :set_author
|
|
| 18 |
before_save :set_author
|
|
| 19 | 19 |
before_update :delete_publication_cache |
| 20 | 20 |
|
| 21 | 21 |
# tod: review scope of ordering |
| ... | ... | |
| 44 | 44 |
# using default setter (attr_writer) |
| 45 | 45 |
|
| 46 | 46 |
if self.author.nil? |
| 47 |
return ""
|
|
| 47 |
@search_author_class = ""
|
|
| 48 | 48 |
else |
| 49 |
return "Author"
|
|
| 49 |
@search_author_class = "Author"
|
|
| 50 | 50 |
end |
| 51 |
|
|
| 52 |
@search_author_class |
|
| 51 | 53 |
end |
| 52 | 54 |
|
| 55 |
# def search_author_class=(search_author_class) |
|
| 56 |
# @search_author_class = search_author_class |
|
| 57 |
# end |
|
| 58 |
|
|
| 53 | 59 |
def search_author_id |
| 54 | 60 |
if self.author.nil? |
| 55 |
return ""
|
|
| 61 |
"xxx"
|
|
| 56 | 62 |
else |
| 57 |
return self.author_id
|
|
| 63 |
author_id |
|
| 58 | 64 |
end |
| 59 | 65 |
end |
| 60 | 66 |
|
| ... | ... | |
| 87 | 93 |
Rails.cache.delete "publication-#{publication.id}-bibtex"
|
| 88 | 94 |
end |
| 89 | 95 |
|
| 96 |
private |
|
| 97 |
|
|
| 90 | 98 |
def set_author |
| 91 | 99 |
# if an author, simply associates with it |
| 92 | 100 |
# if an user, checks if it has already an author associated with it |
| ... | ... | |
| 95 | 103 |
|
| 96 | 104 |
logger.error { "%%%%%%%%%%%%%%% Associate Author User %%%%%%%%%%%%%%" }
|
| 97 | 105 |
|
| 98 |
logger.error { "EU #{self.to_yaml}" }
|
|
| 99 |
logger.error { "Class: #{search_author_class}" }
|
|
| 100 |
logger.error { "ID #{search_author_id}" }
|
|
| 106 |
logger.error { "Me #{self.to_yaml}" }
|
|
| 107 |
logger.error { "Class: #{@search_author_class}" }
|
|
| 108 |
logger.error { "ID #{@search_author_id}" }
|
|
| 101 | 109 |
|
| 102 |
case self.search_author_class
|
|
| 110 |
case @search_author_class
|
|
| 103 | 111 |
when "" |
| 104 | 112 |
logger.debug { "Adding new author to the database." }
|
| 105 | 113 |
author = Author.new |
| ... | ... | |
| 107 | 115 |
|
| 108 | 116 |
when "User" |
| 109 | 117 |
# get user id |
| 110 |
user = User.find(self.search_author_id)
|
|
| 118 |
user = User.find(@search_author_id)
|
|
| 111 | 119 |
logger.error { "Found user with this ID: #{user.id}" }
|
| 112 | 120 |
|
| 113 | 121 |
if user.author.nil? |
| ... | ... | |
| 124 | 132 |
end |
| 125 | 133 |
|
| 126 | 134 |
when "Author" |
| 127 |
author = Author.find(self.search_author_id)
|
|
| 135 |
author = Author.find(@search_author_id)
|
|
| 128 | 136 |
end |
| 129 | 137 |
|
| 130 | 138 |
self.author = author |
Also available in: Unified diff