Class: Osm::Member
Instance Attribute Summary collapse
-
#address ⇒ String
The member’s address.
-
#address2 ⇒ String
The member’s 2nd address.
-
#age ⇒ String
The member’s current age (yy/mm).
-
#custom1 ⇒ String
The custom1 data for the member.
-
#custom2 ⇒ String
The custom2 data for the member.
-
#custom3 ⇒ String
The custom3 data for the member.
-
#custom4 ⇒ String
The custom4 data for the member.
-
#custom5 ⇒ String
The custom5 data for the member.
-
#custom6 ⇒ String
The custom6 data for the member.
-
#custom7 ⇒ String
The custom7 data for the member.
-
#custom8 ⇒ String
The custom8 data for the member.
-
#custom9 ⇒ String
The custom9 data for the member.
-
#date_of_birth ⇒ Date
The member’s date of birth.
-
#email1 ⇒ String
The 1st email address for the member.
-
#email2 ⇒ String
The 2nd email address for the member.
-
#email3 ⇒ String
The 3rd email address for the member.
-
#email4 ⇒ String
The 4th email address for the member.
-
#ethnicity ⇒ String
The member’s ethnicity.
-
#first_name ⇒ String
The member’s first name.
-
#grouping_id ⇒ Fixnum
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).
-
#has_photo ⇒ Boolean
Whether the scout has a photo in OSM.
-
#id ⇒ Fixnum
The id for the member.
-
#joined ⇒ Date
When the member joined the section.
-
#joined_years ⇒ Fixnum
How many years the member has been in Scouting.
-
#joining_in_years ⇒ Fixnum
?.
-
#last_name ⇒ String
The member’s last name.
-
#medical ⇒ String
The member’s key medical details.
-
#notes ⇒ String
Notes relating to the member.
-
#parents ⇒ String
The member’s parent’s names.
-
#phone1 ⇒ String
The 1st phone number for the member.
-
#phone2 ⇒ String
The 2nd phone number for the member.
-
#phone3 ⇒ String
The 3rd phone number for the member.
-
#phone4 ⇒ String
The 4th phone number for the member.
-
#religion ⇒ String
The member’s religion.
-
#school ⇒ String
The school the member attends.
-
#section_id ⇒ Fixnum
The section the member belongs to.
-
#started ⇒ Date
When the member started Scouting.
-
#subs ⇒ String
Details about the member’s subs.
-
#type ⇒ String
?.
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 Activity 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.
-
#create(api) ⇒ Boolan
Create the user in OSM.
-
#get_photo(api, black_and_white = false, 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.
-
#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) ⇒ Boolan
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 226
|
Instance Attribute Details
#address ⇒ String
Returns the member’s address.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#address2 ⇒ String
Returns the member’s 2nd address.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#age ⇒ String
Returns the member’s current age (yy/mm).
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom1 ⇒ String
Returns the custom1 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom2 ⇒ String
Returns the custom2 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom3 ⇒ String
Returns the custom3 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom4 ⇒ String
Returns the custom4 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom5 ⇒ String
Returns the custom5 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom6 ⇒ String
Returns the custom6 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom7 ⇒ String
Returns the custom7 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom8 ⇒ String
Returns the custom8 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#custom9 ⇒ String
Returns the custom9 data for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#date_of_birth ⇒ Date
Returns the member’s date of birth.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#email1 ⇒ String
Returns the 1st email address for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#email2 ⇒ String
Returns the 2nd email address for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#email3 ⇒ String
Returns the 3rd email address for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#email4 ⇒ String
Returns the 4th email address for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#ethnicity ⇒ String
Returns the member’s ethnicity.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#first_name ⇒ String
Returns the member’s first name.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#grouping_id ⇒ Fixnum
Returns the grouping within the section that the member belongs to.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#grouping_leader ⇒ Fixnum
Returns whether the member is the grouping leader (0=no, 1=seconder/APL, 2=sixer/PL).
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#has_photo ⇒ Boolean
Returns whether the scout has a photo in OSM.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#id ⇒ Fixnum
Returns the id for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#joined ⇒ Date
Returns when the member joined the section.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#joined_years ⇒ Fixnum
Returns how many years the member has been in Scouting.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#joining_in_years ⇒ Fixnum
Returns ?.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#last_name ⇒ String
Returns the member’s last name.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#medical ⇒ String
Returns the member’s key medical details.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#notes ⇒ String
Returns notes relating to the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#parents ⇒ String
Returns the member’s parent’s names.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#phone1 ⇒ String
Returns the 1st phone number for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#phone2 ⇒ String
Returns the 2nd phone number for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#phone3 ⇒ String
Returns the 3rd phone number for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#phone4 ⇒ String
Returns the 4th phone number for the member.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#religion ⇒ String
Returns the member’s religion.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#school ⇒ String
Returns the school the member attends.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#section_id ⇒ Fixnum
Returns the section the member belongs to.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#started ⇒ Date
Returns when the member started Scouting.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#subs ⇒ String
Returns details about the member’s subs.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
#type ⇒ String
Returns ?.
86 |
# File 'lib/osm/member.rb', line 86 attribute :id, :type => Integer |
Class Method Details
.get_for_section(api, section, term = nil, options = {}) ⇒ Array<Osm::Member>
Get members for a section
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 |
# File 'lib/osm/member.rb', line 157 def self.get_for_section(api, section, term=nil, ={}) require_ability_to(api, :read, :member, section, ) section = Osm::Section.get(api, section) if section.is_a?(Fixnum) term = -1 if section.waiting? term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i cache_key = ['members', section.id, term_id] if ![:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end data = api.perform_query("users.php?action=getUserDetails§ionid=#{section.id}&termid=#{term_id}") summary_data = api.perform_query("ext/members/contact/?action=getListOfMembers&sort=patrolid§ionid=#{section.id}&termid=#{term_id}§ion=#{section.type}") || {} summary_data = summary_data['items'] || [] summary_data = Hash[summary_data.map { |i| [i['scoutid'].to_i, i] }] result = Array.new data['items'].each do |item| id = Osm::to_i_or_nil(item['scoutid']) result.push Osm::Member.new( :section_id => section.id, :id => id, :type => item['type'], :first_name => item['firstname'], :last_name => item['lastname'], :email1 => item['email1'], :email2 => item['email2'], :email3 => item['email3'], :email4 => item['email4'], :phone1 => item['phone1'], :phone2 => item['phone2'], :phone3 => item['phone3'], :phone4 => item['phone4'], :address => item['address'], :address2 => item['address2'], :date_of_birth => Osm::parse_date(item['dob'], :ignore_epoch => true), :started => Osm::parse_date(item['started']), :joining_in_years => item['joining_in_yrs'].to_i, :parents => item['parents'], :notes => item['notes'], :medical => item['medical'], :religion => item['religion'], :school => item['school'], :ethnicity => item['ethnicity'], :subs => item['subs'], :custom1 => item['custom1'], :custom2 => item['custom2'], :custom3 => item['custom3'], :custom4 => item['custom4'], :custom5 => item['custom5'], :custom6 => item['custom6'], :custom7 => item['custom7'], :custom8 => item['custom8'], :custom9 => item['custom9'], :grouping_id => Osm::to_i_or_nil(item['patrolid']), :grouping_leader => Osm::to_i_or_nil(item['patrolleader']), :joined => Osm::parse_date(item['joined']), :age => item['age'].gsub(' ', ''), :joined_years => item['yrs'].to_i, :has_photo => summary_data[id]['pic'] ) end cache_write(api, cache_key, result) return result end |
Instance Method Details
#<=>(another) ⇒ Object
Compare Activity based on section_id, grouping_id, grouping_leader (descending), last_name then first_name
459 460 461 462 463 464 465 466 |
# File 'lib/osm/member.rb', line 459 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
372 373 374 |
# File 'lib/osm/member.rb', line 372 def age_months return age[-2..-1].to_i end |
#age_years ⇒ Fixnum
Get the years element of this scout’s age
366 367 368 |
# File 'lib/osm/member.rb', line 366 def age_years return age[0..1].to_i end |
#create(api) ⇒ Boolan
Create the user in OSM
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 |
# File 'lib/osm/member.rb', line 236 def create(api) raise Osm::ObjectIsInvalid, 'member is invalid' unless valid? require_ability_to(api, :write, :member, section_id) raise Osm::Error, 'the member already exists in OSM' unless id.nil? data = api.perform_query("users.php?action=newMember", { 'firstname' => first_name, 'lastname' => last_name, 'dob' => date_of_birth.strftime(Osm::OSM_DATE_FORMAT), 'started' => started.strftime(Osm::OSM_DATE_FORMAT), 'startedsection' => joined.strftime(Osm::OSM_DATE_FORMAT), 'patrolid' => grouping_id, 'patrolleader' => grouping_leader, 'sectionid' => section_id, 'email1' => email1, 'email2' => email2, 'email3' => email3, 'email4' => email4, 'phone1' => phone1, 'phone2' => phone2, 'phone3' => phone3, 'phone4' => phone4, 'address' => address, 'address2' => address2, 'parents' => parents, 'notes' => notes, 'medical' => medical, 'religion' => religion, 'school' => school, 'ethnicity' => ethnicity, 'subs' => subs, 'custom1' => custom1, 'custom2' => custom2, 'custom3' => custom3, 'custom4' => custom4, 'custom5' => custom5, 'custom6' => custom6, 'custom7' => custom7, 'custom8' => custom8, 'custom9' => custom9, }) 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 return true else return false end end |
#get_photo(api, black_and_white = false, options = {}) ⇒ Object
Get the member’s photo
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/osm/member.rb', line 420 def get_photo(api, black_and_white=false, ={}) 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::Error, "the member doesn't have a photo in OSM" unless has_photo 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
385 386 387 |
# File 'lib/osm/member.rb', line 385 def leader? grouping_id.eql?(-2) end |
#myscout_link(api, link_to = :badges, item_id = nil) ⇒ String
Get the My.SCOUT link for this member
447 448 449 450 451 452 453 454 455 456 |
# File 'lib/osm/member.rb', line 447 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
400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/osm/member.rb', line 400 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
379 380 381 |
# File 'lib/osm/member.rb', line 379 def name(seperator=' ') return "#{first_name}#{seperator.to_s}#{last_name}" end |
#update(api) ⇒ Boolan
Update the member in OSM
294 295 296 297 298 299 300 301 302 303 304 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 332 333 334 335 336 337 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 |
# File 'lib/osm/member.rb', line 294 def update(api) raise Osm::ObjectIsInvalid, 'member is invalid' unless valid? require_ability_to(api, :write, :member, section_id) to_update = changed_attributes values = {} values['firstname'] = first_name if to_update.include?('first_name') values['lastname'] = last_name if to_update.include?('last_name') values['dob'] = date_of_birth.strftime(Osm::OSM_DATE_FORMAT) if to_update.include?('date_of_birth') values['started'] = started.strftime(Osm::OSM_DATE_FORMAT) if to_update.include?('started') values['startedsection'] = joined.strftime(Osm::OSM_DATE_FORMAT) if to_update.include?('joined') values['email1'] = email1 if to_update.include?('email1') values['email2'] = email2 if to_update.include?('email2') values['email3'] = email3 if to_update.include?('email3') values['email4'] = email4 if to_update.include?('email4') values['phone1'] = phone1 if to_update.include?('phone1') values['phone2'] = phone2 if to_update.include?('phone2') values['phone3'] = phone3 if to_update.include?('phone3') values['phone4'] = phone4 if to_update.include?('phone3') values['address'] = address if to_update.include?('address') values['address2'] = address2 if to_update.include?('address2') values['parents'] = parents if to_update.include?('parents') values['notes'] = notes if to_update.include?('notes') values['medical'] = medical if to_update.include?('medical') values['religion'] = religion if to_update.include?('religion') values['school'] = school if to_update.include?('school') values['ethnicity'] = ethnicity if to_update.include?('ethnicity') values['subs'] = subs if to_update.include?('subs') values['custom1'] = custom1 if to_update.include?('custom1') values['custom2'] = custom2 if to_update.include?('custom2') values['custom3'] = custom3 if to_update.include?('custom3') values['custom4'] = custom4 if to_update.include?('custom4') values['custom5'] = custom5 if to_update.include?('custom5') values['custom6'] = custom6 if to_update.include?('custom6') values['custom7'] = custom7 if to_update.include?('custom7') values['custom8'] = custom8 if to_update.include?('custom8') values['custom9'] = custom9 if to_update.include?('custom9') result = true values.each do |column, value| data = api.perform_query("users.php?action=updateMember&dateFormat=generic", { 'scoutid' => self.id, 'column' => column, 'value' => value, 'sectionid' => section_id, }) result &= (data[column] == value.to_s) end if to_update.include?('grouping_id') || to_update.include?('grouping_leader') data = api.perform_query("users.php?action=updateMemberPatrol", { 'scoutid' => self.id, 'patrolid' => grouping_id, 'pl' => grouping_leader, 'sectionid' => section_id, }) result &= ((data['patrolid'].to_i == grouping_id) && (data['patrolleader'].to_i == grouping_leader)) end if result reset_changed_attributes # The cached columns for the flexi record 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 result end |
#youth? ⇒ Boolean
Check if the member is in a non-leaders grouping
391 392 393 |
# File 'lib/osm/member.rb', line 391 def youth? grouping_id > 0 end |