Module: EffectiveCpdUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_cpd_user.rb
Overview
EffectiveCpdUser
Mark your user model with effective_cpd_user to get a few helpers And user specific point required scores
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
-
#build_cpd_statement(cpd_cycle:) ⇒ Object
Find or build.
-
#build_cpd_target(cpd_cycle:) ⇒ Object
Find or build.
-
#build_cpd_targets ⇒ Object
For the form.
- #cpd_audit_cpd_required? ⇒ Boolean
- #cpd_audit_reviewer? ⇒ Boolean
-
#cpd_current_statement_completed?(date: nil) ⇒ Boolean
These two are checked by effective memberships for the CPD step.
- #cpd_previous_statement_completed?(date: nil) ⇒ Boolean
- #cpd_statement(cpd_cycle:) ⇒ Object
-
#cpd_target(cpd_cycle:) ⇒ Object
Dont use IDs here.
-
#cpd_target_score(cpd_cycle:) ⇒ Object
The required or targeted number of credits for this user in this cycle.
-
#cpd_target_score_required_to_submit?(cpd_cycle:) ⇒ Boolean
Whether the user can submit a statement without the required number of credits.
-
#default_cpd_target_score(cpd_cycle:) ⇒ Object
Required for this user category without the targets.
-
#default_cpd_target_score_required_to_submit?(cpd_cycle:) ⇒ Boolean
Required for this user category without the targets.
Instance Method Details
#build_cpd_statement(cpd_cycle:) ⇒ Object
Find or build
92 93 94 95 |
# File 'app/models/concerns/effective_cpd_user.rb', line 92 def build_cpd_statement(cpd_cycle:) raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?) cpd_statement(cpd_cycle: cpd_cycle) || cpd_statements.build(cpd_cycle: cpd_cycle) end |
#build_cpd_target(cpd_cycle:) ⇒ Object
Find or build
104 105 106 107 |
# File 'app/models/concerns/effective_cpd_user.rb', line 104 def build_cpd_target(cpd_cycle:) raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?) cpd_target(cpd_cycle: cpd_cycle) || cpd_targets.build(cpd_cycle: cpd_cycle) end |
#build_cpd_targets ⇒ Object
For the form
110 111 112 113 114 |
# File 'app/models/concerns/effective_cpd_user.rb', line 110 def build_cpd_targets Effective::CpdCycle.sorted.all.map do |cpd_cycle| cpd_target(cpd_cycle: cpd_cycle) || cpd_targets.new(cpd_cycle: cpd_cycle) end.sort_by(&:cpd_cycle_id).reverse end |
#cpd_audit_cpd_required? ⇒ Boolean
78 79 80 |
# File 'app/models/concerns/effective_cpd_user.rb', line 78 def cpd_audit_cpd_required? true end |
#cpd_audit_reviewer? ⇒ Boolean
82 83 84 |
# File 'app/models/concerns/effective_cpd_user.rb', line 82 def cpd_audit_reviewer? roles.include?(:cpd_audit_reviewer) end |
#cpd_current_statement_completed?(date: nil) ⇒ Boolean
These two are checked by effective memberships for the CPD step
117 118 119 120 |
# File 'app/models/concerns/effective_cpd_user.rb', line 117 def cpd_current_statement_completed?(date: nil) cpd_cycle = EffectiveCpd.current_cpd_cycle(date: date) cpd_cycle.present? && cpd_statement(cpd_cycle: cpd_cycle).try(:completed?) end |
#cpd_previous_statement_completed?(date: nil) ⇒ Boolean
122 123 124 125 |
# File 'app/models/concerns/effective_cpd_user.rb', line 122 def cpd_previous_statement_completed?(date: nil) cpd_cycle = EffectiveCpd.previous_cpd_cycle(date: date) cpd_cycle.present? && cpd_statement(cpd_cycle: cpd_cycle).try(:completed?) end |
#cpd_statement(cpd_cycle:) ⇒ Object
86 87 88 89 |
# File 'app/models/concerns/effective_cpd_user.rb', line 86 def cpd_statement(cpd_cycle:) raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?) cpd_statements.find { |cpd_statement| cpd_statement.cpd_cycle_id == cpd_cycle.id } end |
#cpd_target(cpd_cycle:) ⇒ Object
Dont use IDs here
98 99 100 101 |
# File 'app/models/concerns/effective_cpd_user.rb', line 98 def cpd_target(cpd_cycle:) raise('expected an CpdCycle') unless cpd_cycle.class.respond_to?(:effective_cpd_cpd_cycle?) cpd_targets.find { |cpd_target| cpd_target.cpd_cycle == cpd_cycle } end |
#cpd_target_score(cpd_cycle:) ⇒ Object
The required or targeted number of credits for this user in this cycle
47 48 49 50 51 52 |
# File 'app/models/concerns/effective_cpd_user.rb', line 47 def cpd_target_score(cpd_cycle:) target = cpd_target(cpd_cycle: cpd_cycle) return target.score if target&.score.present? default_cpd_target_score(cpd_cycle: cpd_cycle) end |
#cpd_target_score_required_to_submit?(cpd_cycle:) ⇒ Boolean
Whether the user can submit a statement without the required number of credits
55 56 57 58 59 60 |
# File 'app/models/concerns/effective_cpd_user.rb', line 55 def cpd_target_score_required_to_submit?(cpd_cycle:) target = cpd_target(cpd_cycle: cpd_cycle) return target.required_to_submit? unless target&.required_to_submit.nil? default_cpd_target_score_required_to_submit?(cpd_cycle: cpd_cycle) end |
#default_cpd_target_score(cpd_cycle:) ⇒ Object
Required for this user category without the targets. Used to display defaults on admin form.
63 64 65 66 67 68 69 70 71 |
# File 'app/models/concerns/effective_cpd_user.rb', line 63 def default_cpd_target_score(cpd_cycle:) if self.class.try(:effective_memberships_user?) category = membership_categories_on(cpd_cycle.start_at)&.first if cpd_cycle.start_at.present? category ||= membership_categories_on(cpd_cycle.end_at)&.first if cpd_cycle.end_at.present? category ||= membership&.categories&.first category&.cpd_target_score(cpd_cycle: cpd_cycle) end end |
#default_cpd_target_score_required_to_submit?(cpd_cycle:) ⇒ Boolean
Required for this user category without the targets. Used to display defaults on admin form.
74 75 76 |
# File 'app/models/concerns/effective_cpd_user.rb', line 74 def default_cpd_target_score_required_to_submit?(cpd_cycle:) cpd_cycle.required_to_submit? end |