Class: Decidim::Admin::NewsletterRecipients
- Inherits:
-
Query
- Object
- Query
- Decidim::Admin::NewsletterRecipients
- Defined in:
- app/queries/decidim/admin/newsletter_recipients.rb
Overview
A class used to find the recipients of the Newsletter depending on the params of the form
Class Method Summary collapse
-
.for(form) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
Instance Method Summary collapse
-
#initialize(form) ⇒ NewsletterRecipients
constructor
Initializes the class.
- #query ⇒ Object
Constructor Details
#initialize(form) ⇒ NewsletterRecipients
Initializes the class.
form - params to filter the query
18 19 20 |
# File 'app/queries/decidim/admin/newsletter_recipients.rb', line 18 def initialize(form) @form = form end |
Class Method Details
.for(form) ⇒ Object
Syntactic sugar to initialize the class and return the queried objects.
form - params to filter the query
11 12 13 |
# File 'app/queries/decidim/admin/newsletter_recipients.rb', line 11 def self.for(form) new(form).query end |
Instance Method Details
#query ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/queries/decidim/admin/newsletter_recipients.rb', line 22 def query recipients = Decidim::User.where(organization: @form.current_organization) .where.not(newsletter_notifications_at: nil) .where.not(email: nil) .where.not(confirmed_at: nil) .not_deleted recipients = recipients.interested_in_scopes(@form.scope_ids) if @form.scope_ids.present? followers = recipients.where(id: user_id_of_followers) if @form.send_to_followers participants = recipients.where(id: participant_ids) if @form.send_to_participants recipients = participants if @form.send_to_participants recipients = followers if @form.send_to_followers recipients = (followers + participants).uniq if @form.send_to_followers && @form.send_to_participants recipients end |