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).
-
#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.
-
#initialize ⇒ Object
constructor
Initialize a new Member.
-
#myscout_link(api, link_to = :badges) ⇒ String
Get the My.SCOUT link for this member.
-
#name(seperator = ' ') ⇒ String
Get the full name.
-
#update(api) ⇒ Boolan
Update the member in OSM.
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 213
|
Instance Attribute Details
#address ⇒ String
Returns the member’s address.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#address2 ⇒ String
Returns the member’s 2nd address.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#age ⇒ String
Returns the member’s current age (yy/mm).
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom1 ⇒ String
Returns the custom1 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom2 ⇒ String
Returns the custom2 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom3 ⇒ String
Returns the custom3 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom4 ⇒ String
Returns the custom4 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom5 ⇒ String
Returns the custom5 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom6 ⇒ String
Returns the custom6 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom7 ⇒ String
Returns the custom7 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom8 ⇒ String
Returns the custom8 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#custom9 ⇒ String
Returns the custom9 data for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#date_of_birth ⇒ Date
Returns the member’s date of birth.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#email1 ⇒ String
Returns the 1st email address for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#email2 ⇒ String
Returns the 2nd email address for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#email3 ⇒ String
Returns the 3rd email address for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#email4 ⇒ String
Returns the 4th email address for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#ethnicity ⇒ String
Returns the member’s ethnicity.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#first_name ⇒ String
Returns the member’s first name.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#grouping_id ⇒ Fixnum
Returns the grouping within the section that the member belongs to.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#grouping_leader ⇒ Fixnum
Returns whether the member is the grouping leader (0=no, 1=seconder/APL, 2=sixer/PL).
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#id ⇒ Fixnum
Returns the id for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#joined ⇒ Date
Returns when the member joined the section.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#joined_years ⇒ Fixnum
Returns how many years the member has been in Scouting.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#joining_in_years ⇒ Fixnum
Returns ?.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#last_name ⇒ String
Returns the member’s last name.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#medical ⇒ String
Returns the member’s key medical details.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#notes ⇒ String
Returns notes relating to the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#parents ⇒ String
Returns the member’s parent’s names.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#phone1 ⇒ String
Returns the 1st phone number for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#phone2 ⇒ String
Returns the 2nd phone number for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#phone3 ⇒ String
Returns the 3rd phone number for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#phone4 ⇒ String
Returns the 4th phone number for the member.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#religion ⇒ String
Returns the member’s religion.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#school ⇒ String
Returns the school the member attends.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#section_id ⇒ Fixnum
Returns the section the member belongs to.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#started ⇒ Date
Returns when the member started Scouting.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#subs ⇒ String
Returns details about the member’s subs.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
#type ⇒ String
Returns ?.
84 |
# File 'lib/osm/member.rb', line 84 attribute :id, :type => Integer |
Class Method Details
.get_for_section(api, section, term = nil, options = {}) ⇒ Array<Osm::Member>
Get members for a section
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 |
# File 'lib/osm/member.rb', line 150 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}") result = Array.new data['items'].each do |item| result.push Osm::Member.new( :section_id => section.id, :id => Osm::to_i_or_nil(item['scoutid']), :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, ) 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
393 394 395 396 397 398 399 400 |
# File 'lib/osm/member.rb', line 393 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(:last_name) if result == 0 return result end |
#age_months ⇒ Fixnum
Get the months element of this scout’s age
359 360 361 |
# File 'lib/osm/member.rb', line 359 def age_months return age[-2..-1].to_i end |
#age_years ⇒ Fixnum
Get the years element of this scout’s age
353 354 355 |
# File 'lib/osm/member.rb', line 353 def age_years return age[0..1].to_i end |
#create(api) ⇒ Boolan
Create the user in OSM
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 |
# File 'lib/osm/member.rb', line 223 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 |
#myscout_link(api, link_to = :badges) ⇒ String
Get the My.SCOUT link for this member
377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/osm/member.rb', line 377 def myscout_link(api, link_to=:badges) 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].include?(link_to) 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 "https://www.onlinescoutmanager.co.uk/parents/#{link_to}.php?sc=#{self.id}&se=#{section_id}&c=#{@myscout_link_key}" end |
#name(seperator = ' ') ⇒ String
Get the full name
366 367 368 |
# File 'lib/osm/member.rb', line 366 def name(seperator=' ') return "#{first_name}#{seperator.to_s}#{last_name}" end |
#update(api) ⇒ Boolan
Update the member in OSM
281 282 283 284 285 286 287 288 289 290 291 292 293 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 |
# File 'lib/osm/member.rb', line 281 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 |