Revision 1075:2cc9845228b3 vendor/plugins/redmine_bibliography/app/models
| vendor/plugins/redmine_bibliography/app/models/publication.rb | ||
|---|---|---|
| 2 | 2 |
|
| 3 | 3 |
class Publication < ActiveRecord::Base |
| 4 | 4 |
unloadable |
| 5 |
|
|
| 5 |
|
|
| 6 | 6 |
has_many :authorships, :dependent => :destroy, :order => "auth_order ASC" |
| 7 | 7 |
has_many :authors, :through => :authorships, :uniq => true |
| 8 |
|
|
| 8 |
|
|
| 9 | 9 |
has_one :bibtex_entry, :dependent => :destroy |
| 10 | 10 |
|
| 11 | 11 |
validates_presence_of :title |
| ... | ... | |
| 14 | 14 |
accepts_nested_attributes_for :authorships |
| 15 | 15 |
accepts_nested_attributes_for :authors, :allow_destroy => true |
| 16 | 16 |
accepts_nested_attributes_for :bibtex_entry, :allow_destroy => true |
| 17 |
|
|
| 17 |
|
|
| 18 | 18 |
has_and_belongs_to_many :projects, :uniq => true |
| 19 |
|
|
| 19 |
|
|
| 20 | 20 |
before_save :set_initial_author_order |
| 21 | 21 |
|
| 22 | 22 |
# Ensure error message uses proper text instead of |
| ... | ... | |
| 30 | 30 |
end |
| 31 | 31 |
end |
| 32 | 32 |
|
| 33 |
def notify_authors_publication_added(project)
|
|
| 33 |
def notify_authors_publication_added(project) |
|
| 34 | 34 |
self.authors.each do |author| |
| 35 | 35 |
Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
|
| 36 | 36 |
Mailer.deliver_publication_added(author.user, self, project) unless author.user.nil? |
| 37 | 37 |
end |
| 38 | 38 |
end |
| 39 |
|
|
| 40 |
def notify_authors_publication_updated(project)
|
|
| 39 |
|
|
| 40 |
def notify_authors_publication_updated(project) |
|
| 41 | 41 |
self.authors.each do |author| |
| 42 | 42 |
Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
|
| 43 | 43 |
Mailer.deliver_publication_updated(author.user, self, project) unless author.user.nil? |
| 44 | 44 |
end |
| 45 | 45 |
end |
| 46 |
|
|
| 47 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 | 48 |
def set_initial_author_order |
| 49 | 49 |
authorships = self.authorships |
| 50 |
|
|
| 50 |
|
|
| 51 | 51 |
logger.debug { "Publication \"#{self.title}\" has #{authorships.size} authors." }
|
| 52 |
|
|
| 52 |
|
|
| 53 | 53 |
authorships.each_with_index do |authorship, index| |
| 54 | 54 |
if authorship.auth_order.nil? |
| 55 | 55 |
authorship.auth_order = index |
| 56 | 56 |
end |
| 57 |
end
|
|
| 57 |
end |
|
| 58 | 58 |
end |
| 59 |
|
|
| 59 |
|
|
| 60 | 60 |
def print_bibtex_author_names |
| 61 |
# this authors are correctly sorted because the authorships model
|
|
| 61 |
# this authors are correctly sorted because the authorships model |
|
| 62 | 62 |
# already outputs the author names ASC by auth_order |
| 63 | 63 |
self.authorships.map{|a| a.name_on_paper}.join(' and ')
|
| 64 |
end
|
|
| 65 |
|
|
| 64 |
end |
|
| 65 |
|
|
| 66 | 66 |
def print_entry(style) |
| 67 | 67 |
bib = BibTeX::Entry.new |
| 68 | 68 |
|
| 69 | 69 |
bib.author = self.print_bibtex_author_names |
| 70 | 70 |
bib.title = self.title |
| 71 | 71 |
|
| 72 |
self.bibtex_entry.attributes.keys.sort.each do |key|
|
|
| 72 |
self.bibtex_entry.attributes.keys.sort.each do |key| |
|
| 73 | 73 |
value = self.bibtex_entry.attributes[key].to_s |
| 74 | 74 |
next if key == 'id' or key == 'publication_id' or value == "" |
| 75 | 75 |
|
| 76 |
if key == "entry_type"
|
|
| 76 |
if key == "entry_type" |
|
| 77 | 77 |
bib.type = BibtexEntryType.find(self.bibtex_entry.entry_type).name |
| 78 | 78 |
else |
| 79 | 79 |
bib[key.to_sym] = value |
| 80 |
end
|
|
| 80 |
end |
|
| 81 | 81 |
end |
| 82 |
|
|
| 82 |
|
|
| 83 | 83 |
if style == :ieee |
| 84 |
CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html
|
|
| 85 |
else
|
|
| 84 |
CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html |
|
| 85 |
else |
|
| 86 | 86 |
bibtex = bib.to_s :include => :meta_content |
| 87 | 87 |
bibtex.strip! |
| 88 | 88 |
logger.error { bibtex }
|
| 89 |
end
|
|
| 89 |
end |
|
| 90 | 90 |
end |
| 91 | 91 |
end |
Also available in: Unified diff