Class: Osm::Event::Attendance

Inherits:
Model
  • Object
show all
Defined in:
lib/osm/event.rb

Constant Summary collapse

SORT_BY =
[:event, :row]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Model

#<, #<=, #<=>, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i

Instance Attribute Details

#attendingSymbol



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#date_of_birthDate



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#fieldsHash



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#first_nameString



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#grouping__idFixnum



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#last_nameString



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#member_idFixnum



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#payment_controlSymbol



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#paymentsHash



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

#rowFixnum



749
# File 'lib/osm/event.rb', line 749

attribute :row, :type => Integer

Instance Method Details

#get_audit_trail(api, options = {}) ⇒ Array<Hash>

Get audit trail



859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
# File 'lib/osm/event.rb', line 859

def get_audit_trail(api, options={})
  require_ability_to(api, :read, :events, event.section_id, options)
  cache_key = ['event\_attendance\_audit', event.id, member_id]

  if !options[:no_cache] && cache_exist?(api, cache_key)
    return cache_read(api, cache_key)
  end

  data = api.perform_query("events.php?action=getEventAudit&sectionid=#{event.section_id}&scoutid=#{member_id}&eventid=#{event.id}")
  data ||= []

  attending_values = {
    'Yes' => :yes,
    'No' => :no,
    'Invited' => :invited,
    'Show in My.SCOUT' => :shown,
    'Reserved' => :reserved,
  }

  trail = []
  data.each do |item|
    this_item = {
      :at => DateTime.strptime(item['date'], '%d/%m/%Y %H:%M'),
      :by => item['updatedby'].strip,
      :type => item['type'].to_sym,
      :description => item['desc'],
      :event_id => event.id,
      :member_id => member_id,
      :event_attendance => self,
    }
    if this_item[:type].eql?(:detail)
      results = this_item[:description].match(/\ASet '(?<label>.+)' to '(?<value>.+)'\Z/)
      this_item[:label] = results[:label]
      this_item[:value] = results[:value]
    end
    if this_item[:type].eql?(:attendance)
      results = this_item[:description].match(/\AAttendance: (?<attending>.+)\Z/)
      this_item[:attendance] = attending_values[results[:attending]]
    end
    trail.push this_item
  end

  cache_write(api, cache_key, trail)
  return trail
end

#inspectObject



937
938
939
# File 'lib/osm/event.rb', line 937

def inspect
  Osm.inspect_instance(self, options={:replace_with => {'event' => :id}})
end

#update(api) ⇒ Boolean

Update event attendance



795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
# File 'lib/osm/event.rb', line 795

def update(api)
  require_ability_to(api, :write, :events, event.section_id)

  payment_values = {
    :manual => 'Manual',
    :automatic => 'Automatic',
  }
  attending_values = {
    :yes => 'Yes',
    :no => 'No',
    :invited => 'Invited',
    :shown => 'Show in My.SCOUT',
    :reserved => 'Reserved',
  }

  updated = true
  fields.changes.each do |field, (was,now)|
    data = api.perform_query("events.php?action=updateScout", {
      'scoutid' => member_id,
      'column' => "f_#{field}",
      'value' => now,
      'sectionid' => event.section_id,
      'row' => row,
      'eventid' => event.id,
    })
    updated = false unless data.is_a?(Hash)
  end

  if changed_attributes.include?('payment_control')
    data = api.perform_query("events.php?action=updateScout", {
      'scoutid' => member_id,
      'column' => 'payment',
      'value' => payment_values[payment_control],
      'sectionid' => event.section_id,
      'row' => row,
      'eventid' => event.id,
    })
    updated = false unless data.is_a?(Hash)
  end
  if changed_attributes.include?('attending')
    data = api.perform_query("events.php?action=updateScout", {
      'scoutid' => member_id,
      'column' => 'attending',
      'value' => attending_values[attending],
      'sectionid' => event.section_id,
      'row' => row,
      'eventid' => event.id,
    })
    updated = false unless data.is_a?(Hash)
  end

  if updated
    reset_changed_attributes
    fields.clean_up!
    # The cached event attedance will be out of date
    cache_delete(api, ['event_attendance', event.id])
  end
  return updated
end