Class: Osm::Meeting
Defined Under Namespace
Classes: Activity
Instance Attribute Summary collapse
-
#activities ⇒ Array<Activity>
List of activities being done during 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.
-
#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 55
|
Instance Attribute Details
#activities ⇒ Array<Activity>
Returns list of activities being done during the meeting.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#date ⇒ Date
Returns the date of the meeting.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#finish_time ⇒ String
Returns the end time (hh:mm).
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#games ⇒ String
Returns games to be played during the meeting.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#id ⇒ Fixnum
Returns the id of the meeting.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#leaders ⇒ String
Returns the leaders present at the meeting.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#notes_for_parents ⇒ String
Returns notes to be shared with parents.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#post_notes ⇒ String
Returns notes for the end of the meeting.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#pre_notes ⇒ String
Returns notes for the start of the meeting.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#section_id ⇒ Fixnum
Returns the section the meeting belongs to.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#start_time ⇒ String
Returns the start time (hh:mm).
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
#title ⇒ String
Returns the title of the meeting.
31 |
# File 'lib/osm/meeting.rb', line 31 attribute :id, :type => Integer |
Class Method Details
.create(api, parameters) ⇒ Osm::Meeting?
Create a meeting in OSM
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/osm/meeting.rb', line 120 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
66 67 68 69 70 71 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 |
# File 'lib/osm/meeting.rb', line 66 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'] || {} 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 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
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/osm/meeting.rb', line 245 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
194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/osm/meeting.rb', line 194 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
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/osm/meeting.rb', line 212 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
229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/osm/meeting.rb', line 229 def get_badge_requirements(api, ={}) require_ability_to(api, :read, :programme, section_id, ) 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 data = api.perform_query("users.php?action=getActivityRequirements&date=#{date.strftime(Osm::OSM_DATE_FORMAT)}§ionid=#{section.id}§ion=#{section.type}") cache_write(api, cache_key, data) return data end |
#update(api) ⇒ Boolean
Update an meeting in OSM
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 |
# File 'lib/osm/meeting.rb', line 147 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 activities_data = ActiveSupport::JSON.encode(activities_data) 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' => activities_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 |