Revision 1450:020bc7fe7a2a plugins/redmine_bibliography/lib

View differences:

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