-
Notifications
You must be signed in to change notification settings - Fork 482
/
facilitator_application_base.rb
451 lines (383 loc) · 14.4 KB
/
facilitator_application_base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
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
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
220
221
222
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
276
277
278
279
280
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# == Schema Information
#
# Table name: pd_applications
#
# id :integer not null, primary key
# user_id :integer
# type :string(255) not null
# application_year :string(255) not null
# application_type :string(255) not null
# regional_partner_id :integer
# status :string(255)
# locked_at :datetime
# notes :text(65535)
# form_data :text(65535) not null
# created_at :datetime not null
# updated_at :datetime not null
# course :string(255)
# response_scores :text(65535)
# application_guid :string(255)
# accepted_at :datetime
# properties :text(65535)
# deleted_at :datetime
# status_timestamp_change_log :text(65535)
#
# Indexes
#
# index_pd_applications_on_application_guid (application_guid)
# index_pd_applications_on_application_type (application_type)
# index_pd_applications_on_application_year (application_year)
# index_pd_applications_on_course (course)
# index_pd_applications_on_regional_partner_id (regional_partner_id)
# index_pd_applications_on_status (status)
# index_pd_applications_on_type (type)
# index_pd_applications_on_user_id (user_id)
#
module Pd::Application
class FacilitatorApplicationBase < WorkshopAutoenrolledApplication
include Pd::FacilitatorCommonApplicationConstants
serialized_attrs %w(
fit_workshop_id
auto_assigned_fit_enrollment_id
question_1
question_2
question_3
question_4
question_5
question_6
question_7
)
# Implement in derived class.
# @return a valid year (see ApplicationConstants.APPLICATION_YEARS)
def year
raise 'Abstract method must be overridden by inheriting class'
end
# @override
def set_type_and_year
self.application_type = FACILITATOR_APPLICATION
self.application_year = year
end
PROGRAMS = {
csf: 'CS Fundamentals',
csd: 'CS Discoveries',
csp: 'CS Principles'
}.freeze
VALID_COURSES = PROGRAMS.keys.map(&:to_s)
YES_COMMIT = 'Yes, I can commit to this requirement'
NO_COMMIT = "No, I can't commit to this requirement"
validates :course, presence: true, inclusion: {in: VALID_COURSES}
before_validation :set_course_from_program
def set_course_from_program
self.course = PROGRAMS.key(program)
end
before_create :match_partner, if: -> {regional_partner.nil?}
def match_partner
self.regional_partner = RegionalPartner.find_by_region(zip_code, state_code)
end
def fit_workshop
return nil unless fit_workshop_id
# attempt to retrieve from cache
cache_fetch self.class.get_workshop_cache_key(fit_workshop_id) do
Pd::Workshop.includes(:sessions, :enrollments).find_by(id: fit_workshop_id)
end
end
def fit_workshop_date_and_location
fit_workshop.try(&:date_and_location_name)
end
def log_fit_workshop_change(user)
update_status_timestamp_change_log(user, "Fit Workshop: #{fit_workshop_id ? fit_workshop_date_and_location : 'Unassigned'}")
end
def registered_fit_workshop?
# inspect the cached fit_workshop.enrollments rather than querying the DB
fit_workshop.enrollments.any? {|e| e.user_id == user.id} if fit_workshop_id
end
def self.options
{
title: COMMON_OPTIONS[:title],
state: COMMON_OPTIONS[:state],
gender_identity: COMMON_OPTIONS[:gender_identity],
race: COMMON_OPTIONS[:race],
institution_type: [
'School district',
'Non-profit',
'Institute of higher education',
'Tech company',
TEXT_FIELDS[:other_with_text]
],
how_heard: [
'Code.org email',
'Code.org social media post',
TEXT_FIELDS[:how_heard_facilitator],
TEXT_FIELDS[:how_heard_code_org_staff],
TEXT_FIELDS[:how_heard_regional_partner],
'My employer',
TEXT_FIELDS[:other_with_text]
],
plan_on_teaching: [
YES,
NO,
"I don't know yet",
TEXT_FIELDS[:other_with_text]
],
teaching_experience: [
'Yes, I am a current classroom teacher',
'Yes. I am not currently a classroom teacher, but I have taught in a classroom in the past.',
'No, I do not have classroom teaching experience'
],
currently_involved_in_cs_education: [
'I teach CS courses for credit to K-12, community college, or university students',
'I teach CS courses in a CS bootcamp program',
'I lead an afterschool or enrichment program focused on CS',
'I advocate for CS education within my community',
'I work at an organization that supports CS education advocacy and access',
'I am not currently involved with CS education',
TEXT_FIELDS[:other_please_describe]
],
grades_taught: [
'Elementary school',
'Middle school ',
'High school ',
'Post-secondary ',
"N/A: I don't have classroom teaching experience"
],
experience_teaching_this_course: [
'Yes, to elementary school students',
'Yes, to middle school students',
'Yes, to high school students',
'I do not have experience teaching this curriculum to students, but I do have experience teaching a different CS curriculum to students',
'I do not have experience teaching any CS curriculum to students',
],
csf_previous_workshop: [
'Yes, I have attended a Code.org CS Fundamentals workshop.',
'I have attended a Code.org workshop, but for a different curriculum.',
'No, I have not attended a Code.org workshop.'
],
csd_csp_completed_pd: [
'Yes, I have participated in the Code.org Professional Learning Program for this curriculum.',
'I have participated in the Code.org Professional Learning Program, but for a different curriculum.',
'No, I have not participated in a Code.org Professional Learning Program for any curriculum.',
],
facilitator_availability: [
'Weekdays during the school year',
'Weekdays during the summer',
'Saturdays during the school year',
'Saturdays during the summer',
'Sundays during the school year',
'Sundays during the summer',
TEXT_FIELDS[:other_with_text]
],
csf_good_standing_requirement: [YES_COMMIT, NO_COMMIT],
code_org_facilitator: [YES, NO],
code_org_facilitator_years: [
'2014-15 school year',
'2015-16 school year',
'2016-17 school year',
'2017-18 school year',
'2018-19 school year',
TEXT_FIELDS[:other_with_text]
],
code_org_facilitator_programs: [
'CS Fundamentals',
'CS Discoveries',
'CS Principles',
'CS in Algebra',
'CS in Science',
'Exploring Computer Science',
TEXT_FIELDS[:other_with_text]
],
have_led_adults: [YES, NO],
csf_summit_requirement: [YES_COMMIT, NO_COMMIT],
csf_workshop_requirement: [YES_COMMIT, NO_COMMIT],
csf_community_requirement: [YES_COMMIT, NO_COMMIT],
csd_csp_fit_weekend_requirement: [YES_COMMIT, NO_COMMIT],
csd_csp_workshop_requirement: [YES_COMMIT, NO_COMMIT],
csd_training_requirement: [YES_COMMIT, NO_COMMIT],
csp_training_requirement: [YES_COMMIT, NO_COMMIT],
csd_csp_lead_summer_workshop_requirement: [YES_COMMIT, NO_COMMIT],
csd_csp_deeper_learning_requirement: [YES_COMMIT, NO_COMMIT],
development_and_preparation_requirement: [YES_COMMIT, NO_COMMIT],
csd_csp_good_standing_requirement: [YES_COMMIT, NO_COMMIT],
csd_csp_no_partner_summer_workshop: [
'Yes, I understand that I must commit to a 5-day summer workshop. If I am assigned to a nearby Regional Partner, I will coordinate with Code.org once dates are finalized.'
],
csd_csp_partner_but_no_summer_workshop: [
'Yes, I understand that I must commit to a 5-day summer workshop. I will coordinate with Code.org once dates are finalized.'
],
csd_csp_partner_with_summer_workshop: [YES_COMMIT, NO_COMMIT],
}
end
def self.required_fields
%i(
first_name
last_name
phone
address
city
state
zip_code
institution_type
current_employer
job_title
program
code_org_facilitator
teaching_experience
have_led_adults
development_and_preparation_requirement
currently_involved_in_cs_education
grades_taught
experience_teaching_this_course
plan_on_teaching
facilitator_availability
why_should_all_have_access
skills_areas_to_improve
inquiry_based_learning
why_interested
gender_identity
race
agree
)
end
def dynamic_required_fields(hash)
[].tap do |required|
if hash[:code_org_facilitator] == YES
required.concat [
:code_org_facilitator_years,
:code_org_facilitator_programs
]
end
if hash[:program] == PROGRAMS[:csf]
required.concat [
:csf_summit_requirement,
:csf_workshop_requirement,
:csf_community_requirement,
:csf_previous_workshop,
:csf_good_standing_requirement
]
end
if hash[:program] != PROGRAMS[:csf]
if !hash[:regional_partner_id]
required << :csd_csp_no_partner_summer_workshop
else
if hash[:summer_workshops] && !hash[:summer_workshops].empty?
required.concat [
:csd_csp_partner_with_summer_workshop,
:csd_csp_which_summer_workshop
]
else
required << :csd_csp_partner_but_no_summer_workshop
end
if hash[:fit_workshops] && !hash[:fit_workshops].empty?
required << :csd_csp_which_fit_weekend
end
end
required.concat [
:csd_csp_fit_weekend_requirement,
:csd_csp_workshop_requirement,
:csd_csp_lead_summer_workshop_requirement,
:csd_csp_deeper_learning_requirement,
:csd_csp_completed_pd,
:csd_csp_good_standing_requirement
]
end
if hash[:program] == PROGRAMS[:csd]
required << :csd_training_requirement
end
if hash[:program] == PROGRAMS[:csp]
required << :csp_training_requirement
end
end
end
def first_name
sanitize_form_data_hash[:first_name]
end
def last_name
sanitize_form_data_hash[:last_name]
end
def program
sanitize_form_data_hash[:program]
end
def zip_code
sanitize_form_data_hash[:zip_code]
end
def state_name
sanitize_form_data_hash[:state]
end
def state_code
STATE_ABBR_WITH_DC_HASH.key(state_name).try(:to_s)
end
# Include additional text for all the multi-select fields that have the option
def additional_text_fields
[
[:institution_type],
[:code_org_facilitator_years],
[:code_org_facilitator_programs],
[:csd_csp_which_summer_workshop, TEXT_FIELDS[:not_sure_please_explain], :csd_csp_which_summer_workshop_not_sure],
[:csd_csp_which_summer_workshop, TEXT_FIELDS[:unable_to_attend_please_explain], :csd_csp_which_summer_workshop_unable_to_attend],
[:csd_csp_which_fit_weekend, TEXT_FIELDS[:not_sure_please_explain], :csd_csp_which_fit_weekend_not_sure],
[:csd_csp_which_fit_weekend, TEXT_FIELDS[:unable_to_attend_please_explain], :csd_csp_which_fit_weekend_unable_to_attend],
[:currently_involved_in_cs_education, TEXT_FIELDS[:other_please_describe]],
[:plan_on_teaching],
[:facilitator_availability],
[:how_heard, TEXT_FIELDS[:how_heard_facilitator], :how_heard_facilitator],
[:how_heard, TEXT_FIELDS[:how_heard_code_org_staff], :how_heard_code_org_staff],
[:how_heard, TEXT_FIELDS[:how_heard_regional_partner], :how_heard_regional_partner],
[:how_heard]
]
end
# @override
# Add account_email (based on the associated user's email) to the sanitized form data hash
def sanitize_form_data_hash
super.merge(account_email: user.email)
end
before_save :destroy_fit_autoenrollment, if: -> {status_changed? && status != "accepted"}
def destroy_fit_autoenrollment
return unless auto_assigned_fit_enrollment_id
Pd::Enrollment.find_by(id: auto_assigned_fit_enrollment_id).try(:destroy)
self.auto_assigned_fit_enrollment_id = nil
end
# override
def enroll_user
super
return unless fit_workshop_id
enrollment = Pd::Enrollment.where(
pd_workshop_id: fit_workshop_id,
email: user.email
).first_or_initialize
# If this is a new enrollment, we want to:
# - save it with all required data
# - save a reference to it in properties
# - delete the previous auto-created enrollment if it exists
if enrollment.new_record?
enrollment.update(
user: user,
school_info: user.school_info,
full_name: user.name
)
enrollment.save!
destroy_fit_autoenrollment
self.auto_assigned_fit_enrollment_id = enrollment.id
end
end
# Assigns the default FiT workshop, if one is not yet assigned
def assign_default_fit_workshop!
return if fit_workshop_id
update! fit_workshop_id: find_default_fit_workshop.try(:id)
end
def find_default_fit_workshop
return unless regional_partner
find_fit_workshop(
course: workshop_course,
city: find_default_fit_teachercon[:city]
)
end
# override
def self.prefetch_associated_models(applications)
# also prefetch fit workshops
prefetch_workshops applications.flat_map {|a| [a.pd_workshop_id, a.fit_workshop_id]}.uniq.compact
end
# @override
def self.can_see_locked_status?(user)
true
end
end
end