Class: Osm::Event::Attendance

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

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

Returns whether the member is attending (either :yes, :no, :invited, :shown, :reserved or nil).

Returns:

  • (Symbol)

    whether the member is attending (either :yes, :no, :invited, :shown, :reserved or nil)



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

attribute :row, :type => Integer

#date_of_birthDate

Returns the member’s date of birth.

Returns:

  • (Date)

    the member’s date of birth



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

attribute :row, :type => Integer

#fieldsHash

Returns Keys are the field’s id, values are the field values.

Returns:

  • (Hash)

    Keys are the field’s id, values are the field values



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

attribute :row, :type => Integer

#first_nameString

Returns the member’s first name.

Returns:

  • (String)

    the member’s first name



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

attribute :row, :type => Integer

#grouping__idFixnum

Returns OSM id for the grouping the member is in.

Returns:

  • (Fixnum)

    OSM id for the grouping the member is in



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

attribute :row, :type => Integer

#last_nameString

Returns the member’s last name.

Returns:

  • (String)

    the member’s last name



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

attribute :row, :type => Integer

#member_idFixnum

Returns OSM id for the member.

Returns:

  • (Fixnum)

    OSM id for the member



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

attribute :row, :type => Integer

#payment_controlSymbol

Returns whether payments are done manually or automatically (either :manual, :automatic or nil).

Returns:

  • (Symbol)

    whether payments are done manually or automatically (either :manual, :automatic or nil)



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

attribute :row, :type => Integer

#paymentsHash

Returns keys are the payment’s id, values are the payment state.

Returns:

  • (Hash)

    keys are the payment’s id, values are the payment state



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

attribute :row, :type => Integer

#rowFixnum

Returns part of the OSM API.

Returns:

  • (Fixnum)

    part of the OSM API



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

attribute :row, :type => Integer

Instance Method Details

#<=>(another) ⇒ Object

Compare Attendance based on event then row



729
730
731
732
733
# File 'lib/osm/event.rb', line 729

def <=>(another)
  result = self.event <=> another.try(:event)
  result = self.row <=> another.try(:row) if result == 0
  return result
end

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

Get audit trail

Parameters:

  • api (Osm::Api)

    The api to use to make the request

Returns:

  • (Array<Hash>)


650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
# File 'lib/osm/event.rb', line 650

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



735
736
737
# File 'lib/osm/event.rb', line 735

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

#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



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# File 'lib/osm/event.rb', line 586

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