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 or nil).

Returns:

  • (Symbol)

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



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

attribute :row, :type => Integer

#date_of_birthDate

Returns the member’s date of birth.

Returns:

  • (Date)

    the member’s date of birth



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

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



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

attribute :row, :type => Integer

#first_nameString

Returns the member’s first name.

Returns:

  • (String)

    the member’s first name



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

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



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

attribute :row, :type => Integer

#last_nameString

Returns the member’s last name.

Returns:

  • (String)

    the member’s last name



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

attribute :row, :type => Integer

#member_idFixnum

Returns OSM id for the member.

Returns:

  • (Fixnum)

    OSM id for the member



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

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)



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

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



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

attribute :row, :type => Integer

#rowFixnum

Returns part of the OSM API.

Returns:

  • (Fixnum)

    part of the OSM API



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

attribute :row, :type => Integer

Instance Method Details

#<=>(another) ⇒ Object

Compare Attendance based on event then row



656
657
658
659
660
# File 'lib/osm/event.rb', line 656

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

#inspectObject



662
663
664
# File 'lib/osm/event.rb', line 662

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



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
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
# File 'lib/osm/event.rb', line 566

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',
  }

  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