annotate vendor/plugins/redmine_bibliography/app/models/publication.rb @ 658:65749e700af0 feature_36

Feature #284: New, Edit and Show views already with the External URL field.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Fri, 09 Sep 2011 15:34:19 +0100
parents 1ee95265342f
children 865d079e5fa0
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
luis@643 20 after_save :notify_authors
chris@653 21
chris@653 22 # Ensure error message uses proper text instead of
chris@653 23 # bibtex_entry.entry_type (#268). There has to be a better way to
chris@653 24 # do this!
chris@653 25 def self.human_attribute_name(k)
chris@653 26 if k == 'bibtex_entry.entry_type'
chris@653 27 l(:field_entry_type)
chris@653 28 else
chris@653 29 super
chris@653 30 end
chris@653 31 end
chris@653 32
luis@643 33 # Returns the mail adresses of users that should be notified
luis@643 34 def notify_authors
luis@651 35
luis@643 36 self.authors.each do |author|
luis@651 37 Rails.logger.debug { "Sending mail to \"#{self.title}\" publication authors." }
luis@649 38 Mailer.deliver_publication_added(author.user, self) unless author.user.nil?
luis@643 39 end
luis@643 40
luis@643 41 end
luis@643 42
luis@556 43
luis@556 44 def set_initial_author_order
luis@556 45 authorships = self.authorships
luis@556 46
luis@556 47 logger.debug { "Publication \"#{self.title}\" has #{authorships.size} authors." }
luis@556 48
luis@556 49 authorships.each_with_index do |authorship, index|
luis@556 50 if authorship.auth_order.nil?
luis@556 51 authorship.auth_order = index
luis@556 52 end
luis@556 53 end
luis@556 54 end
luis@556 55
luis@556 56
luis@556 57
luis@556 58
luis@328 59 end