Class: Osm::Meeting
Defined Under Namespace
Instance Attribute Summary collapse
-
#activities ⇒ Array<Activity>
List of activities being done during the meeting.
-
#badge_links ⇒ Array<BadgeLink>
List of badge links added to the meeting.
-
#date ⇒ Date
The date of the meeting.
-
#finish_time ⇒ String
The end time (hh:mm).
-
#games ⇒ String
Games to be played during the meeting.
-
#id ⇒ Fixnum
The id of the meeting.
-
#leaders ⇒ String
The leaders present at the meeting.
-
#notes_for_parents ⇒ String
Notes to be shared with parents.
-
#post_notes ⇒ String
Notes for the end of the meeting.
-
#pre_notes ⇒ String
Notes for the start of the meeting.
-
#section_id ⇒ Fixnum
The section the meeting belongs to.
-
#start_time ⇒ String
The start time (hh:mm).
-
#title ⇒ String
The title of the meeting.
Class Method Summary collapse
-
.create(api, parameters) ⇒ Osm::Meeting?
Create a meeting in OSM.
-
.get_for_section(api, section, term = nil, options = {}) ⇒ Array<Osm::Meeting>
Get the programme for a given term.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Compare Meeting based on section_id, date, start_time then id.
-
#add_activity(api, activity, notes = '') ⇒ Boolean
Add an activity to this meeting in OSM.
-
#delete(api) ⇒ Boolean
Delete meeting from OSM.
-
#get_badge_requirements(api, options = {}) ⇒ Array<Hash>?
Get the badge requirements met on a specific meeting Requires either write permission to badges (prefered as it’s one OSM query) or read permission to programme.
-
#initialize ⇒ Object
constructor
Initialize a new Meeting.
-
#update(api) ⇒ Boolean
Update an meeting in OSM.
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Meeting
|
# File 'lib/osm/meeting.rb', line 61
|
Instance Attribute Details
#activities ⇒ Array<Activity>
Returns list of activities being done during the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#badge_links ⇒ Array<BadgeLink>
Returns list of badge links added to the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#date ⇒ Date
Returns the date of the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#finish_time ⇒ String
Returns the end time (hh:mm).
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#games ⇒ String
Returns games to be played during the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#id ⇒ Fixnum
Returns the id of the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#leaders ⇒ String
Returns the leaders present at the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#notes_for_parents ⇒ String
Returns notes to be shared with parents.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#post_notes ⇒ String
Returns notes for the end of the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#pre_notes ⇒ String
Returns notes for the start of the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#section_id ⇒ Fixnum
Returns the section the meeting belongs to.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#start_time ⇒ String
Returns the start time (hh:mm).
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
#title ⇒ String
Returns the title of the meeting.
34 |
# File 'lib/osm/meeting.rb', line 34 attribute :id, :type => Integer |
Class Method Details
.create(api, parameters) ⇒ Osm::Meeting?
Create a meeting in OSM
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/osm/meeting.rb', line 141 def self.create(api, parameters) require_ability_to(api, :write, :programme, parameters[:section_id]) meeting = new(parameters) data = api.perform_query("programme.php?action=addActivityToProgramme", { 'meetingdate' => meeting.date.strftime(Osm::OSM_DATE_FORMAT), 'sectionid' => meeting.section_id, 'activityid' => -1, 'start' => meeting.date.strftime(Osm::OSM_DATE_FORMAT), 'starttime' => meeting.start_time, 'endtime' => meeting.finish_time, 'title' => meeting.title, }) # The cached programmes for the section will be out of date - remove them Osm::Term.get_for_section(api, meeting.section_id).each do |term| cache_delete(api, ['programme', meeting.section_id, term.id]) end return data.is_a?(Hash) ? meeting : nil end |
.get_for_section(api, section, term = nil, options = {}) ⇒ Array<Osm::Meeting>
Get the programme for a given term
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/osm/meeting.rb', line 72 def self.get_for_section(api, section, term=nil, ={}) require_ability_to(api, :read, :programme, section, ) section_id = section.to_i term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i cache_key = ['programme', section_id, term_id] if ![:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end data = api.perform_query("programme.php?action=getProgramme§ionid=#{section_id}&termid=#{term_id}") result = Array.new data = {'items'=>[],'activities'=>{}} if data.is_a? Array items = data['items'] || [] activities = data['activities'] || {} badge_links = data['badgelinks'] || {} items.each do |item| attributes = {} attributes[:id] = Osm::to_i_or_nil(item['eveningid']) attributes[:section_id] = Osm::to_i_or_nil(item['sectionid']) attributes[:title] = item['title'] || 'Unnamed meeting' attributes[:notes_for_parents] = item['notesforparents'] || '' attributes[:games] = item['games'] || '' attributes[:pre_notes] = item['prenotes'] || '' attributes[:post_notes] = item['postnotes'] || '' attributes[:leaders] = item['leaders'] || '' attributes[:start_time] = item['starttime'].nil? ? nil : item['starttime'][0..4] attributes[:finish_time] = item['endtime'].nil? ? nil : item['endtime'][0..4] attributes[:date] = Osm::parse_date(item['meetingdate']) our_activities = activities[item['eveningid']] attributes[:activities] = Array.new unless our_activities.nil? our_activities.each do |activity_data| attributes[:activities].push Osm::Meeting::Activity.new( :activity_id => Osm::to_i_or_nil(activity_data['activityid']), :title => activity_data['title'], :notes => activity_data['notes'], ) end end our_badge_links = badge_links[item['eveningid']] attributes[:badge_links] = Array.new unless our_badge_links.nil? our_badge_links.each do |badge_link_data| attributes[:badge_links].push Osm::Meeting::BadgeLink.new( :badge_key => badge_link_data['badge'], :badge_type => badge_link_data['badgetype'].downcase.to_sym, :requirement_key => badge_link_data['columnname'], :badge_section => badge_link_data['section'].downcase.to_sym, :label => badge_link_data['label'], ) end end result.push new(attributes) end cache_write(api, cache_key, result) return result end |
Instance Method Details
#<=>(another) ⇒ Object
Compare Meeting based on section_id, date, start_time then id
302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/osm/meeting.rb', line 302 def <=>(another) result = self.section_id <=> another.try(:section_id) result = self.date <=> another.try(:date) if result == 0 if result == 0 my_start_time = self.start_time.split(':').map{ |i| i.to_i } another_start_time = another.start_time.split(':').map{ |i| i.to_i } result = my_start_time[0] <=> another_start_time[0] if result == 0 result = compare = my_start_time[1] <=> another_start_time[1] if result == 0 end result = self.id <=> another.try(:id) if result == 0 return result end |
#add_activity(api, activity, notes = '') ⇒ Boolean
Add an activity to this meeting in OSM
226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/osm/meeting.rb', line 226 def add_activity(api, activity, notes='') if activity.add_to_programme(api, section_id, date, notes) activities.push Osm::Meeting::Activity.new(:activity_id => activity.id, :notes => notes, :title => activity.title) # The cached programmes for the section will be out of date - remove them Osm::Term.get_for_section(api, section_id).each do |term| cache_delete(api, ['programme', section_id, term.id]) if term.contains_date?(date) end return true end return false end |
#delete(api) ⇒ Boolean
Delete meeting from OSM
244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/osm/meeting.rb', line 244 def delete(api) require_ability_to(api, :write, :programme, section_id) data = api.perform_query("programme.php?action=deleteEvening&eveningid=#{id}§ionid=#{section_id}") # The cached programmes for the section will be out of date - remove them Osm::Term.get_for_section(api, section_id).each do |term| cache_delete(api, ['programme', section_id, term.id]) if term.contains_date?(date) end return true end |
#get_badge_requirements(api, options = {}) ⇒ Array<Hash>?
Get the badge requirements met on a specific meeting Requires either write permission to badges (prefered as it’s one OSM query) or read permission to programme.
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 293 294 295 296 297 298 299 |
# File 'lib/osm/meeting.rb', line 264 def get_badge_requirements(api, ={}) section = Osm::Section.get(api, section_id) cache_key = ['badge_requirements', section.id, id] if ![:no_cache] && cache_exist?(api, cache_key) return cache_read(api, cache_key) end badges = nil if (api, :write, :badge, section_id, ) # We can shortcut and do it in one query badges = api.perform_query("users.php?action=getActivityRequirements&date=#{date.strftime(Osm::OSM_DATE_FORMAT)}§ionid=#{section.id}§ion=#{section.type}") else # We'll have to iterate through the activities require_ability_to(api, :read, :programme, section_id, ) badges = [] activities.each do |activity| activity = Osm::Activity.get(api, activity.activity_id, nil, ) activity.badges.each do |badge| badges.push ({ 'name' => badge.label, 'badgeName' => badge.badge, 'sectionid' => section_id.to_s, 'eveningid' => id.to_s, 'section' => badge.section_type, 'badgetype' => badge.type, 'badge' => badge.badge, 'columnname' => badge.requirement, }) end end end cache_write(api, cache_key, badges) unless badges.nil? return badges end |
#update(api) ⇒ Boolean
Update an meeting in OSM
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 |
# File 'lib/osm/meeting.rb', line 168 def update(api) raise Osm::ObjectIsInvalid, 'meeting is invalid' unless valid? require_ability_to(api, :write, :programme, section_id) activities_data = Array.new activities.each do |activity| this_activity = { 'activityid' => activity.activity_id, 'notes' => activity.notes, } activities_data.push this_activity end badge_links_data = Array.new badge_links.each do |badge_link| this_badge_link = { 'section' => badge_link.badge_section, 'badge' => badge_link.badge_key, 'columnname' => badge_link.requirement_key, 'badgetype' => badge_link.badge_type, } badge_links_data.push this_badge_link end api_data = { 'eveningid' => id, 'sectionid' => section_id, 'meetingdate' => date.strftime(Osm::OSM_DATE_FORMAT), 'starttime' => start_time, 'endtime' => finish_time, 'title' => title, 'notesforparents' => notes_for_parents, 'prenotes' => pre_notes, 'postnotes' => post_notes, 'games' => games, 'leaders' => leaders, 'activity' => ActiveSupport::JSON.encode(activities_data), 'badgelinks' => ActiveSupport::JSON.encode(badge_links_data), } response = api.perform_query("programme.php?action=editEvening", api_data) if response.is_a?(Hash) && (response['result'] == 0) reset_changed_attributes # The cached programmes for the section will be out of date - remove them Osm::Term.get_for_section(api, section_id).each do |term| cache_delete(api, ['programme', section_id, term.id]) if term.contains_date?(date) end return true else return false end end |