To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / plugins / redmine_bibliography / lib / bibliography / user_author_patch.rb @ 1441:8d721cac2925

History | View | Annotate | Download (1.46 KB)

1 466:a7dc708d48a1 luis
require_dependency 'user'
2
3
module Bibliography
4 1070:858f042e8d11 luis
  module UserAuthorPatch
5 466:a7dc708d48a1 luis
    def self.included(base)
6 1070:858f042e8d11 luis
      base.send(:include, InstanceMethods)
7 1441:8d721cac2925 luis
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
29 1070:858f042e8d11 luis
30 466:a7dc708d48a1 luis
    end #self.included
31 1070:858f042e8d11 luis
32 483:cc267eb99115 luis
    module InstanceMethods
33 518:b24091590b63 luis
34 1441:8d721cac2925 luis
      # todo: deprecated? ~lf.20131011
35 600:c3c1091639ad luis
      def institution
36
        unless self.ssamr_user_detail.nil?
37
          institution_name = self.ssamr_user_detail.institution_name
38
        else
39
          institution_name = "No Institution Set"
40 1070:858f042e8d11 luis
        end
41
        return institution_name
42 600:c3c1091639ad luis
      end
43
44 483:cc267eb99115 luis
    end #InstanceMethods
45 1070:858f042e8d11 luis
46 466:a7dc708d48a1 luis
  end #UserPublicationsPatch
47 567:5404f7dfb4b3 chris
end #RedmineBibliography