Commit bb3b9e56ee616b2d459559bc51f615f15b9f276f
1 parent
67f99b16
Exists in
master
and in
5 other branches
software_search: Add search scope. Needs atttention on language,database, controlled vocabulary
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
2 changed files
with
71 additions
and
0 deletions
Show diff stats
lib/mpog_software_plugin.rb
| ... | ... | @@ -353,6 +353,10 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
| 353 | 353 | elsif params[:action] == "communities" and params[:type] == "Institution" |
| 354 | 354 | |
| 355 | 355 | elsif params[:action] == "communities" and params[:type] == "Software" |
| 356 | + SoftwareInfo.search(params[:name], params[:database_description][:id], | |
| 357 | + params[:programming_language][:id], params[:operating_system][:id], | |
| 358 | + params[:controlled_vocabulary], params[:license_info][:id], params[:e_ping], params[:e_mag], | |
| 359 | + params[:icp_brasil], params[:e_arq], params[:internacionalizable]) | |
| 356 | 360 | |
| 357 | 361 | else |
| 358 | 362 | [] # An empty list will trigger noosfero's default communities search | ... | ... |
lib/software_info.rb
| ... | ... | @@ -21,6 +21,73 @@ class SoftwareInfo < ActiveRecord::Base |
| 21 | 21 | joins(:community).where("name ilike ?", "%#{name}%") |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | + scope :search, lambda { |name="", database_description="", programming_language="", operating_system="", | |
| 25 | + controlled_vocabulary="", license_info="", e_ping="", e_mag="", | |
| 26 | + icp_brasil="", e_arq="", internacionalizable=""| | |
| 27 | + | |
| 28 | + like_sql = "" | |
| 29 | + values = [] | |
| 30 | + | |
| 31 | + unless name.nil? and name.blank? | |
| 32 | + like_sql << "name ILIKE ? AND " | |
| 33 | + values << "%#{name}%" | |
| 34 | + end | |
| 35 | + | |
| 36 | + unless database_description.nil? and database_description.blank? | |
| 37 | + software_databases = SoftwareDatabase.where(:database_description_id => database_description) | |
| 38 | + like_sql << "software_databases ILIKE ? AND " | |
| 39 | + values << "%#{software_databases}%" | |
| 40 | + end | |
| 41 | + | |
| 42 | + unless programming_language.nil? and programming_language.blank? | |
| 43 | + like_sql << "programming_language_id ILIKE ? AND " | |
| 44 | + values << "%#{programming_language}%" | |
| 45 | + end | |
| 46 | + | |
| 47 | + unless operating_system.nil? and operating_system.blank? | |
| 48 | + like_sql << "operating_system_id ILIKE ? AND " | |
| 49 | + values << "%#{operating_system}%" | |
| 50 | + end | |
| 51 | + | |
| 52 | + unless license_info.nil? and license_info.blank? | |
| 53 | + like_sql << "license_info_id ILIKE ? AND " | |
| 54 | + values << "%#{license_info}%" | |
| 55 | + end | |
| 56 | + | |
| 57 | + unless e_ping.nil? and e_ping.blank? and e_ping == "Any" | |
| 58 | + like_sql << "e_ping ILIKE ? AND " | |
| 59 | + values << "%#{e_ping}%" | |
| 60 | + end | |
| 61 | + | |
| 62 | + unless e_mag.nil? and e_mag.blank? and e_mag == "Any" | |
| 63 | + like_sql << "e_mag ILIKE ? AND " | |
| 64 | + values << "%#{e_mag}%" | |
| 65 | + end | |
| 66 | + | |
| 67 | + unless icp_brasil.nil? and icp_brasil.blank? and icp_brasil == "Any" | |
| 68 | + like_sql << "icp_brasil ILIKE ? AND " | |
| 69 | + values << "%#{icp_brasil}%" | |
| 70 | + end | |
| 71 | + | |
| 72 | + unless e_arq.nil? and e_arq.blank? and e_arq == "Any" | |
| 73 | + like_sql << "e_arq ILIKE ? AND " | |
| 74 | + values << "%#{e_arq}%" | |
| 75 | + end | |
| 76 | + | |
| 77 | + unless internacionalizable.nil? and internacionalizable.blank? and internacionalizable == "Any" | |
| 78 | + like_sql << "internacionalizable ILIKE ? AND " | |
| 79 | + values << "%#{internacionalizable}%" | |
| 80 | + end | |
| 81 | + | |
| 82 | + like_sql = like_sql[0..like_sql.length-5] | |
| 83 | + | |
| 84 | + { | |
| 85 | + :joins => :community, | |
| 86 | + :conditions=>[like_sql, *values] | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + | |
| 24 | 91 | def validate_operating_platform |
| 25 | 92 | self.errors.add(:operating_platform, _("can't be blank")) if self.operating_platform.blank? && self.errors.messages[:operating_platform].nil? |
| 26 | 93 | end | ... | ... |