osm 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +32 -5
- data/README.md +16 -17
- data/lib/osm.rb +1 -1
- data/lib/osm/activity.rb +18 -0
- data/lib/osm/api.rb +3 -2
- data/lib/osm/evening.rb +51 -15
- data/lib/osm/event.rb +72 -15
- data/lib/osm/flexi_record.rb +114 -1
- data/lib/osm/grouping.rb +1 -1
- data/lib/osm/member.rb +118 -6
- data/lib/osm/register.rb +1 -1
- data/lib/osm/section.rb +8 -8
- data/osm.gemspec +1 -1
- data/spec/osm/activity_spec.rb +25 -0
- data/spec/osm/evening_spec.rb +54 -4
- data/spec/osm/event_spec.rb +76 -2
- data/spec/osm/flexi_record_spec.rb +225 -0
- data/spec/osm/member_spec.rb +212 -0
- data/spec/osm/section_spec.rb +6 -4
- data/version.rb +1 -1
- metadata +17 -17
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,31 @@
|
|
1
|
-
## Version 0.
|
1
|
+
## Version 0.1.12
|
2
|
+
|
3
|
+
* Attribute Section.myscout\_email\_address\_send defaults to an empty String
|
4
|
+
* Attribute Section.myscout\_email\_address\_copy defaults to an empty String
|
5
|
+
* Attribute Section.myscout\_email\_address\_send renamed to myscout\_email\_address\_from
|
6
|
+
* Osm::Event::Column
|
7
|
+
* Rename parent\_label attribute to label
|
8
|
+
* Add update method to update OSM
|
9
|
+
* Add delete method to update OSM
|
10
|
+
* Osm::Evening
|
11
|
+
* Add delete method to update OSM
|
12
|
+
* Changes to create method:
|
13
|
+
* Now takes arguments of (api, parameters)
|
14
|
+
* Now returns an Osm::Evening on success, nil on failure
|
15
|
+
* Will now pass start time, finish time and title to OSM
|
16
|
+
* Add activity to programme
|
17
|
+
* Evening.add\_activity(api, activity, notes="")
|
18
|
+
* Activity.add\_to\_programme(api, section, date, notes="")
|
19
|
+
* Osm::Member
|
20
|
+
* Add create method to update OSM
|
21
|
+
* Add update method to update OSM
|
22
|
+
* Osm::FlexiRecord
|
23
|
+
* Add add\_field method to add a field to the record in OSM
|
24
|
+
* Add update\_field method to rename a field in OSM
|
25
|
+
* Add delete\_field method to delete a field from OSM
|
26
|
+
* Add update\_data method to update the data in OSM
|
27
|
+
|
28
|
+
## Version 0.1.11
|
2
29
|
|
3
30
|
* Fix "can't convert Hash into String" occuring when some section's config is a Hash not a JSON encoded Hash
|
4
31
|
* Remove num\_scouts attribute from Section (OSM always sets this to 999)
|
@@ -14,8 +41,8 @@
|
|
14
41
|
* myscout\_emails (Hash of Symbol to Boolean) - which email addresses are linked to MyScout for each Member
|
15
42
|
* myscout\_email\_address\_send (String, blank OK) - which email address to send My.SCOUT emails as
|
16
43
|
* myscout\_email\_address\_copy (String, blank OK) - which email address to send copys of My.SCOUT emails to
|
17
|
-
* myscout\_badges\_partial (Boolean) -
|
18
|
-
* myscout\_programme\_summary (Boolean) -
|
44
|
+
* myscout\_badges\_partial (Boolean) - Whether parents can see partially completed badges
|
45
|
+
* myscout\_programme\_summary (Boolean) - Whether parents can see the summary of programme items
|
19
46
|
* myscout\_event\_reminder\_count (Integer) - How many event reminders to send to parents who haven't responded
|
20
47
|
* myscout\_event\_reminder\_frequency (Integer) - How many days to leave between event reminder emails
|
21
48
|
* myscout\_payment\_reminder\_count (Integer) - How many payment reminders to send to parents who haven't paid yet
|
@@ -24,8 +51,8 @@
|
|
24
51
|
* notepad - the notepad shown in OSM
|
25
52
|
* public\_notepad - the notepad shown on My.SCOUT
|
26
53
|
* confirm\_by\_date - the last day that parents can change their child's attendance details
|
27
|
-
* allow\_changes -
|
28
|
-
* reminders -
|
54
|
+
* allow\_changes - whether parents can change their child's attendance details
|
55
|
+
* reminders - whether reminder emails are sent
|
29
56
|
* Osm::Event
|
30
57
|
* Mark fields attribute as depricated
|
31
58
|
* Add columns attribute returning an array of column details
|
data/README.md
CHANGED
@@ -68,7 +68,7 @@ api_for_this_user = Osm::Api.new(userid, secret)
|
|
68
68
|
Documentation can be found on [rubydoc.info](http://rubydoc.info/github/robertgauld/osm/master/frames)
|
69
69
|
|
70
70
|
We follow the [Semantic Versioning](http://semver.org/) concept,
|
71
|
-
however it should be noted that when the OSM API adds a feature it can be difficult to decide
|
71
|
+
however it should be noted that when the OSM API adds a feature it can be difficult to decide Whether to bump the patch or minor version number up. A smaller change (such as adding score into the grouping object) will bump the patch whereas a larger change wil bump the minor version.
|
72
72
|
|
73
73
|
|
74
74
|
## Parts of the OSM API Supported:
|
@@ -82,7 +82,7 @@ however it should be noted that when the OSM API adds a feature it can be diffic
|
|
82
82
|
* Evening
|
83
83
|
* Event
|
84
84
|
* Events
|
85
|
-
* Event
|
85
|
+
* Event Columns
|
86
86
|
* Event Attendance
|
87
87
|
* Flexi Record Data
|
88
88
|
* Flexi Record Structure
|
@@ -103,41 +103,40 @@ however it should be noted that when the OSM API adds a feature it can be diffic
|
|
103
103
|
* Evening
|
104
104
|
* Event
|
105
105
|
* Event Attendance
|
106
|
-
*
|
106
|
+
* Event Column
|
107
|
+
* Flexi Record Column
|
108
|
+
* Flexi Record Data
|
109
|
+
* Member
|
110
|
+
* Register Attendance
|
107
111
|
|
108
112
|
### Create
|
109
113
|
* Evening
|
110
114
|
* Event
|
115
|
+
* Member
|
116
|
+
* Flexi Record Column
|
111
117
|
|
112
118
|
### Delete
|
119
|
+
* Evening
|
113
120
|
* Event
|
121
|
+
* Event Column
|
122
|
+
* Flexi Record Column
|
114
123
|
|
115
124
|
### Actions
|
116
125
|
* Authorise an app to use the API on a user's behalf
|
126
|
+
* Add activity to programme
|
117
127
|
|
118
128
|
|
119
|
-
## Parts of the OSM API currently NOT supported:
|
129
|
+
## Parts of the OSM API currently NOT supported (may not be an exhaustive list):
|
120
130
|
|
121
|
-
* Event Fields:
|
122
|
-
* Delete [issue 45]
|
123
|
-
* Rename [issue 46]
|
124
131
|
* Badges:
|
125
132
|
* Which requirements each member has met:
|
126
133
|
* Retreive [issue 21]
|
127
134
|
* Update [issue 22]
|
128
135
|
* Retrieve details for each badge (stock, short column names etc.) [issue 20]
|
129
|
-
* Flexi Records:
|
130
|
-
* Update data [issue 23]
|
131
|
-
* Add Column [issue 24]
|
132
|
-
* Member:
|
133
|
-
* Update [issue 33]
|
134
|
-
* Add [issue 34]
|
135
|
-
* Add activity to programme [issue 35]
|
136
|
-
* Delete Evening [issue 36]
|
137
136
|
* Update Activity
|
138
|
-
* Gift aid (
|
137
|
+
* Gift aid (Everything)
|
139
138
|
* Finances (Everything)
|
140
139
|
* SMS:
|
141
140
|
* Retreival of delivery reports
|
142
141
|
* Sending a message
|
143
|
-
* MyScout
|
142
|
+
* MyScout (Everything) (Maybe)
|
data/lib/osm.rb
CHANGED
@@ -35,7 +35,7 @@ module Osm
|
|
35
35
|
# Configure the options used by classes in the module
|
36
36
|
# @param [Hash] options
|
37
37
|
# @option options [Hash] :api Default options for accessing the API
|
38
|
-
# @option options[:api] [Symbol] :default_site
|
38
|
+
# @option options[:api] [Symbol] :default_site whether to use OSM (if :osm) or OGM (if :ogm) by default
|
39
39
|
# @option options[:api] [Hash] :osm (optional but :osm_api or :ogm_api must be present) the api data for OSM
|
40
40
|
# @option options[:api][:osm] [String] :id the apiid given to you for using the OSM id
|
41
41
|
# @option options[:api][:osm] [String] :token the token which goes with the above api
|
data/lib/osm/activity.rb
CHANGED
@@ -177,6 +177,24 @@ module Osm
|
|
177
177
|
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
178
178
|
|
179
179
|
|
180
|
+
# Add this activity to the programme in OSM
|
181
|
+
# @param [Osm::Api] api The api to use to make the request
|
182
|
+
# @param [Osm::Section, Fixnum] activity The Section (or it's ID) to add the Activity to
|
183
|
+
# @param [Date, DateTime] date The date of the Evening to add the Activity to (OSM will create the Evening if it doesn't already exist)
|
184
|
+
# @param [String] notes The notes which should appear for this Activity on this Evening
|
185
|
+
# @return [Boolean] Whether the activity ws successfully added
|
186
|
+
def add_to_programme(api, section, date, notes="")
|
187
|
+
data = api.perform_query("programme.php?action=addActivityToProgramme", {
|
188
|
+
'meetingdate' => date.strftime(Osm::OSM_DATE_FORMAT),
|
189
|
+
'activityid' => id,
|
190
|
+
'sectionid' => section.to_i,
|
191
|
+
'notes' => notes,
|
192
|
+
})
|
193
|
+
|
194
|
+
return (data == {'result'=>0})
|
195
|
+
end
|
196
|
+
|
197
|
+
|
180
198
|
private
|
181
199
|
class File
|
182
200
|
include ::ActiveAttr::MassAssignmentSecurity
|
data/lib/osm/api.rb
CHANGED
@@ -17,7 +17,7 @@ module Osm
|
|
17
17
|
|
18
18
|
# Configure the API options used by all instances of the class
|
19
19
|
# @param [Hash] options
|
20
|
-
# @option options [Symbol] :default_site
|
20
|
+
# @option options [Symbol] :default_site whether to use OSM (if :osm) or OGM (if :ogm)
|
21
21
|
# @option options [Hash] :osm (optional but :osm_api or :ogm_api must be present) the api data for OSM
|
22
22
|
# @option options[:osm] [String] :id the apiid given to you for using the OSM id
|
23
23
|
# @option options[:osm] [String] :token the token which goes with the above api
|
@@ -53,7 +53,7 @@ module Osm
|
|
53
53
|
# Initialize a new API connection
|
54
54
|
# @param [String] user_id osm userid of the user to act as (get this by using the authorize method)
|
55
55
|
# @param [String] secret osm secret of the user to act as (get this by using the authorize method)
|
56
|
-
# @param [Symbol] site
|
56
|
+
# @param [Symbol] site whether to use OSM (:osm) or OGM (:ogm), defaults to the value set for the class
|
57
57
|
# @return nil
|
58
58
|
def initialize(user_id, secret, site=@@site)
|
59
59
|
raise ArgumentError, 'You must pass a secret (get this by using the authorize method)' if secret.nil?
|
@@ -171,6 +171,7 @@ module Osm
|
|
171
171
|
puts result.response.body
|
172
172
|
end
|
173
173
|
|
174
|
+
return nil if result.response.body.empty?
|
174
175
|
raise Osm::Error, result.response.body unless looks_like_json?(result.response.body)
|
175
176
|
decoded = ActiveSupport::JSON.decode(result.response.body)
|
176
177
|
osm_error = get_osm_error(decoded)
|
data/lib/osm/evening.rb
CHANGED
@@ -63,6 +63,7 @@ module Osm
|
|
63
63
|
# @param [Osm::term, Fixnum, nil] term the term (or its ID) to get the programme for, passing nil causes the current term to be used
|
64
64
|
# @!macro options_get
|
65
65
|
# @return [Array<Osm::Evening>]
|
66
|
+
# TODO Change to get_all in next version bump
|
66
67
|
def self.get_programme(api, section, term, options={})
|
67
68
|
section_id = section.to_i
|
68
69
|
term_id = term.nil? ? Osm::Term.get_current_term_for_section(api, section).id : term.to_i
|
@@ -115,25 +116,26 @@ module Osm
|
|
115
116
|
|
116
117
|
# Create an evening in OSM
|
117
118
|
# @param [Osm::Api] api The api to use to make the request
|
118
|
-
# @
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
'
|
125
|
-
'
|
126
|
-
'
|
127
|
-
|
128
|
-
|
129
|
-
|
119
|
+
# @return [Osm::Evening, nil] the created evening, nil if failed
|
120
|
+
def self.create(api, parameters)
|
121
|
+
evening = new(parameters)
|
122
|
+
|
123
|
+
data = api.perform_query("programme.php?action=addActivityToProgramme", {
|
124
|
+
'meetingdate' => evening.meeting_date.strftime(Osm::OSM_DATE_FORMAT),
|
125
|
+
'sectionid' => evening.section_id,
|
126
|
+
'activityid' => -1,
|
127
|
+
'start' => evening.meeting_date.strftime(Osm::OSM_DATE_FORMAT),
|
128
|
+
'starttime' => evening.start_time,
|
129
|
+
'endtime' => evening.finish_time,
|
130
|
+
'title' => evening.title,
|
131
|
+
})
|
130
132
|
|
131
133
|
# The cached programmes for the section will be out of date - remove them
|
132
|
-
Osm::Term.get_for_section(api,
|
133
|
-
cache_delete(api, ['programme', section_id, term.id])
|
134
|
+
Osm::Term.get_for_section(api, evening.section_id).each do |term|
|
135
|
+
cache_delete(api, ['programme', evening.section_id, term.id])
|
134
136
|
end
|
135
137
|
|
136
|
-
return data.is_a?(Hash)
|
138
|
+
return data.is_a?(Hash) ? evening : nil
|
137
139
|
end
|
138
140
|
|
139
141
|
|
@@ -177,6 +179,40 @@ module Osm
|
|
177
179
|
return response.is_a?(Hash) && (response['result'] == 0)
|
178
180
|
end
|
179
181
|
|
182
|
+
# Add an activity to this evening in OSM
|
183
|
+
# @param [Osm::Api] api The api to use to make the request
|
184
|
+
# @param [Osm::Activity] activity The Activity to add to the Evening
|
185
|
+
# @param [String] notes The notes which should appear for this Activity on this Evening
|
186
|
+
# @return [Boolean] Whether the activity ws successfully added
|
187
|
+
def add_activity(api, activity, notes='')
|
188
|
+
if activity.add_to_programme(api, section_id, meeting_date, notes)
|
189
|
+
activities.push Osm::Evening::Activity.new(:activity_id => activity.id, :notes => notes, :title => activity.title)
|
190
|
+
|
191
|
+
# The cached programmes for the section will be out of date - remove them
|
192
|
+
Osm::Term.get_for_section(api, section_id).each do |term|
|
193
|
+
cache_delete(api, ['programme', section_id, term.id]) if term.contains_date?(meeting_date)
|
194
|
+
end
|
195
|
+
|
196
|
+
return true
|
197
|
+
end
|
198
|
+
|
199
|
+
return false
|
200
|
+
end
|
201
|
+
|
202
|
+
# Delete evening from OSM
|
203
|
+
# @param [Osm::Api] api The api to use to make the request
|
204
|
+
# @return [Boolean] true
|
205
|
+
def delete(api)
|
206
|
+
data = api.perform_query("programme.php?action=deleteEvening&eveningid=#{id}§ionid=#{section_id}")
|
207
|
+
|
208
|
+
# The cached programmes for the section will be out of date - remove them
|
209
|
+
Osm::Term.get_for_section(api, section_id).each do |term|
|
210
|
+
cache_delete(api, ['programme', section_id, term.id]) if term.contains_date?(meeting_date)
|
211
|
+
end
|
212
|
+
|
213
|
+
return true
|
214
|
+
end
|
215
|
+
|
180
216
|
|
181
217
|
# Get the badge requirements met on a specific evening
|
182
218
|
# @param [Osm::Api] api The api to use to make the request
|
data/lib/osm/event.rb
CHANGED
@@ -33,9 +33,9 @@ module Osm
|
|
33
33
|
# @!attribute [rw] confirm_by_date
|
34
34
|
# @return [Date] the date parents can no longer add/change their child's details
|
35
35
|
# @!attribute [rw] allow_changes
|
36
|
-
# @return [Boolean]
|
36
|
+
# @return [Boolean] whether parent's can change their child's details
|
37
37
|
# @!attribute [rw] reminders
|
38
|
-
# @return [Boolean]
|
38
|
+
# @return [Boolean] whether email reminders are sent for the event
|
39
39
|
|
40
40
|
attribute :id, :type => Integer
|
41
41
|
attribute :section_id, :type => Integer
|
@@ -160,7 +160,7 @@ module Osm
|
|
160
160
|
|
161
161
|
# Update event in OSM
|
162
162
|
# @param [Osm::Api] api The api to use to make the request
|
163
|
-
# @return [Boolean]
|
163
|
+
# @return [Boolean] whether the update succedded
|
164
164
|
def update(api)
|
165
165
|
raise Forbidden, 'you do not have permission to write to events for this section' unless get_user_permission(api, section_id, :events).include?(:write)
|
166
166
|
|
@@ -196,7 +196,7 @@ module Osm
|
|
196
196
|
|
197
197
|
# Delete event from OSM
|
198
198
|
# @param [Osm::Api] api The api to use to make the request
|
199
|
-
# @return [Boolean]
|
199
|
+
# @return [Boolean] whether the delete succedded
|
200
200
|
def delete(api)
|
201
201
|
raise Forbidden, 'you do not have permission to write to events for this section' unless get_user_permission(api, section_id, :events).include?(:write)
|
202
202
|
|
@@ -254,7 +254,7 @@ module Osm
|
|
254
254
|
# @param [Osm::Api] api The api to use to make the request
|
255
255
|
# @param [String] label the label for the field in OSM
|
256
256
|
# @param [String] name the label for the field in My.SCOUT (if this is blank then parents can't edit it)
|
257
|
-
# @return [Boolean]
|
257
|
+
# @return [Boolean] whether the update succedded
|
258
258
|
def add_column(api, name, label='')
|
259
259
|
raise ArgumentIsInvalid, 'name is invalid' if name.blank?
|
260
260
|
raise Forbidden, 'you do not have permission to write to events for this section' unless get_user_permission(api, section_id, :events).include?(:write)
|
@@ -278,7 +278,7 @@ module Osm
|
|
278
278
|
# @deprecated use add_column instead
|
279
279
|
# @param [Osm::Api] api The api to use to make the request
|
280
280
|
# @param [String] field_label the label for the field to add
|
281
|
-
# @return [Boolean]
|
281
|
+
# @return [Boolean] whether the update succedded
|
282
282
|
# TODO - Remove this method when upping the version
|
283
283
|
def add_field(api, label)
|
284
284
|
warn "[DEPRECATION OF METHOD] this method is being depreiated, use add_column instead"
|
@@ -311,11 +311,6 @@ module Osm
|
|
311
311
|
|
312
312
|
private
|
313
313
|
def self.new_event_from_data(event_data)
|
314
|
-
columns = []
|
315
|
-
ActiveSupport::JSON.decode(event_data['config']).each do |field|
|
316
|
-
columns.push Column.new(:id => field['id'], :name => field['name'], :parent_label => field['pL'])
|
317
|
-
end
|
318
|
-
|
319
314
|
event = Osm::Event.new(
|
320
315
|
:id => Osm::to_i_or_nil(event_data['eventid']),
|
321
316
|
:section_id => Osm::to_i_or_nil(event_data['sectionid']),
|
@@ -326,13 +321,19 @@ module Osm
|
|
326
321
|
:location => event_data['location'],
|
327
322
|
:notes => event_data['notes'],
|
328
323
|
:archived => event_data['archived'].eql?('1'),
|
329
|
-
:columns => columns,
|
330
324
|
:notepad => event_data['notepad'],
|
331
325
|
:public_notepad => event_data['publicnotes'],
|
332
326
|
:confirm_by_date => Osm::parse_date(event_data['confdate']),
|
333
327
|
:allow_changes => event_data['allowchanges'].eql?('1'),
|
334
328
|
:reminders => !event_data['disablereminders'].eql?('1'),
|
335
329
|
)
|
330
|
+
|
331
|
+
columns = []
|
332
|
+
ActiveSupport::JSON.decode(event_data['config']).each do |field|
|
333
|
+
columns.push Column.new(:id => field['id'], :name => field['name'], :label => field['pL'], :event => event)
|
334
|
+
end
|
335
|
+
event.columns = columns
|
336
|
+
return event
|
336
337
|
end
|
337
338
|
|
338
339
|
|
@@ -344,14 +345,17 @@ module Osm
|
|
344
345
|
# @return [String] OSM id for the column
|
345
346
|
# @!attribute [rw] name
|
346
347
|
# @return [String] name for the column (displayed in OSM)
|
347
|
-
# @!attribute [rw]
|
348
|
+
# @!attribute [rw] label
|
348
349
|
# @return [String] label to display in My.SCOUT ("" prevents display in My.SCOUT)
|
350
|
+
# @!attriute [rw] event
|
351
|
+
# @return [Osm::Event] the event that this column belongs to
|
349
352
|
|
350
353
|
attribute :id, :type => String
|
351
354
|
attribute :name, :type => String
|
352
|
-
attribute :
|
355
|
+
attribute :label, :type => String, :default => ''
|
356
|
+
attribute :event
|
353
357
|
|
354
|
-
attr_accessible :id, :name, :
|
358
|
+
attr_accessible :id, :name, :label, :event
|
355
359
|
|
356
360
|
validates_presence_of :id
|
357
361
|
validates_presence_of :name
|
@@ -361,6 +365,57 @@ module Osm
|
|
361
365
|
# Initialize a new Column
|
362
366
|
# @param [Hash] attributes the hash of attributes (see attributes for descriptions, use Symbol of attribute name as the key)
|
363
367
|
|
368
|
+
|
369
|
+
# Update event column in OSM
|
370
|
+
# @param [Osm::Api] api The api to use to make the request
|
371
|
+
# @return [Boolean] if the operation suceeded or not
|
372
|
+
def update(api)
|
373
|
+
raise Forbidden, 'you do not have permission to write to events for this section' unless Osm::Model.get_user_permission(api, event.section_id, :events).include?(:write)
|
374
|
+
|
375
|
+
data = api.perform_query("events.php?action=renameColumn§ionid=#{event.section_id}&eventid=#{event.id}", {
|
376
|
+
'columnId' => id,
|
377
|
+
'columnName' => name,
|
378
|
+
'pL' => label
|
379
|
+
})
|
380
|
+
|
381
|
+
# The cached events for the section will be out of date - remove them
|
382
|
+
Osm::Model.cache_delete(api, ['events', event.section_id])
|
383
|
+
Osm::Model.cache_delete(api, ['event', event.id])
|
384
|
+
|
385
|
+
(ActiveSupport::JSON.decode(data['config']) || []).each do |i|
|
386
|
+
if i['id'] == id
|
387
|
+
return i['name'].eql?(name) && (i['pL'].nil? || i['pL'].eql?(label))
|
388
|
+
end
|
389
|
+
end
|
390
|
+
return false
|
391
|
+
end
|
392
|
+
|
393
|
+
# Delete event column from OSM
|
394
|
+
# @param [Osm::Api] api The api to use to make the request
|
395
|
+
# @return [Boolean] whether the delete succedded
|
396
|
+
def delete(api)
|
397
|
+
raise Forbidden, 'you do not have permission to write to events for this section' unless Osm::Model.get_user_permission(api, event.section_id, :events).include?(:write)
|
398
|
+
|
399
|
+
data = api.perform_query("events.php?action=deleteColumn§ionid=#{event.section_id}&eventid=#{event.id}", {
|
400
|
+
'columnId' => id
|
401
|
+
})
|
402
|
+
|
403
|
+
# The cached events for the section will be out of date - remove them
|
404
|
+
Osm::Model.cache_delete(api, ['events', event.section_id])
|
405
|
+
Osm::Model.cache_delete(api, ['event', event.id])
|
406
|
+
|
407
|
+
(ActiveSupport::JSON.decode(data['config']) || []).each do |i|
|
408
|
+
return false if i['id'] == id
|
409
|
+
end
|
410
|
+
|
411
|
+
new_columns = []
|
412
|
+
event.columns.each do |column|
|
413
|
+
new_columns.push(column) unless column == self
|
414
|
+
end
|
415
|
+
event.columns = new_columns
|
416
|
+
return true
|
417
|
+
end
|
418
|
+
|
364
419
|
end # class Column
|
365
420
|
|
366
421
|
|
@@ -376,6 +431,8 @@ module Osm
|
|
376
431
|
# @return [Hash] Keys are the field's id, values are the field values
|
377
432
|
# @!attribute [rw] row
|
378
433
|
# @return [Fixnum] part of the OSM API
|
434
|
+
# @!attriute [rw] event
|
435
|
+
# @return [Osm::Event] the event that this attendance applies to
|
379
436
|
|
380
437
|
attribute :row, :type => Integer
|
381
438
|
attribute :member_id, :type => Integer
|
data/lib/osm/flexi_record.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# TODO make 'proper' class
|
2
|
+
|
1
3
|
module Osm
|
2
4
|
|
3
5
|
class FlexiRecord
|
@@ -5,7 +7,7 @@ module Osm
|
|
5
7
|
# Get structure for a flexi record
|
6
8
|
# @param [Osm::Api] api The api to use to make the request
|
7
9
|
# @param [Osm::Section, Fixnum] section the section (or its ID) to get the structure for
|
8
|
-
# @param [Fixnum] the id of the Flexi Record
|
10
|
+
# @param [Fixnum] id the id of the Flexi Record
|
9
11
|
# @!macro options_get
|
10
12
|
# @return [Array<Osm::FlexiRecordField>] representing the fields of the flexi record
|
11
13
|
def self.get_fields(api, section, id, options={})
|
@@ -33,6 +35,87 @@ module Osm
|
|
33
35
|
return structure
|
34
36
|
end
|
35
37
|
|
38
|
+
# Add a field in OSM
|
39
|
+
# @param [Osm::Api] api The api to use to make the request
|
40
|
+
# @param [Osm::Section, Fixnum] section the section (or its ID) to get the structure for
|
41
|
+
# @param [Fixnum] id the id of the Flexi Record
|
42
|
+
# @param [String] name The name for the created column
|
43
|
+
# @return [Boolean] whether the field was created in OSM
|
44
|
+
def self.add_field(api, section, id, name)
|
45
|
+
raise ArgumentError, 'name is invalid' if name.blank?
|
46
|
+
section_id = section.to_i
|
47
|
+
|
48
|
+
data = api.perform_query("extras.php?action=addColumn§ionid=#{section_id}&extraid=#{id}", {
|
49
|
+
'columnName' => name,
|
50
|
+
})
|
51
|
+
|
52
|
+
if (data.is_a?(Hash) && data.has_key?('config'))
|
53
|
+
ActiveSupport::JSON.decode(data['config']).each do |field|
|
54
|
+
if field['name'] == name
|
55
|
+
# The cached fields for the flexi record will be out of date - remove them
|
56
|
+
Osm::Model.cache_delete(api, ['flexi_record_fields', id])
|
57
|
+
return true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
return false
|
62
|
+
end
|
63
|
+
|
64
|
+
# Update a field in OSM
|
65
|
+
# @param [Osm::Api] api The api to use to make the request
|
66
|
+
# @param [Osm::Section, Fixnum] section the section (or its ID) to get the structure for
|
67
|
+
# @param [Fixnum] id the id of the Flexi Record
|
68
|
+
# @param [String] field the id of the Flexi Record Field
|
69
|
+
# @param [String] name The new name for the created column
|
70
|
+
# @return [Boolean] whether the field was updated in OSM
|
71
|
+
def self.update_field(api, section, id, field, name)
|
72
|
+
raise ArgumentError, 'name is invalid' if name.blank?
|
73
|
+
section_id = section.to_i
|
74
|
+
|
75
|
+
data = api.perform_query("extras.php?action=renameColumn§ionid=#{section_id}&extraid=#{id}", {
|
76
|
+
'columnId' => field,
|
77
|
+
'columnName' => name,
|
78
|
+
})
|
79
|
+
|
80
|
+
if (data.is_a?(Hash) && data.has_key?('config'))
|
81
|
+
ActiveSupport::JSON.decode(data['config']).each do |f|
|
82
|
+
if (f['id'] == field) && (f['name'] == name)
|
83
|
+
# The cached fields for the flexi record will be out of date - remove them
|
84
|
+
Osm::Model.cache_delete(api, ['flexi_record_fields', id])
|
85
|
+
return true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return false
|
90
|
+
end
|
91
|
+
|
92
|
+
# Update a field in OSM
|
93
|
+
# @param [Osm::Api] api The api to use to make the request
|
94
|
+
# @param [Osm::Section, Fixnum] section the section (or its ID) to get the structure for
|
95
|
+
# @param [Fixnum] id the id of the Flexi Record
|
96
|
+
# @param [String] field the id of the Flexi Record Field
|
97
|
+
# @return [Boolean] whether the field was updated in OSM
|
98
|
+
def self.delete_field(api, section, id, field)
|
99
|
+
section_id = section.to_i
|
100
|
+
|
101
|
+
data = api.perform_query("extras.php?action=deleteColumn§ionid=#{section_id}&extraid=#{id}", {
|
102
|
+
'columnId' => field,
|
103
|
+
})
|
104
|
+
|
105
|
+
if (data.is_a?(Hash) && data.has_key?('config'))
|
106
|
+
ActiveSupport::JSON.decode(data['config']).each do |f|
|
107
|
+
if f['id'] == field
|
108
|
+
# It wasn't deleted
|
109
|
+
return false
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# The cached fields for the flexi record will be out of date - remove them
|
115
|
+
Osm::Model.cache_delete(api, ['flexi_record_fields', id])
|
116
|
+
return true
|
117
|
+
end
|
118
|
+
|
36
119
|
# Get data for flexi record
|
37
120
|
# @param [Osm::Api] api The api to use to make the request
|
38
121
|
# @param [Osm::Section, Fixnum] section the section (or its ID) to get the register for
|
@@ -76,6 +159,36 @@ module Osm
|
|
76
159
|
return to_return
|
77
160
|
end
|
78
161
|
|
162
|
+
# Update a field in OSM
|
163
|
+
# @param [Osm::Api] api The api to use to make the request
|
164
|
+
# @param [Osm::Section, Fixnum] section the section (or its ID) to update the data for
|
165
|
+
# @param [Fixnum] flexi_record_id the id of the Flexi Record
|
166
|
+
# @param [Osm::Member, Fixnum] member the member (or their ID) to update
|
167
|
+
# @param [String] column the id of the Flexi Record Field
|
168
|
+
# @param [String] value The updated value
|
169
|
+
# @return [Boolean] whether the field was updated in OSM
|
170
|
+
def self.update_data(api, section, flexi_record_id, member, column, value)
|
171
|
+
raise ArgumentError, 'name is invalid' if name.blank?
|
172
|
+
section_id = section.to_i
|
173
|
+
member_id = member.to_i
|
174
|
+
term_id = Osm::Term.get_current_term_for_section(api, section).id
|
175
|
+
|
176
|
+
data = api.perform_query("extras.php?action=updateScout", {
|
177
|
+
'termid' => term_id,
|
178
|
+
'scoutid' => member_id,
|
179
|
+
'column' => column,
|
180
|
+
'value' => value,
|
181
|
+
'sectionid' => section_id,
|
182
|
+
'extraid' => flexi_record_id,
|
183
|
+
})
|
184
|
+
|
185
|
+
if (data.is_a?(Hash) && data['items'].is_a?(Array))
|
186
|
+
data['items'].each do |item|
|
187
|
+
return true if (item[column] == value) && (item['scoutid'] == member_id.to_s)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
return false
|
191
|
+
end
|
79
192
|
|
80
193
|
|
81
194
|
|