Revision 1444:e2485421fc14 plugins/redmine_bibliography

View differences:

plugins/redmine_bibliography/app/controllers/publications_controller.rb
203 203
    # todo: make sure query works with both pgres and mysql ~lf.20131010
204 204
    authors_list = Author.joins(:authorships).where("LOWER(authorships.name_on_paper) LIKE LOWER(?)", "%#{params[:term]}%").uniq
205 205

  
206
    users_list = User.active.like(params[:term]).find(:all, :limit => 100)
206
    # name_like scope, defined in lib/user_author patch
207
    users_list = User.active.name_like(params[:term]).find(:all, :limit => 100)
207 208

  
208 209
    logger.debug "Query for \"#{params[:term]}\" returned \"#{authors_list.size}\" authors and \"#{users_list.size}\" users"
209 210

  
plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb
4 4
  module UserAuthorPatch
5 5
    def self.included(base)
6 6
      base.send(:include, InstanceMethods)
7
      extend ClassMethods
7

  
8
      base.class_eval do
9
        # adapted from the app/models/principals_model.rb
10
        # to remove the email address from the search
11
        scope :name_like, lambda {|q|
12
          q = q.to_s
13
          if q.blank?
14
            where({})
15
          else
16
            pattern = "%#{q}%"
17
            sql = %w(login firstname lastname).map {|column| "LOWER(#{  table_name}.    #{column}) LIKE LOWER(:p)"}.join(" OR ")
18
            params = {:p => pattern}
19
            if q =~ /^(.+)\s+(.+)$/
20
              a, b = "#{$1}%", "#{$2}%"
21
              sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:a) AND  LOWER    (#{table_name}.lastname) LIKE LOWER(:b))"
22
              sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:b) AND  LOWER    (#{table_name}.lastname) LIKE LOWER(:a))"
23
              params.merge!(:a => a, :b => b)
24
            end
25
          where(sql, params)
26
          end
27
        }
28
      end #base.class_eval
8 29

  
9 30
    end #self.included
10 31

  
11
    module ClassMethods
12
    end
13

  
14 32
    module InstanceMethods
15 33

  
34
      # todo: deprecated? ~lf.20131011
16 35
      def institution
17 36
        unless self.ssamr_user_detail.nil?
18 37
          institution_name = self.ssamr_user_detail.institution_name

Also available in: Unified diff