Revision 1403:35732ac4324a plugins/redmine_bibliography/app/models

View differences:

plugins/redmine_bibliography/app/models/authorship.rb
52 52
    @search_author_class || aclass
53 53
  end
54 54

  
55
  # def search_author_class=(search_author_class)
56
  #  @search_author_class = search_author_class
57
  # end
58

  
59 55
  def search_author_id
60 56
    if self.author.nil?
61 57
      authid = ""
......
99 95
  private
100 96

  
101 97
  def set_author
102
    # if an author, simply associates with it
103
    # if an user, checks if it has already an author associated with it
104
    # if so, assicoates with that author
105
    # otherwise, creates a new author
98
    # do we want to associate the authorship
99
    #  with an existing author/user?
100
    if @search_author_tie
101
      # if an author, simply associates with it
102
      # if an user, checks if it has already an author associated with it
103
      #   if so, associates with that author
104
      #   otherwise, creates a new author
106 105

  
107
    logger.error { "%%%%%%%%%%%%%%% Associate Author User %%%%%%%%%%%%%%" }
106
      case @search_author_class
107
      when ""
108
        author = Author.new
109
        author.save
108 110

  
109
    logger.error { "Me #{self.to_yaml}" }
110
    logger.error { "Class: #{@search_author_class}" }
111
    logger.error { "ID #{@search_author_id}" }
111
      when "User"
112
        user = User.find(@search_author_id)
112 113

  
113
    case @search_author_class
114
    when ""
115
      logger.debug { "Adding new author to the database." }
114
        if user.author.nil?
115
          # User w/o author:
116
          # create new author and update user
117
          author = Author.new
118
          author.save
119
          user.author = author
120
          user.save
121
        else
122
          author = user.author
123
        end
124

  
125
      when "Author"
126
        author = Author.find(@search_author_id)
127
      end
128

  
129
    # if we don't want to associate with an existing author/user
130
    else
131
      # todo: should we delete any previously existing relationship?
116 132
      author = Author.new
117 133
      author.save
118

  
119
    when "User"
120
      # get user id
121
      user = User.find(@search_author_id)
122
      logger.error { "Found user with this ID: #{user.id}" }
123

  
124
      if user.author.nil?
125
        logger.error { "The user has no author... creating one!" }
126

  
127
        # User w/o author:
128
        # create new author and update user
129
        author = Author.new
130
        author.save
131
        user.author = author
132
        user.save
133
      else
134
        logger.error { "found an author!" }
135
        author = user.author
136
      end
137

  
138
    when "Author"
139
      author = Author.find(@search_author_id)
140 134
    end
141 135

  
142 136
    self.author = author

Also available in: Unified diff