Class: Osm::Activity
Defined Under Namespace
Instance Attribute Summary collapse
-
#badges ⇒ Array<Osm::Activity::Badge>
Array<Osm::Activity::Badge>.
-
#deletable ⇒ Boolean
Wether the current API user can delete this activity.
-
#description ⇒ String
The description of the activity.
-
#editable ⇒ Boolean
Wether the current API user can edit this activity.
-
#files ⇒ Array<Osm::Activity::File>
Array<Osm::Activity::File>.
-
#group_id ⇒ Fixnum
The group_id.
-
#id ⇒ Fixnum
The id for the activity.
-
#instructions ⇒ String
Instructions for doing the activity.
-
#location ⇒ Symbol
:indoors, :outdoors or :both.
-
#rating ⇒ Fixnum
?.
-
#resources ⇒ String
Resources required to do the activity.
-
#running_time ⇒ Fixnum
Duration of the activity in minutes.
-
#sections ⇒ Array<Symbol>
The sections the activity is appropriate for.
-
#shared ⇒ Fixnum
2 - Public, 0 - Private.
-
#tags ⇒ Array<String>
The tags attached to the activity.
-
#title ⇒ String
The activity’s title.
-
#used ⇒ Fixnum
How many times this activity has been used (total accross all of OSM).
-
#user_id ⇒ Fixnum
The user_id of the creator of the activity.
-
#version ⇒ Fixnum
The version of the activity.
- #versions ⇒ Array<Osm::Activity::Version>
Class Method Summary collapse
-
.get(api, activity_id, version = nil, options = {}) ⇒ Osm::Activity
Get activity details.
Instance Method Summary collapse
-
#<=>(another) ⇒ Object
Compare Activity based on id then version.
-
#add_to_programme(api, section, date, notes = "") ⇒ Boolean
Add this activity to the programme in OSM.
-
#initialize ⇒ Object
constructor
Initialize a new Term.
-
#osm_link ⇒ String
Get the link to display this activity in OSM.
-
#update(api, section, secret_update = false) ⇒ Boolean
Update this activity in OSM.
Methods inherited from Model
#<, #<=, #>, #>=, #between?, #changed_attributes, configure, #reset_changed_attributes, #to_i
Constructor Details
#initialize ⇒ Object
Initialize a new Term
|
# File 'lib/osm/activity.rb', line 186
|
Instance Attribute Details
#badges ⇒ Array<Osm::Activity::Badge>
Returns Array<Osm::Activity::Badge>.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#deletable ⇒ Boolean
Returns Wether the current API user can delete this activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#description ⇒ String
Returns the description of the activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#editable ⇒ Boolean
Returns Wether the current API user can edit this activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#files ⇒ Array<Osm::Activity::File>
Returns Array<Osm::Activity::File>.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#group_id ⇒ Fixnum
Returns the group_id.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#id ⇒ Fixnum
Returns the id for the activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#instructions ⇒ String
Returns instructions for doing the activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#location ⇒ Symbol
Returns :indoors, :outdoors or :both.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#rating ⇒ Fixnum
Returns ?.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#resources ⇒ String
Returns resources required to do the activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#running_time ⇒ Fixnum
Returns duration of the activity in minutes.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#sections ⇒ Array<Symbol>
Returns the sections the activity is appropriate for.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#shared ⇒ Fixnum
Returns 2 - Public, 0 - Private.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#tags ⇒ Array<String>
Returns the tags attached to the activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#title ⇒ String
Returns the activity’s title.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#used ⇒ Fixnum
Returns How many times this activity has been used (total accross all of OSM).
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#user_id ⇒ Fixnum
Returns the user_id of the creator of the activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#version ⇒ Fixnum
Returns the version of the activity.
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
#versions ⇒ Array<Osm::Activity::Version>
49 |
# File 'lib/osm/activity.rb', line 49 attribute :id, :type => Integer |
Class Method Details
.get(api, activity_id, version = nil, options = {}) ⇒ Osm::Activity
Get activity details
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 136 137 138 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 |
# File 'lib/osm/activity.rb', line 106 def self.get(api, activity_id, version=nil, ={}) cache_key = ['activity', activity_id] if ![:no_cache] && cache_exist?(api, [*cache_key, version]) activity = cache_read(api, [*cache_key, version]) if (activity.shared == 2) || (activity.user_id == api.user_id) || # Shared or owned by this user Osm::Section.get_all(api).map{ |s| s.group_id }.uniq.include?(activity.group_id) # user belomngs to the group owning the activity return activity else return nil end end data = nil if version.nil? data = api.perform_query("programme.php?action=getActivity&id=#{activity_id}") else data = api.perform_query("programme.php?action=getActivity&id=#{activity_id}&version=#{version}") end attributes = {} attributes[:id] = Osm::to_i_or_nil(data['details']['activityid']) attributes[:version] = data['details']['version'].to_i attributes[:group_id] = Osm::to_i_or_nil(data['details']['groupid']) attributes[:user_id] = Osm::to_i_or_nil(data['details']['userid']) attributes[:title] = data['details']['title'] attributes[:description] = data['details']['description'] attributes[:resources] = data['details']['resources'] attributes[:instructions] = data['details']['instructions'] attributes[:running_time] = Osm::to_i_or_nil(data['details']['runningtime']) attributes[:location] = data['details']['location'].to_sym attributes[:shared] = Osm::to_i_or_nil(data['details']['shared']) attributes[:rating] = data['details']['rating'].to_i attributes[:editable] = data['editable'] attributes[:deletable] = data['deletable'] ? true : false attributes[:used] = data['used'].to_i attributes[:sections] = data['sections'].is_a?(Array) ? Osm::make_array_of_symbols(data['sections']) : [] attributes[:tags] = data['tags'].is_a?(Array) ? data['tags'] : [] attributes[:versions] = [] attributes[:files] = [] attributes[:badges] = [] # Populate Arrays (data['files'].is_a?(Array) ? data['files'] : []).each do |file_data| attributes[:files].push File.new( :id => Osm::to_i_or_nil(file_data['fileid']), :activity_id => Osm::to_i_or_nil(file_data['activityid']), :file_name => file_data['filename'], :name => file_data['name'] ) end (data['badges'].is_a?(Array) ? data['badges'] : []).each do |badge_data| attributes[:badges].push Badge.new( :badge_type => badge_data['badgetype'].to_sym, :badge_section => badge_data['section'].to_sym, :badge_name => badge_data['badgeLongName'], :badge_id => Osm::to_i_or_nil(badge_data['badge_id']), :badge_version => Osm::to_i_or_nil(badge_data['badge_version']), :requirement_id => Osm::to_i_or_nil(badge_data['column_id']), :requirement_label => badge_data['columnnameLongName'], :data => badge_data['data'], ) end (data['versions'].is_a?(Array) ? data['versions'] : []).each do |version_data| attributes[:versions].push Version.new( :version => Osm::to_i_or_nil(version_data['value']), :created_by => Osm::to_i_or_nil(version_data['userid']), :created_by_name => version_data['firstname'], :label => version_data['label'] ) end activity = Osm::Activity.new(attributes) cache_write(api, [*cache_key, nil], activity) if version.nil? cache_write(api, [*cache_key, version], activity) return activity end |
Instance Method Details
#<=>(another) ⇒ Object
Compare Activity based on id then version
278 279 280 281 282 |
# File 'lib/osm/activity.rb', line 278 def <=>(another) result = self.id <=> another.try(:id) result = self.version <=> another.try(:version) if result == 0 return result end |
#add_to_programme(api, section, date, notes = "") ⇒ Boolean
Add this activity to the programme in OSM
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/osm/activity.rb', line 205 def add_to_programme(api, section, date, notes="") require_ability_to(api, :write, :programme, section) data = api.perform_query("programme.php?action=addActivityToProgramme", { 'meetingdate' => date.strftime(Osm::OSM_DATE_FORMAT), 'activityid' => id, 'sectionid' => section.to_i, 'notes' => notes, }) if (data == {'result'=>0}) # The cached activity will be out of date - remove it cache_delete(api, ['activity', self.id]) return true else return false end end |
#osm_link ⇒ String
Get the link to display this activity in OSM
194 195 196 197 |
# File 'lib/osm/activity.rb', line 194 def osm_link raise Osm::ObjectIsInvalid, 'activity is invalid' unless valid? return "https://www.onlinescoutmanager.co.uk/?l=p#{self.id}" end |
#update(api, section, secret_update = false) ⇒ Boolean
Update this activity in OSM
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/activity.rb', line 231 def update(api, section, secret_update=false) raise Osm::ObjectIsInvalid, 'activity is invalid' unless valid? raise Osm::Forbidden, "You are not allowed to update this activity" unless self.editable data = api.perform_query("programme.php?action=update", { 'title' => title, 'description' => description, 'resources' => resources, 'instructions' => instructions, 'id' => id, 'files' => files.map{|f| f.id }.join(','), 'time' => running_time.to_s, 'location' => location, 'sections' => sections.to_json, 'tags' => .to_json, 'links' => badges.map{ |b| { 'badge_id' => b.badge_id.to_s, 'badge_version' => b.badge_version.to_s, 'column_id' => b.requirement_id.to_s, 'badge' => nil, 'badgeLongName' => b.badge_name, 'columnname' => nil, 'columnnameLongName' => b.requirement_label, 'data' => b.data, 'section' => b.badge_section, 'sectionLongName' => nil, 'sections' => sections.map{ |s| s.to_s }, 'badgetype' => b.badge_type.to_s, 'badgetypeLongName' => nil, } }.to_json, 'shared' => shared, 'sectionid' => section.to_i, 'secretEdit' => secret_update, }) if (data == {'result'=>true}) # The cached activity will be out of date - remove it cache_delete(api, ['activity', self.id]) return true else return false end end |