Class: Course::Settings::Notifications

Inherits:
Object
  • Object
show all
Defined in:
app/models/course/settings/notifications.rb

Overview

This model facilitates displaying and setting of notification settings.

To add email notification settings to a course component, ensure that these two methods are defined on the component's setting model (see ControllerComponentHost::Settings::ClassMethods#settings_class):

Instance Method Summary collapse

Constructor Details

#initialize(components) ⇒ Notifications


13
14
15
# File 'app/models/course/settings/notifications.rb', line 13

def initialize(components)
  @components = components
end

Instance Method Details

#email_settingsArray<Hash>

Consolidates email settings from each course component. Each setting item should be a hash in the format similar to the this example:

{
  component: :course_assessments_component, # Component key
  key: :new_assignment,         # Email setting key
  enabled: true,                # The user's setting, otherwise, the default setting
  component_title: 'Quests',    # [Optional] Title to be displayed as the (sub)component's name
  options: { category_id: 5 },  # [Optional] Other info for the setting
}

31
32
33
34
35
36
37
38
# File 'app/models/course/settings/notifications.rb', line 31

def email_settings
  all_settings = settings_interfaces_hash.values.map do |settings|
    settings.respond_to?(:email_settings) ? settings.email_settings : nil
  end
  all_settings.compact.flatten.sort_by do |item|
    [item[:component], item[:component_title], item[:key]]
  end
end

#update(attributes) ⇒ Boolean

Updates a single email setting. It delegates the updating to the appropriate settings model. The attributes hash is expected to have the following shape:

{
  'component' => 'course_assessments_component', # Component key
  'key' => 'new_assignment',           # Email setting key
  'enabled' => false,                  # The new setting
  'options' => { 'category_id' => 5 }, # [Optional] Other info for the setting
}

54
55
56
57
58
# File 'app/models/course/settings/notifications.rb', line 54

def update(attributes)
  settings_interface = settings_interfaces_hash[attributes['component']]
  return false unless settings_interface
  settings_interface.update_email_setting(attributes)
end