Revision 1081:b56a4c5afa35 vendor/plugins/redmine_bibliography/app/models

View differences:

vendor/plugins/redmine_bibliography/app/models/author.rb
1 1
class Author < ActiveRecord::Base
2
  unloadable
3
  
2 4
  has_many :authorships, :dependent => :destroy
3 5
  has_many :publications, :through => :authorships
4 6

  
vendor/plugins/redmine_bibliography/app/models/bibtex_entry_type.rb
1 1
class BibtexEntryType < ActiveRecord::Base
2
  unloadable
2 3

  
3 4
  @@fields = Hash['article', ['journal', 'year', 'volume', 'number', 'pages', 'month', 'note' ], 
4 5
                  'book' , [ 'editor', 'publisher', 'volume', 'series', 'address', 'edition', 'month', 'year', 'note' ],
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
  
60
  
61
  
62
  
59

  
60
  def print_bibtex_author_names
61
    # this authors are correctly sorted because the authorships model
62
    # already outputs the author names ASC by auth_order
63
    self.authorships.map{|a| a.name_on_paper}.join(' and ')
64
  end
65

  
66
  def print_entry(style)
67
    bib = BibTeX::Entry.new
68

  
69
    bib.author = self.print_bibtex_author_names
70
    bib.title = self.title
71

  
72
    self.bibtex_entry.attributes.keys.sort.each do |key|
73
      value = self.bibtex_entry.attributes[key].to_s
74
      next if key == 'id' or key == 'publication_id' or value == ""
75

  
76
      if key == "entry_type"
77
        bib.type = BibtexEntryType.find(self.bibtex_entry.entry_type).name
78
      else
79
        bib[key.to_sym] = value
80
      end
81
    end
82

  
83
    if style == :ieee
84
      CiteProc.process bib.to_citeproc, :style => :ieee, :format => :html
85
    else
86
      bibtex = bib.to_s :include => :meta_content
87
      bibtex.strip!
88
      logger.error { bibtex }
89
    end
90
  end
63 91
end

Also available in: Unified diff