Module: Queries::Concerns::Attributions
- Extended by:
- ActiveSupport::Concern
- Included in:
- Image::Filter, Sound::Filter
- Defined in:
- lib/queries/concerns/attributions.rb
Overview
Helpers and facets for queries that reference Attributions.
Class Method Summary collapse
Instance Method Summary collapse
- #attribution_facet ⇒ Object
- #copyright_holder_facet ⇒ Object
- #copyright_year_facet ⇒ Object
- #creator_facet ⇒ Object
- #editor_facet ⇒ Object
- #license_facet ⇒ Object
- #owner_facet ⇒ Object
- #set_attributions_params(params) ⇒ Object
Class Method Details
.merge_clauses ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/queries/concerns/attributions.rb', line 163 def self.merge_clauses [ :attribution_facet, :copyright_holder_facet, :copyright_year_facet, :creator_facet, :editor_facet, :license_facet, :owner_facet ] end |
.params ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/queries/concerns/attributions.rb', line 7 def self.params [ :attribution, :copyright_after_year, :copyright_holder_id, :copyright_holder_id_all, :copyright_holder_organization_id, :copyright_prior_to_year, :copyright_year, :creator_id, :creator_id_all, :editor_id, :editor_id_all, :license, :owner_id, :owner_id_all, :owner_organization_id, copyright_holder_id: [], copyright_holder_organization_id: [], creator_id: [], editor_id: [], license: [], owner_id: [], owner_organization_id: [], ] end |
Instance Method Details
#attribution_facet ⇒ Object
175 176 177 178 179 180 181 182 183 |
# File 'lib/queries/concerns/attributions.rb', line 175 def attribution_facet return nil if attribution.nil? if attribution referenced_klass.joins(:attribution) else referenced_klass.where.missing(:attribution) end end |
#copyright_holder_facet ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/queries/concerns/attributions.rb', line 238 def copyright_holder_facet return nil if copyright_holder_id.empty? && copyright_holder_organization_id.empty? q = referenced_klass .joins(attribution: :roles) .where(roles: {type: 'AttributionCopyrightHolder'}) .where('roles.person_id IN (?) OR roles.organization_id IN (?)', copyright_holder_id, copyright_holder_organization_id ) if copyright_holder_id_all q .group(:id) .having("count(#{table.name}.id) = #{copyright_holder_id.length + copyright_holder_organization_id.length}") else q.distinct end end |
#copyright_year_facet ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/queries/concerns/attributions.rb', line 264 def copyright_year_facet return nil if copyright_year.nil? && copyright_after_year.nil? && copyright_prior_to_year.nil? if copyright_year return referenced_klass.joins(:attribution).where(attribution: { copyright_year: }) end t = ::Attribution.arel_table if copyright_after_year && copyright_prior_to_year.nil? y = t[:copyright_year].gt(copyright_after_year) elsif copyright_after_year.nil? && copyright_prior_to_year y = t[:copyright_year].lt(copyright_prior_to_year) else y = t[:copyright_year].gt(copyright_after_year).and( t[:copyright_year].lt(copyright_prior_to_year) ) end referenced_klass.joins(:attribution).where(y) end |
#creator_facet ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/queries/concerns/attributions.rb', line 185 def creator_facet return nil if creator_id.empty? q = referenced_klass .joins(attribution: :roles) .where(roles: {type: 'AttributionCreator'}) .where(roles: {person_id: creator_id}) if creator_id_all q .group(:id) .having("count(#{table.name}.id) = #{creator_id.length}") else q.distinct end end |
#editor_facet ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/queries/concerns/attributions.rb', line 202 def editor_facet return nil if editor_id.empty? q = referenced_klass .joins(attribution: :roles) .where(roles: {type: 'AttributionEditor'}) .where(roles: {person_id: editor_id}) if editor_id_all q .group(:id) .having("count(#{table.name}.id) = #{editor_id.length}") else q.distinct end end |
#license_facet ⇒ Object
258 259 260 261 262 |
# File 'lib/queries/concerns/attributions.rb', line 258 def license_facet return nil if license.empty? referenced_klass.joins(:attribution).where(attribution: { license: }).distinct end |
#owner_facet ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/queries/concerns/attributions.rb', line 219 def owner_facet return nil if owner_id.empty? && owner_organization_id.empty? q = referenced_klass .joins(attribution: :roles) .where(roles: {type: 'AttributionOwner'}) .where('roles.person_id IN (?) OR roles.organization_id IN (?)', owner_id, owner_organization_id ) if owner_id_all q .group(:id) .having("count(#{table.name}.id) = #{owner_id.length + owner_organization_id.length}") else q.distinct end end |
#set_attributions_params(params) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/queries/concerns/attributions.rb', line 145 def set_attributions_params(params) @attribution = boolean_param(params, :attribution) @copyright_after_year = params[:copyright_after_year] @copyright_holder_id = params[:copyright_holder_id] @copyright_holder_id_all = boolean_param(params, :copyright_holder_id_all) @copyright_holder_organization_id = params[:copyright_holder_organization_id] @copyright_prior_to_year = params[:copyright_prior_to_year] @copyright_year = params[:copyright_year] @creator_id = params[:creator_id] @creator_id_all = boolean_param(params, :creator_id_all) @editor_id = params[:editor_id] @editor_id_all = boolean_param(params, :editor_id_all) @license = params[:license] @owner_id = params[:owner_id] @owner_id_all = boolean_param(params, :owner_id_all) @owner_organization_id = params[:owner_organization_id] end |