Class: Osm::Member
Defined Under Namespace
Modules: EmailableContact, EnableableEmailableContact, EnableablePhoneableContact Classes: Contact, DoctorContact, EmergencyContact, MemberContact, PrimaryContact, SecondaryContact
Constant Summary collapse
- GID_PRIMARY_CONTACT =
Constants for group id
1
- GID_SECONDARY_CONTACT =
2
- GID_EMERGENCY_CONTACT =
3
- GID_DOCTOR_CONTACT =
4
- GID_CUSTOM =
5
- GID_MEMBER_CONTACT =
6
- GID_FLOATING =
7
- CID_FIRST_NAME =
Constants for column id
2
- CID_LAST_NAME =
3
- CID_ADDRESS_1 =
7
- CID_ADDRESS_2 =
8
- CID_ADDRESS_3 =
9
- CID_ADDRESS_4 =
10
- CID_POSTCODE =
11
- CID_EMAIL_1 =
12
- CID_RECIEVE_EMAIL_1 =
13
- CID_EMAIL_2 =
14
- CID_RECIEVE_EMAIL_2 =
15
- CID_PHONE_1 =
18
- CID_RECIEVE_PHONE_1 =
19
- CID_PHONE_2 =
20
- CID_RECIEVE_PHONE_2 =
21
- CID_GENDER =
34
- CID_SURGERY =
54
- CORE_FIELD_IDS =
(1..21).to_a + [34, 54]
Instance Attribute Summary collapse
-
#additional_information ⇒ DirtyHashy
The Additional Information (key is OSM’s variable name, value is the data).
-
#additional_information_labels ⇒ DirtyHashy
The labels for the additional information (key is OSM’s variable name, value is the label).
-
#age ⇒ String
The member’s current age (yy/mm).
-
#contact ⇒ Osm::Member::MemberContact?
The member’s contact details (nil if hidden in OSM).
-
#date_of_birth ⇒ Date
The member’s date of birth.
-
#doctor ⇒ Osm::Member::DoctorContact?
The member’s doctor (nil if hidden in OSM).
-
#emergency_contact ⇒ Osm::Member::EmergencyContact?
The member’s emergency contact (nil if hidden in OSM).
-
#finished_section ⇒ Date
When the member finished the section they were retrieved for.
-
#first_name ⇒ String
The member’s first name.
-
#gender ⇒ Symbol
The member’s gender (:male, :female, :other or :unspecified).
-
#grouping_id ⇒ Fixnum
The ID of the grouping within the section that the member belongs to.
-
#grouping_label ⇒ String
The name of the grouping within the section that the member belongs to.
-
#grouping_leader ⇒ Fixnum
Whether the member is the grouping leader (0=no, 1=seconder/APL, 2=sixer/PL, 3=senior PL).
-
#grouping_leader_label ⇒ String
Whether the member is the grouping leader.
-
#id ⇒ Fixnum
The id for the member.
-
#joined_movement ⇒ Date
When the member joined the movement.
-
#last_name ⇒ String
The member’s last name.
-
#primary_contact ⇒ Osm::Member::PrimaryContact?
The member’s primary contact (primary contact 1 in OSM) (nil if hidden in OSM).
-
#secondary_contact ⇒ Osm::Member::SecondaryContact?
The member’s secondary contact (primary contact 2 in OSM) (nil if hidden in OSM).
-
#section_id ⇒ Fixnum
The section the member belongs to.
-
#started_section ⇒ Date
When the member started the section they were retrieved for.
Class Method Summary collapse
-
.get_for_section(api, section, term = nil, options = {}) ⇒ Array<Osm::Member>
Get members for a section.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Compare member based on section_id, grouping_id, grouping_leader (descending), last_name then first_name.
-
#age_months ⇒ Fixnum
Get the months element of this scout’s age.
-
#age_years ⇒ Fixnum
Get the years element of this scout’s age.
-
#all_emails ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor).
-
#all_emails_with_name ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor).
-
#all_phones ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor).
-
#create(api) ⇒ Boolan?
Create the user in OSM.
-
#current?(date = Date.today) ⇒ Boolean
Check if this is a current member of the section they were retrieved for.
-
#enabled_emails ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor).
-
#enabled_emails_with_name ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor).
-
#enabled_phones ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor).
-
#female? ⇒ Boolean
Check if the member is male.
-
#get_photo(api, black_and_white = !current?,, options = {}) ⇒ Object
Get the member’s photo.
-
#initialize ⇒ Object
constructor
Initialize a new Member.
-
#leader? ⇒ Boolean
Check if the member is in the leaders grouping.
-
#male? ⇒ Boolean
Check if the member is male.
-
#myscout_link(api, link_to = :badges, item_id = nil) ⇒ String
Get the My.SCOUT link for this member.
-
#myscout_link_key(api) ⇒ String
Get the Key to use in My.SCOUT links for this member.
-
#name(seperator = ' ') ⇒ String
Get the full name.
-
#update(api, force = false) ⇒ Boolean
Update the member in OSM.
-
#youth? ⇒ Boolean
Check if the member is in a non-leaders grouping.
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Member
|
# File 'lib/osm/member.rb', line 295
|
Instance Attribute Details
#additional_information ⇒ DirtyHashy
Returns the Additional Information (key is OSM’s variable name, value is the data).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#additional_information_labels ⇒ DirtyHashy
Returns the labels for the additional information (key is OSM’s variable name, value is the label).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#age ⇒ String
Returns the member’s current age (yy/mm).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#contact ⇒ Osm::Member::MemberContact?
Returns the member’s contact details (nil if hidden in OSM).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#date_of_birth ⇒ Date
Returns the member’s date of birth.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#doctor ⇒ Osm::Member::DoctorContact?
Returns the member’s doctor (nil if hidden in OSM).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#emergency_contact ⇒ Osm::Member::EmergencyContact?
Returns the member’s emergency contact (nil if hidden in OSM).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#finished_section ⇒ Date
Returns when the member finished the section they were retrieved for.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#first_name ⇒ String
Returns the member’s first name.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#gender ⇒ Symbol
Returns the member’s gender (:male, :female, :other or :unspecified).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#grouping_id ⇒ Fixnum
Returns the ID of the grouping within the section that the member belongs to.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#grouping_label ⇒ String
Returns the name of the grouping within the section that the member belongs to.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#grouping_leader ⇒ Fixnum
Returns whether the member is the grouping leader (0=no, 1=seconder/APL, 2=sixer/PL, 3=senior PL).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#grouping_leader_label ⇒ String
Returns whether the member is the grouping leader.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#id ⇒ Fixnum
Returns the id for the member.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#joined_movement ⇒ Date
Returns when the member joined the movement.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#last_name ⇒ String
Returns the member’s last name.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#primary_contact ⇒ Osm::Member::PrimaryContact?
Returns the member’s primary contact (primary contact 1 in OSM) (nil if hidden in OSM).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#secondary_contact ⇒ Osm::Member::SecondaryContact?
Returns the member’s secondary contact (primary contact 2 in OSM) (nil if hidden in OSM).
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#section_id ⇒ Fixnum
Returns the section the member belongs to.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
#started_section ⇒ Date
Returns when the member started the section they were retrieved for.
77 |
# File 'lib/osm/member.rb', line 77 attribute :id, :type => Integer |
Class Method Details
.get_for_section(api, section, term = nil, options = {}) ⇒ Array<Osm::Member>
Get members for a section
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/osm/member.rb', line 139 def self.get_for_section(api, section, term=nil, ={}) require_ability_to(api, :read, :member, section, ) if term.nil? section = Osm::Section.get(api, section) if section.is_a?(Fixnum) term = section.waiting? ? -1 : Osm::Term.get_current_term_for_section(api, section) end cache_key = ['members', section.to_i, term.to_i] if ![:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end result = Array.new api_response = api.perform_query('ext/members/contact/grid/?action=getMembers', { 'section_id' => section.to_i, 'term_id' => term.to_i, }) data = api_response['data'].is_a?(Hash) ? api_response['data'].values : [] structure = (api_response['meta'] || {})['structure'] || [] structure = Hash[ structure.map{ |i| [i['group_id'].to_i, i ] } ] # Make a hash of identifier to group data hash custom_labels = {} key_key = 'column_id' # the key in the data from OSM to use as the key in additional_information and labels hashes structure.each do |gid, group| columns = group['columns'] || [] custom_labels[gid.to_i] = Hash[ columns.map.select{ |a| gid.eql?(GID_CUSTOM) || !CORE_FIELD_IDS.include?(a['column_id'].to_i) }.map{ |c| [c[key_key], c['label']] } ] end data.each do |item| item_data = Hash[ item['custom_data'].map{ |k,v| [k.to_i, v] } ] member_contact = item_data[GID_MEMBER_CONTACT].nil? ? nil : Hash[ item_data[GID_MEMBER_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |k,v| CORE_FIELD_IDS.include?(k) } ] member_custom = item_data[GID_MEMBER_CONTACT].nil? ? DirtyHashy.new : DirtyHashy[ item_data[GID_MEMBER_CONTACT].select{ |k,v| !CORE_FIELD_IDS.include?(k.to_i) }.map{ |k,v| [k.to_i, v] } ] primary_contact = item_data[GID_PRIMARY_CONTACT].nil? ? nil : Hash[ item_data[GID_PRIMARY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |k,v| CORE_FIELD_IDS.include?(k) } ] primary_custom = item_data[GID_PRIMARY_CONTACT].nil? ? DirtyHashy.new : DirtyHashy[ item_data[GID_PRIMARY_CONTACT].select{ |k,v| !CORE_FIELD_IDS.include?(k.to_i) }.map{ |k,v| [k.to_i, v] } ] secondary_contact = item_data[GID_SECONDARY_CONTACT].nil? ? nil : Hash[ item_data[GID_SECONDARY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |k,v| CORE_FIELD_IDS.include?(k) } ] secondary_custom = item_data[GID_SECONDARY_CONTACT].nil? ? DirtyHashy.new : DirtyHashy[ item_data[GID_SECONDARY_CONTACT].select{ |k,v| !CORE_FIELD_IDS.include?(k.to_i) }.map{ |k,v| [k.to_i, v] } ] emergency_contact = item_data[GID_EMERGENCY_CONTACT].nil? ? nil : Hash[ item_data[GID_EMERGENCY_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |k,v| CORE_FIELD_IDS.include?(k) } ] emergency_custom = item_data[GID_EMERGENCY_CONTACT].nil? ? DirtyHashy.new : DirtyHashy[ item_data[GID_EMERGENCY_CONTACT].select{ |k,v| !CORE_FIELD_IDS.include?(k.to_i) }.map{ |k,v| [k.to_i, v] } ] doctor_contact = item_data[GID_DOCTOR_CONTACT].nil? ? nil : Hash[ item_data[GID_DOCTOR_CONTACT].map{ |k,v| [k.to_i, v] }.select{ |k,v| CORE_FIELD_IDS.include?(k) } ] doctor_custom = item_data[GID_DOCTOR_CONTACT].nil? ? DirtyHashy.new : DirtyHashy[ item_data[GID_DOCTOR_CONTACT].select{ |k,v| !CORE_FIELD_IDS.include?(k.to_i) }.map{ |k,v| [k.to_i, v] } ] floating_data = item_data[GID_FLOATING].nil? ? {} : Hash[ item_data[GID_FLOATING].map{ |k,v| [k.to_i, v] }.select{ |k,v| CORE_FIELD_IDS.include?(k) } ] custom_data = item_data[GID_CUSTOM].nil? ? DirtyHashy.new : DirtyHashy[ item_data[GID_CUSTOM].map{ |k,v| [k.to_i, v] } ] result.push Osm::Member.new( :id => Osm::to_i_or_nil(item['member_id']), :section_id => Osm::to_i_or_nil(item['section_id']), :first_name => item['first_name'], :last_name => item['last_name'], :grouping_id => Osm::to_i_or_nil(item['patrol_id']), :grouping_label => item['patrol'], :grouping_leader => item['patrol_role_level'], :grouping_leader_label => item['patrol_role_level_label'], :age => item['age'], :date_of_birth => Osm::parse_date(item['date_of_birth'], :ignore_epoch => true), :started_section => Osm::parse_date(item['joined']), :finished_section => Osm::parse_date(item['end_date']), :joined_movement => Osm::parse_date(item['started']), :gender => {'male'=>:male, 'female'=>:female, 'other'=>:other, 'unspecified'=>:unspecified}[(floating_data[CID_GENDER] || '').downcase], :contact => member_contact.nil? ? nil : MemberContact.new( first_name: item['first_name'], last_name: item['last_name'], address_1: member_contact[CID_ADDRESS_1], address_2: member_contact[CID_ADDRESS_2], address_3: member_contact[CID_ADDRESS_3], address_4: member_contact[CID_ADDRESS_4], postcode: member_contact[CID_POSTCODE], phone_1: member_contact[CID_PHONE_1], phone_2: member_contact[CID_PHONE_2], email_1: member_contact[CID_EMAIL_1], email_2: member_contact[CID_EMAIL_2], receive_phone_1: member_contact[CID_RECIEVE_PHONE_1], receive_phone_2: member_contact[CID_RECIEVE_PHONE_2], receive_email_1: member_contact[CID_RECIEVE_EMAIL_1], receive_email_2: member_contact[CID_RECIEVE_EMAIL_2], additional_information: member_custom, additional_information_labels: custom_labels[GID_MEMBER_CONTACT], ), :primary_contact => primary_contact.nil? ? nil : PrimaryContact.new( first_name: primary_contact[CID_FIRST_NAME], last_name: primary_contact[CID_LAST_NAME], address_1: primary_contact[CID_ADDRESS_1], address_2: primary_contact[CID_ADDRESS_2], address_3: primary_contact[CID_ADDRESS_3], address_4: primary_contact[CID_ADDRESS_4], postcode: primary_contact[CID_POSTCODE], phone_1: primary_contact[CID_PHONE_1], phone_2: primary_contact[CID_PHONE_2], email_1: primary_contact[CID_EMAIL_1], email_2: primary_contact[CID_EMAIL_2], receive_phone_1: primary_contact[CID_RECIEVE_PHONE_1], receive_phone_2: primary_contact[CID_RECIEVE_PHONE_2], receive_email_1: primary_contact[CID_RECIEVE_EMAIL_1], receive_email_2: primary_contact[CID_RECIEVE_EMAIL_2], additional_information: primary_custom, additional_information_labels: custom_labels[GID_PRIMARY_CONTACT], ), :secondary_contact => secondary_contact.nil? ? nil : SecondaryContact.new( first_name: secondary_contact[CID_FIRST_NAME], last_name: secondary_contact[CID_LAST_NAME], address_1: secondary_contact[CID_ADDRESS_1], address_2: secondary_contact[CID_ADDRESS_2], address_3: secondary_contact[CID_ADDRESS_3], address_4: secondary_contact[CID_ADDRESS_4], postcode: secondary_contact[CID_POSTCODE], phone_1: secondary_contact[CID_PHONE_1], phone_2: secondary_contact[CID_PHONE_2], email_1: secondary_contact[CID_EMAIL_1], email_2: secondary_contact[CID_EMAIL_2], receive_phone_1: secondary_contact[CID_RECIEVE_PHONE_1], receive_phone_2: secondary_contact[CID_RECIEVE_PHONE_2], receive_email_1: secondary_contact[CID_RECIEVE_EMAIL_1], receive_email_2: secondary_contact[CID_RECIEVE_EMAIL_2], additional_information: secondary_custom, additional_information_labels: custom_labels[GID_SECONDARY_CONTACT], ), :emergency_contact => emergency_contact.nil? ? nil : EmergencyContact.new( first_name: emergency_contact[CID_FIRST_NAME], last_name: emergency_contact[CID_LAST_NAME], address_1: emergency_contact[CID_ADDRESS_1], address_2: emergency_contact[CID_ADDRESS_2], address_3: emergency_contact[CID_ADDRESS_3], address_4: emergency_contact[CID_ADDRESS_4], postcode: emergency_contact[CID_POSTCODE], phone_1: emergency_contact[CID_PHONE_1], phone_2: emergency_contact[CID_PHONE_2], email_1: emergency_contact[CID_EMAIL_1], email_2: emergency_contact[CID_EMAIL_2], additional_information: emergency_custom, additional_information_labels: custom_labels[GID_EMERGENCY_CONTACT], ), :doctor => doctor_contact.nil? ? nil : DoctorContact.new( first_name: doctor_contact[CID_FIRST_NAME], last_name: doctor_contact[CID_LAST_NAME], surgery: doctor_contact[CID_SURGERY], address_1: doctor_contact[CID_ADDRESS_1], address_2: doctor_contact[CID_ADDRESS_2], address_3: doctor_contact[CID_ADDRESS_3], address_4: doctor_contact[CID_ADDRESS_4], postcode: doctor_contact[CID_POSTCODE], phone_1: doctor_contact[CID_PHONE_1], phone_2: doctor_contact[CID_PHONE_2], additional_information: doctor_custom, additional_information_labels: custom_labels[GID_DOCTOR_CONTACT], ), additional_information: custom_data, additional_information_labels: custom_labels[GID_CUSTOM], ) end cache_write(api, cache_key, result) return result end |
Instance Method Details
#<=>(another) ⇒ Object
Compare member based on section_id, grouping_id, grouping_leader (descending), last_name then first_name
556 557 558 559 560 561 562 563 |
# File 'lib/osm/member.rb', line 556 def <=>(another) result = self.section_id <=> another.try(:section_id) result = self.grouping_id <=> another.try(:grouping_id) if result == 0 result = -(self.grouping_leader <=> another.try(:grouping_leader)) if result == 0 result = self.last_name <=> another.try(:last_name) if result == 0 result = self.first_name <=> another.try(:first_name) if result == 0 return result end |
#age_months ⇒ Fixnum
Get the months element of this scout’s age
419 420 421 |
# File 'lib/osm/member.rb', line 419 def age_months return age[-2..-1].to_i end |
#age_years ⇒ Fixnum
Get the years element of this scout’s age
413 414 415 |
# File 'lib/osm/member.rb', line 413 def age_years return age[0..1].to_i end |
#all_emails ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor)
483 484 485 486 487 488 489 490 491 |
# File 'lib/osm/member.rb', line 483 [:all_emails, :all_emails_with_name, :enabled_emails, :enabled_emails_with_name, :all_phones, :enabled_phones].each do |meth| define_method meth do items = [] [:contact, :primary_contact, :secondary_contact].each do |cont| items.push *send(cont).send(meth) end return items end end |
#all_emails_with_name ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor)
483 484 485 486 487 488 489 490 491 |
# File 'lib/osm/member.rb', line 483 [:all_emails, :all_emails_with_name, :enabled_emails, :enabled_emails_with_name, :all_phones, :enabled_phones].each do |meth| define_method meth do items = [] [:contact, :primary_contact, :secondary_contact].each do |cont| items.push *send(cont).send(meth) end return items end end |
#all_phones ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor)
483 484 485 486 487 488 489 490 491 |
# File 'lib/osm/member.rb', line 483 [:all_emails, :all_emails_with_name, :enabled_emails, :enabled_emails_with_name, :all_phones, :enabled_phones].each do |meth| define_method meth do items = [] [:contact, :primary_contact, :secondary_contact].each do |cont| items.push *send(cont).send(meth) end return items end end |
#create(api) ⇒ Boolan?
Create the user in OSM
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/osm/member.rb', line 305 def create(api) raise Osm::Error, 'the member already exists in OSM' unless id.nil? raise Osm::ObjectIsInvalid, 'member is invalid' unless valid? require_ability_to(api, :write, :member, section_id) data = api.perform_query("users.php?action=newMember", { 'firstname' => first_name, 'lastname' => last_name, 'dob' => date_of_birth.strftime(Osm::OSM_DATE_FORMAT), 'started' => joined_movement.strftime(Osm::OSM_DATE_FORMAT), 'startedsection' => started_section.strftime(Osm::OSM_DATE_FORMAT), 'sectionid' => section_id, }) if (data.is_a?(Hash) && (data['result'] == 'ok') && (data['scoutid'].to_i > 0)) self.id = data['scoutid'].to_i # The cached members for the section will be out of date - remove them Osm::Term.get_for_section(api, section_id).each do |term| cache_delete(api, ['members', section_id, term.id]) end # Now it's created we need to give OSM the rest of the data updated = update(api, true) return updated ? true : nil else return false end end |
#current?(date = Date.today) ⇒ Boolean
Check if this is a current member of the section they were retrieved for
457 458 459 460 461 462 463 |
# File 'lib/osm/member.rb', line 457 def current?(date=Date.today) if finished_section.nil? return (started_section <= date) else return (started_section <= date) && (finished_section >= date) end end |
#enabled_emails ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor)
483 484 485 486 487 488 489 490 491 |
# File 'lib/osm/member.rb', line 483 [:all_emails, :all_emails_with_name, :enabled_emails, :enabled_emails_with_name, :all_phones, :enabled_phones].each do |meth| define_method meth do items = [] [:contact, :primary_contact, :secondary_contact].each do |cont| items.push *send(cont).send(meth) end return items end end |
#enabled_emails_with_name ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor)
483 484 485 486 487 488 489 490 491 |
# File 'lib/osm/member.rb', line 483 [:all_emails, :all_emails_with_name, :enabled_emails, :enabled_emails_with_name, :all_phones, :enabled_phones].each do |meth| define_method meth do items = [] [:contact, :primary_contact, :secondary_contact].each do |cont| items.push *send(cont).send(meth) end return items end end |
#enabled_phones ⇒ Array<String>
Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all email addresses from all contacts for the member (not emergency or doctor) Get an array of all email addresses from all contacts for the member in a format which includes the contact’s name (not emergency or doctor) Get an array of all phone numbers from all contacts for the member (not emergency or doctor) Get an array of enabled phone numbers from all contacts for the member (not emergency or doctor)
483 484 485 486 487 488 489 490 491 |
# File 'lib/osm/member.rb', line 483 [:all_emails, :all_emails_with_name, :enabled_emails, :enabled_emails_with_name, :all_phones, :enabled_phones].each do |meth| define_method meth do items = [] [:contact, :primary_contact, :secondary_contact].each do |cont| items.push *send(cont).send(meth) end return items end end |
#female? ⇒ Boolean
Check if the member is male
450 451 452 |
# File 'lib/osm/member.rb', line 450 def female? gender == :female end |
#get_photo(api, black_and_white = !current?,, options = {}) ⇒ Object
Get the member’s photo
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
# File 'lib/osm/member.rb', line 518 def get_photo(api, black_and_white=!current?, ={}) raise Osm::ObjectIsInvalid, 'member is invalid' unless valid? require_ability_to(api, :read, :member, section_id) raise Osm::Error, 'the member does not already exist in OSM' if id.nil? cache_key = ['member_photo', self.id, black_and_white] if ![:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end url = "ext/members/contact/images/member.php?sectionid=#{section_id}&scoutid=#{self.id}&bw=#{black_and_white}" image = api.perform_query(url) cache_write(api, cache_key, image) unless image.nil? return image end |
#leader? ⇒ Boolean
Check if the member is in the leaders grouping
432 433 434 |
# File 'lib/osm/member.rb', line 432 def leader? grouping_id.eql?(-2) end |
#male? ⇒ Boolean
Check if the member is male
444 445 446 |
# File 'lib/osm/member.rb', line 444 def male? gender == :male end |
#myscout_link(api, link_to = :badges, item_id = nil) ⇒ String
Get the My.SCOUT link for this member
544 545 546 547 548 549 550 551 552 553 |
# File 'lib/osm/member.rb', line 544 def myscout_link(api, link_to=:badges, item_id=nil) raise Osm::ObjectIsInvalid, 'member is invalid' unless valid? require_ability_to(api, :read, :member, section_id) raise Osm::Error, 'the member does not already exist in OSM' if id.nil? raise Osm::ArgumentIsInvalid, 'link_to is invalid' unless [:payments, :events, :programme, :badges, :notice, :details, :census, :giftaid].include?(link_to) link = "#{api.base_url}/parents/#{link_to}.php?sc=#{self.id}&se=#{section_id}&c=#{myscout_link_key(api)}" link += "&e=#{item_id.to_i}" if item_id && link_to.eql?(:events) return link end |
#myscout_link_key(api) ⇒ String
Get the Key to use in My.SCOUT links for this member
498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/osm/member.rb', line 498 def myscout_link_key(api) raise Osm::ObjectIsInvalid, 'member is invalid' unless valid? require_ability_to(api, :read, :member, section_id) raise Osm::Error, 'the member does not already exist in OSM' if id.nil? if @myscout_link_key.nil? data = api.perform_query("api.php?action=getMyScoutKey§ionid=#{section_id}&scoutid=#{self.id}") raise Osm::Error, 'Could not retrieve the key for the link from OSM' unless data['ok'] @myscout_link_key = data['key'] end return @myscout_link_key end |
#name(seperator = ' ') ⇒ String
Get the full name
426 427 428 |
# File 'lib/osm/member.rb', line 426 def name(seperator=' ') return [first_name, last_name].select{ |i| !i.blank? }.join(seperator) end |
#update(api, force = false) ⇒ Boolean
Update the member in OSM
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/osm/member.rb', line 338 def update(api, force=false) raise Osm::ObjectIsInvalid, 'member is invalid' unless valid? require_ability_to(api, :write, :member, section_id) updated = true # Do core attributes attribute_map = [ ['first_name', 'firstname', first_name], ['last_name', 'lastname', last_name], ['grouping_id', 'patrolid', grouping_id], ['grouping_leader', 'patrolleader', grouping_leader], ['date_of_birth', 'dob', date_of_birth.strftime(Osm::OSM_DATE_FORMAT)], ['started_section', 'startedsection', started_section.strftime(Osm::OSM_DATE_FORMAT)], ['joined_movement', 'started', joined_movement.strftime(Osm::OSM_DATE_FORMAT)], ] # our name => OSM name attribute_map.select{ |attr,col,val| force || changed_attributes.include?(attr) }.each do |attr,col,val| data = api.perform_query("ext/members/contact/?action=update", { 'scoutid' => self.id, 'column' => col, 'value' => val, 'sectionid' => section_id, }) updated = updated && data.is_a?(Hash) && data['ok'].eql?(true) end # each attr to update # Do 'floating' attributes if force || changed_attributes.include?('gender') new_value = {male: 'Male', female: 'Female', other: 'Other'}[gender] || 'Unspecified' data = api.perform_query("ext/customdata/?action=updateColumn§ion_id=#{section_id}", { 'associated_id' => self.id, 'associated_type' => 'member', 'value' => new_value, 'column_id' => CID_GENDER, 'group_id' => GID_FLOATING, 'context' => 'members', }) updated = updated && data.is_a?(Hash) && data['data'].is_a?(Hash) && data['data']['value'].eql?(new_value) end # Do custom attributes additional_information.keys.select{ |a| force || additional_information.changes.keys.include?(a) }.each do |attr| new_value = additional_information[attr] data = api.perform_query("ext/customdata/?action=updateColumn§ion_id=#{section_id}", { 'associated_id' => self.id, 'associated_type' => 'member', 'value' => new_value, 'column_id' => attr, 'group_id' => GID_CUSTOM, 'context' => 'members', }) updated = updated && data.is_a?(Hash) && data['data'].is_a?(Hash) && data['data']['value'].eql?(new_value) end # each attr to update # Do contacts updated = (contact.nil? || contact.update(api, self, force)) && updated updated = (primary_contact.nil? || primary_contact.update(api, self, force)) && updated updated = (secondary_contact.nil? || secondary_contact.update(api, self, force)) && updated updated = (emergency_contact.nil? ||emergency_contact.update(api, self, force)) && updated updated = (doctor.nil? || doctor.update(api, self, force)) && updated # Finish off if updated reset_changed_attributes additional_information.clean_up! # The cached columns for the members will be out of date - remove them Osm::Term.get_for_section(api, section_id).each do |term| Osm::Model.cache_delete(api, ['members', section_id, term.id]) end end return updated end |
#youth? ⇒ Boolean
Check if the member is in a non-leaders grouping
438 439 440 |
# File 'lib/osm/member.rb', line 438 def youth? grouping_id > 0 end |