Class: Atrium::Showcase

Inherits:
ActiveRecord::Base
  • Object
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

Returns:

  • (Boolean)


112
113
114
# File 'app/models/atrium/showcase.rb', line 112

def for_exhibit?
  showcases_type == "Atrium::Exhibit"
end

#get_parent_pathObject



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

#parentObject



96
97
98
99
100
101
102
103
104
105
106
# File 'app/models/atrium/showcase.rb', line 96

def parent
#    debugger;true
  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_titleObject



108
109
110
# File 'app/models/atrium/showcase.rb', line 108

def parent_title
  parent.pretty_title
end

#showcase_itemsObject



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_idsObject



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

#typeObject



92
93
94
# File 'app/models/atrium/showcase.rb', line 92

def type
  showcase_items[:type] unless showcase_items.blank?
end

#with_selected_facetsObject

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

Returns:

  • Array of showcase objects found



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
    # unfortunately have to do subselect here to get this correct
    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
}