Class: CmsPost
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CmsPost
- Extended by:
- FriendlyId
- Includes:
- DmCore::Concerns::FriendlyId
- Defined in:
- app/models/cms_post.rb
Instance Method Summary collapse
-
#async_send_notification_emails(user_list) ⇒ Object
——————————————————————————.
-
#comments_allowed? ⇒ Boolean
Allow comments if also enabled in the blog ——————————————————————————.
-
#is_published? ⇒ Boolean
——————————————————————————.
-
#model_slug ⇒ Object
Base the slug on the default locale ——————————————————————————.
-
#send_notification_emails(test_user = nil) ⇒ Object
Send post notification to any members and followers.
Instance Method Details
#async_send_notification_emails(user_list) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/cms_post.rb', line 64 def async_send_notification_emails(user_list) success = failed = 0 Rails.logger.info "=== Sending #{user_list.size} emails for blog post '#{title}'" user_list.each do |user| email = PostNotifyMailer.post_notify(user, self, self.account).deliver_later success += 1 if email failed += 1 if email.nil? end update_attribute(:notification_sent_on, Time.now) Rails.logger.info " Completed sending: successes (#{success}) -- failures (#{failed}) " end |
#comments_allowed? ⇒ Boolean
Allow comments if also enabled in the blog
42 43 44 |
# File 'app/models/cms_post.rb', line 42 def comments_allowed? cms_blog.comments_allowed? && comments_allowed end |
#is_published? ⇒ Boolean
36 37 38 |
# File 'app/models/cms_post.rb', line 36 def is_published? !published_on.nil? && published_on <= Time.now end |
#model_slug ⇒ Object
Base the slug on the default locale
31 32 33 |
# File 'app/models/cms_post.rb', line 31 def model_slug send("title_#{Account.current.preferred_default_locale}") end |
#send_notification_emails(test_user = nil) ⇒ Object
Send post notification to any members and followers. Updates the :notification_sent_on column after emails sent. Use ‘sets’ to only end up with a unique list of users
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/cms_post.rb', line 50 def send_notification_emails(test_user = nil) if test_user email = PostNotifyMailer.post_notify(test_user, self, self.account).deliver_now return (email ? 1 : 0) else user_list = cms_blog.member_list(:all).to_set cms_blog.followers.each {|follower| user_list << follower.user} async_send_notification_emails(user_list) return user_list.size end end |