Method: Osm::Event::Attendance#update

Defined in:
lib/osm/event.rb

#update(api) ⇒ Boolean

Update event attendance

Parameters:

  • api (Osm::Api)

    The api to use to make the request

Returns:

  • (Boolean)

    if the operation suceeded or not



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
854
855
856
857
858
859
860
861
862
# File 'lib/osm/event.rb', line 804

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