Class: Atrium::Showcase
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Atrium::Showcase
show all
- Defined in:
- app/models/atrium/showcase.rb
Overview
A Atrium::Showcase is a container for storing feature items and descriptions. A Atrium::Showcase can be attached to a collection, exhibit, or to specific combinations of selected facets and facet values within an exhibit. There can be multiple Atrium::Showcase in an Atrium::Exhibit.
Defined Under Namespace
Classes: FacetSelection, FeaturedSelection
Instance Method Summary
collapse
Instance Method Details
#assign_sequence ⇒ Object
97
98
99
100
101
102
|
# File 'app/models/atrium/showcase.rb', line 97
def assign_sequence
unless for_exhibit?
sequence= parent.showcases.size
self.update_attributes(sequence: sequence)
end
end
|
#facet_details ⇒ Object
46
47
48
49
|
# File 'app/models/atrium/showcase.rb', line 46
def facet_details
logger.debug("Belongs to: #{facet_selections.inspect}")
"#{facet_selections.solr_facet_name - facet_selections.value}"
end
|
#for_exhibit? ⇒ Boolean
42
43
44
|
# File 'app/models/atrium/showcase.rb', line 42
def for_exhibit?
showcases_type == "Atrium::Exhibit"
end
|
#parent ⇒ Object
56
57
58
|
# File 'app/models/atrium/showcase.rb', line 56
def parent
showcases
end
|
#parent_title ⇒ Object
38
39
40
|
# File 'app/models/atrium/showcase.rb', line 38
def parent_title
parent.pretty_title
end
|
#pretty_title ⇒ Object
104
105
106
|
# File 'app/models/atrium/showcase.rb', line 104
def pretty_title
id.blank? ? 'Unnamed Showcase' : "Showcase #{id}"
end
|
#showcase_items ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'app/models/atrium/showcase.rb', line 64
def showcase_items
items = read_attribute(:showcase_items) ||
write_attribute(:showcase_items, {})
if items && items[:solr_doc_ids]
items[:solr_doc_ids].split(",")
else
[]
end
end
|
#showcase_items=(solr_doc_ids = []) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'app/models/atrium/showcase.rb', line 75
def showcase_items=(solr_doc_ids = [])
unless solr_doc_ids.blank?
items={}
items[:type]="featured"
items[:solr_doc_ids]=solr_doc_ids.join(',')
write_attribute(:showcase_items, items)
else
write_attribute(:showcase_items, {})
end
end
|
#solr_doc_ids ⇒ Object
87
88
89
|
# File 'app/models/atrium/showcase.rb', line 87
def solr_doc_ids
showcase_items[:solr_doc_ids] unless showcase_items.blank?
end
|
#type ⇒ Object
91
92
93
|
# File 'app/models/atrium/showcase.rb', line 91
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
118
119
120
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
178
179
180
181
182
183
184
185
186
187
188
|
# File 'app/models/atrium/showcase.rb', line 118
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_selection_quoted_table_name =
Atrium::Showcase::FacetSelection.quoted_table_name
facet_condition_values = []
facet_conditions =
if selected_facets
selected_facets.collect {|key,value|
facet_condition_values << key
facet_condition_values << [value].flatten.compact.first.to_s
%((
#{facet_selection_quoted_table_name}.`solr_facet_name` = ?
AND #{facet_selection_quoted_table_name}.`value` = ?
))
}
else
[]
end
if facet_conditions.empty?
joins(
%(
LEFT OUTER JOIN #{facet_selection_quoted_table_name}
ON #{quoted_table_name}.`id` =
#{facet_selection_quoted_table_name}.`atrium_showcase_id`
)
).
where(showcases_id: parent_id,showcases_type: parent_type).
where("#{facet_selection_quoted_table_name}.`id` is NULL")
else
conditions = [
%(
#{facet_selection_quoted_table_name}.`atrium_showcase_id`
IN
(
SELECT #{facet_selection_quoted_table_name}.`atrium_showcase_id`
FROM #{facet_selection_quoted_table_name}
INNER JOIN #{quoted_table_name}
ON #{facet_selection_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(
#{facet_selection_quoted_table_name}.`atrium_showcase_id`
) =
#{facet_conditions.size}
)
joins(:facet_selections).
where(conditions).
group("#{facet_selection_quoted_table_name}.`atrium_showcase_id`").
having(having_str)
end
}
|