Class: Atrium::Showcase
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Atrium::Showcase
show all
- Defined in:
- app/models/atrium/showcase.rb
Defined Under Namespace
Classes: FacetSelection, Item
Instance Method Summary
collapse
Instance Method Details
#for_exhibit? ⇒ Boolean
112
113
114
|
# File 'app/models/atrium/showcase.rb', line 112
def for_exhibit?
showcases_type == "Atrium::Exhibit"
end
|
#get_parent_path ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/models/atrium/showcase.rb', line 36
def get_parent_path
if for_exhibit?
facet={}
unless facet_selections.blank?
facet[facet_selections.first.solr_facet_name]=facet_selections.first.value
end
path= Rails.application.routes.url_helpers.atrium_exhibit_path(parent, :f=>facet)
return path
else
return parent
end
end
|
#parent ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'app/models/atrium/showcase.rb', line 96
def parent
if showcases_type && showcases_id
begin
showcases_type.constantize.find(showcases_id)
rescue
logger.error("Invalid showcase parent type set for showcase id: #{id}")
nil
end
end
end
|
#parent_title ⇒ Object
108
109
110
|
# File 'app/models/atrium/showcase.rb', line 108
def parent_title
parent.pretty_title
end
|
#showcase_items ⇒ Object
78
79
80
|
# File 'app/models/atrium/showcase.rb', line 78
def showcase_items
read_attribute(:showcase_items) || write_attribute(:showcase_items, {})
end
|
#showcase_items=(solr_doc_ids = []) ⇒ Object
82
83
84
85
86
|
# File 'app/models/atrium/showcase.rb', line 82
def showcase_items=(solr_doc_ids = [])
showcase_items[:type]="featured"
showcase_items[:solr_doc_ids]=solr_doc_ids.join(',')
write_attribute(:showcase_items, showcase_items)
end
|
#solr_doc_ids ⇒ Object
88
89
90
|
# File 'app/models/atrium/showcase.rb', line 88
def solr_doc_ids
showcase_items[:solr_doc_ids] unless showcase_items.blank?
end
|
#type ⇒ Object
92
93
94
|
# File 'app/models/atrium/showcase.rb', line 92
def type
showcase_items[:type] unless showcase_items.blank?
end
|
#with_selected_facets ⇒ Object
This method will select showcase objects that have exactly the selected facets passed in (but no more or no less) and is tied to the given exhibit id It expects two parameters: @param the exhibit id @param hash of key value pairs of selected facets
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'app/models/atrium/showcase.rb', line 121
scope :with_selected_facets, lambda {|*args|
parent_id, parent_type, selected_facets = args.flatten(1)
selected_facets =
if parent_type.eql?("Atrium::Collection")
{}
else
selected_facets
end
facet_condition_values = []
facet_conditions =
if selected_facets
selected_facets.collect {|key,value|
facet_condition_values << key
facet_condition_values << (value.is_a?(String) ? value : value.flatten.compact.to_s)
%((
#{Atrium::Showcase::FacetSelection.quoted_table_name}.`solr_facet_name` = ?
AND #{Atrium::Showcase::FacetSelection.quoted_table_name}.`value` = ?
))
}
else
[]
end
if facet_conditions.empty?
joins(%(
LEFT OUTER JOIN #{Atrium::Showcase::FacetSelection.quoted_table_name}
ON #{quoted_table_name}.`id` = #{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`)
).
where(:showcases_id => parent_id,:showcases_type => parent_type).
where("#{Atrium::Showcase::FacetSelection.quoted_table_name}.`id` is NULL")
else
conditions = [%(
#{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`
IN (
SELECT #{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`
FROM #{Atrium::Showcase::FacetSelection.quoted_table_name}
INNER JOIN #{quoted_table_name}
ON #{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id` = #{quoted_table_name}.`id`
WHERE #{quoted_table_name}.showcases_id = ?
AND #{quoted_table_name}.`showcases_type` = ?
AND (#{facet_conditions.join(" OR ")})
)
), parent_id, parent_type] + facet_condition_values
having_str = %(
COUNT(#{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`) = #{facet_conditions.size}
)
joins(:facet_selections).
where(conditions).
group("#{Atrium::Showcase::FacetSelection.quoted_table_name}.`atrium_showcase_id`").
having(having_str)
end
}
|