Mercurial > hg > soundsoftware-site
comparison plugins/redmine_bibliography/lib/bibliography/user_author_patch.rb @ 1484:51364c0cd58f redmine-2.4-integration
Merge from live branch. Still need to merge manually in files overridden by plugins.
author | Chris Cannam |
---|---|
date | Wed, 15 Jan 2014 09:59:14 +0000 |
parents | 8d721cac2925 |
children |
comparison
equal
deleted
inserted
replaced
1464:261b3d9a4903 | 1484:51364c0cd58f |
---|---|
1 require_dependency 'user' | |
2 | |
3 module Bibliography | |
4 module UserAuthorPatch | |
5 def self.included(base) | |
6 base.send(:include, InstanceMethods) | |
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 | |
29 | |
30 end #self.included | |
31 | |
32 module InstanceMethods | |
33 | |
34 # todo: deprecated? ~lf.20131011 | |
35 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 end | |
41 return institution_name | |
42 end | |
43 | |
44 end #InstanceMethods | |
45 | |
46 end #UserPublicationsPatch | |
47 end #RedmineBibliography |