Class: Collector

Inherits:
Role::ProjectRole show all
Includes:
Shared::DwcOccurrenceHooks
Defined in:
app/models/collector.rb

Instance Attribute Summary

Attributes inherited from Role

#organization_id, #person_id, #position, #project_id, #role_object_id, #role_object_type, #type

Attributes included from Housekeeping::Users

#by

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Role::ProjectRole

#set_project_if_possible

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from Role

#agent, #agent_is_legal, #agent_present, #agent_type, #cached_trigger_methods, #cached_triggers, #is_last_role?, #only_one_agent, #organization_allowed?, #set_cached, #set_role_object_cached

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::PolymorphicAnnotator

#annotated_object_is_persisted?

Methods included from Housekeeping::Users

#set_created_by_id, #set_updated_by_id

Methods inherited from ApplicationRecord

transaction_with_retry

Class Method Details

.human_nameObject

Collectors should not trigger spatial updates def cached_triggers

return { }  #  { CollectingEvent: [:set_cached_cached ] } # does not yet reference Collecotrs

end



32
33
34
# File 'app/models/collector.rb', line 32

def self.human_name
  'Collector'
end

Instance Method Details

#do_not_set_cachedObject



23
24
25
# File 'app/models/collector.rb', line 23

def do_not_set_cached
  true
end

#dwc_occurrencesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/collector.rb', line 5

def dwc_occurrences
  co = DwcOccurrence
    .joins("JOIN collection_objects co on dwc_occurrence_object_id = co.id AND dwc_occurrence_object_type = 'CollectionObject'")
    .joins('JOIN collecting_events ce on co.collecting_event_id = ce.id')
    .joins("JOIN roles r on r.type = 'Collector' AND r.role_object_type = 'CollectingEvent' AND r.role_object_id = ce.id")
    .where(r: {id:})
    .distinct

  fo = DwcOccurrence
    .joins("JOIN field_occurrences fo on dwc_occurrence_object_id = fo.id AND dwc_occurrence_object_type = 'FieldOccurrence'")
    .joins('JOIN collecting_events ce on fo.collecting_event_id = ce.id')
    .joins("JOIN roles r on r.type = 'Collector' AND r.role_object_type = 'CollectingEvent' AND r.role_object_id = ce.id")
    .where(r: {id:})
    .distinct

  ::Queries.union(DwcOccurrence, [co, fo])
end

#year_active_yearObject



36
37
38
39
40
# File 'app/models/collector.rb', line 36

def year_active_year
  [ role_object.end_date_year,
    role_object.start_date_year
  ].compact.first
end