Module: Shared::Dwc::MediaExtensions
- Extended by:
- ActiveSupport::Concern
- Includes:
- MediaIdentifier
- Included in:
- Image::DwcMediaExtensions, Sound::DwcMediaExtensions
- Defined in:
- app/models/concerns/shared/dwc/media_extensions.rb
Overview
A concern on media items like images and sounds.
Constant Summary collapse
- DWC_MEDIA_SHARED_EXTENSION_MAP =
Shared implementation amongst all media sources.
{ identifier: :dwc_media_identifier, providerManagedID: :dwc_media_provider_managed_id, # TODO currently .id ?? 'dc:rights': :dwc_media_dc_rights, 'dcterms:rights': :dwc_media_dcterms_rights, Owner: :dwc_media_owner, Credit: :dwc_media_credit, 'dc:creator': :dwc_media_dc_creator, 'dcterms:creator': :dwc_media_dcterms_creator, }.freeze
Instance Method Summary collapse
- #dwc_media_credit ⇒ Object
- #dwc_media_dc_creator ⇒ Object
- #dwc_media_dc_rights ⇒ Object
- #dwc_media_dcterms_creator ⇒ Object
- #dwc_media_dcterms_rights ⇒ Object
- #dwc_media_owner ⇒ Object
-
#dwc_media_provider_managed_id ⇒ Object
dwc_media_identifier is now provided by Shared::Dwc::MediaIdentifier.
Instance Method Details
#dwc_media_credit ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 54 def dwc_media_credit media = self.class .joins(attribution: :roles) .where(roles: {type: 'AttributionCopyrightHolder'}) .where(id: id) .includes(:attribution) .first return nil if media.nil? ApplicationController.helpers.attribution_copyright_label(media.attribution) end |
#dwc_media_dc_creator ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 67 def dwc_media_dc_creator self.class .joins(attribution: {roles: :person}) .where(roles: {type: 'AttributionCreator'}) .where(id: id) .order('roles.position') .pluck('people.cached') .join(Shared::IsDwcOccurrence::DWC_DELIMITER) end |
#dwc_media_dc_rights ⇒ Object
24 25 26 |
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 24 def dwc_media_dc_rights dwc_media_dcterms_rights end |
#dwc_media_dcterms_creator ⇒ Object
77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 77 def dwc_media_dcterms_creator self.class .joins(attribution: {roles: {person: :identifiers}}) .where(roles: {type: 'AttributionCreator'}) .where(id: id) .where("identifiers.type = 'Identifier::Global::Orcid' OR identifiers.type = 'Identifier::Global::Wikidata'") .order('roles.position') .pluck('identifiers.cached') .join(CollectionObject::DWC_DELIMITER) end |
#dwc_media_dcterms_rights ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 28 def dwc_media_dcterms_rights CREATIVE_COMMONS_LICENSES[ self.class .joins(:attribution) .where(id: id) .pluck('attributions.license') .first ]&.[](:link) end |
#dwc_media_owner ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 38 def dwc_media_owner roles = AttributionOwner .joins("INNER JOIN attributions ON attributions.id = roles.role_object_id AND roles.role_object_type = 'Attribution'") .where(attributions: {attribution_object_id: id, attribution_object_type: self.class.base_class.name}) .order(:position) # Map each role to either person.cached or organization.name. roles.map do |role| if role.person_id Person.find(role.person_id).cached elsif role.organization_id Organization.find(role.organization_id).name end end.compact.join(Shared::IsDwcOccurrence::DWC_DELIMITER) end |
#dwc_media_provider_managed_id ⇒ Object
dwc_media_identifier is now provided by Shared::Dwc::MediaIdentifier
20 21 22 |
# File 'app/models/concerns/shared/dwc/media_extensions.rb', line 20 def dwc_media_provider_managed_id id end |