annotate vendor/plugins/redmine_bibliography/app/models/publication.rb @ 711:60773bbfe050 feature_36_testing

This approach lead to a dead end.
author Luis Figueira <luis.figueira@eecs.qmul.ac.uk>
date Wed, 21 Sep 2011 15:52:05 +0100
parents 865d079e5fa0
children b1debf464389
rev   line source
luis@385 1 # vendor/plugins/redmine_bibliography/app/models/publication.rb
luis@385 2
luis@328 3 class Publication < ActiveRecord::Base
luis@428 4 unloadable
luis@445 5
luis@571 6 has_many :authorships, :dependent => :destroy, :order => "auth_order ASC"
luis@447 7 has_many :authors, :through => :authorships, :uniq => true
luis@446 8
luis@560 9 has_one :bibtex_entry, :dependent => :destroy
luis@376 10
luis@376 11 validates_presence_of :title
luis@445 12
luis@445 13 accepts_nested_attributes_for :authorships
luis@446 14 accepts_nested_attributes_for :authors, :allow_destroy => true
luis@454 15 accepts_nested_attributes_for :bibtex_entry, :allow_destroy => true
luis@454 16
luis@464 17 has_and_belongs_to_many :projects, :uniq => true
luis@428 18
chris@567 19 before_save :set_initial_author_order
chris@653 20
chris@653 21 # Ensure error message uses proper text instead of
chris@653 22 # bibtex_entry.entry_type (#268). There has to be a better way to
chris@653 23 # do this!
chris@653 24 def self.human_attribute_name(k)
chris@653 25 if k == 'bibtex_entry.entry_type'
chris@653 26 l(:field_entry_type)
chris@653 27 else
chris@653 28 super
chris@653 29 end
chris@653 30 end
chris@653 31
luis@666 32 def notify_authors_publication_added(project)
luis@643 33 self.authors.each do |author|
luis@651 34 Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
luis@666 35 Mailer.deliver_publication_added(author.user, self, project) unless author.user.nil?
luis@643 36 end
luis@666 37 end
luis@666 38
luis@666 39 def notify_authors_publication_updated(project)
luis@666 40 self.authors.each do |author|
luis@666 41 Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
luis@666 42 Mailer.deliver_publication_updated(author.user, self, project) unless author.user.nil?
luis@666 43 end
luis@643 44 end
luis@643 45
luis@556 46
luis@556 47 def set_initial_author_order
luis@556 48 authorships = self.authorships
luis@556 49
luis@556 50 logger.debug { "Publication \"#{self.title}\" has #{authorships.size} authors." }
luis@556 51
luis@556 52 authorships.each_with_index do |authorship, index|
luis@556 53 if authorship.auth_order.nil?
luis@556 54 authorship.auth_order = index
luis@556 55 end
luis@556 56 end
luis@556 57 end
luis@556 58
luis@556 59
luis@556 60
luis@556 61
luis@328 62 end