Class: Content
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Content
- Includes:
- ActiveModel::ForbiddenAttributesProtection, PublicActivity::Common
- Defined in:
- app/models/content.rb
Direct Known Subclasses
ClientTime, DynamicContent, Graphic, HtmlText, Ticker, TimeDisplay
Class Method Summary (collapse)
- + (Object) active
-
+ (Object) all_subclasses
All the subclasses of Content.
-
+ (Object) display_name
Display the pretty name of the content type.
-
+ (Object) expired
Easily query for active, expired, or future content The scopes are defined as class methods to delay their resolution, defining them as proper scopes will break lots of things, see github.com/concerto/concerto/issues/288.
-
+ (Object) form_attributes
Define the attributes that will be allowed via strong_parameters.
- + (Object) future
-
+ (Object) preview(*arg)
Allow the subclasses to render a preview of their content.
Instance Method Summary (collapse)
-
- (Boolean) action_allowed?(action_name, user)
Figure out if a user should be able to run a custom action.
-
- (Object) after_add_callback(unused_submission)
A placeholder for any action that should be performed after content has been submitted to a feed.
-
- (Object) end_time=(_end_time)
See start_time=.
-
- (Boolean) has_children?
A quick test to see if a content has any children.
-
- (Boolean) is_active?
Determine if content is active based on its start and end times.
-
- (Boolean) is_approved?
Determine if content is approved everywhere.
-
- (Boolean) is_denied?
Determine if content is denied on a feed.
-
- (Boolean) is_expired?
Determine if content is expired based on its end time.
- - (Boolean) is_orphan?
-
- (Boolean) is_pending?
Determine if content is pending on a feed.
- - (Object) parent_id_cannot_be_this_content
-
- (Object) perform_action(action_name, options)
Perform custom actions on a piece of content.
-
- (Object) pre_render(*arg)
A placeholder for a pre-rendering processing trigger.
-
- (Object) render_details
The additional data required when rendering this content.
-
- (Object) start_time=(_start_time)
Setter for the start time.
Class Method Details
+ (Object) active
45 46 47 |
# File 'app/models/content.rb', line 45 def self.active where("(start_time IS NULL OR start_time < :now) AND (end_time IS NULL OR end_time > :now)", {:now => Clock.time}) end |
+ (Object) all_subclasses
All the subclasses of Content. Conduct a DFS walk of the Content class tree and return the results. This is important because DynamicContent is always 1 step removed from content (Content > DynamicContent > Rss).
142 143 144 145 146 147 148 149 |
# File 'app/models/content.rb', line 142 def self.all_subclasses sub = [] sub.concat(self.subclasses) self.subclasses.each do |subklass| sub.concat(subklass.all_subclasses) end return sub end |
+ (Object) display_name
Display the pretty name of the content type.
152 153 154 155 156 157 158 |
# File 'app/models/content.rb', line 152 def self.display_name if self.const_defined?("DISPLAY_NAME") && !self::DISPLAY_NAME.nil? self::DISPLAY_NAME else self.model_name.human end end |
+ (Object) expired
Easily query for active, expired, or future content The scopes are defined as class methods to delay their resolution, defining them as proper scopes will break lots of things, see github.com/concerto/concerto/issues/288.
39 40 41 |
# File 'app/models/content.rb', line 39 def self.expired where("end_time < :now", {:now => Clock.time}) end |
+ (Object) form_attributes
Define the attributes that will be allowed via strong_parameters. We define a common set of attribtues here, expecting child content types to supplement this list with additional attributes that they require.
134 135 136 |
# File 'app/models/content.rb', line 134 def self.form_attributes attributes = [:name, :duration, :data, {:start_time => [:time, :date]}, {:end_time => [:time, :date]}] end |
+ (Object) future
42 43 44 |
# File 'app/models/content.rb', line 42 def self.future where("start_time > :now", {:now => Clock.time}) end |
+ (Object) preview(*arg)
Allow the subclasses to render a preview of their content
122 123 124 |
# File 'app/models/content.rb', line 122 def self.preview(*arg) "" end |
Instance Method Details
- (Boolean) action_allowed?(action_name, user)
Figure out if a user should be able to run a custom action. Default to any user runs no actions.
162 163 164 |
# File 'app/models/content.rb', line 162 def action_allowed?(action_name, user) return false end |
- (Object) after_add_callback(unused_submission)
A placeholder for any action that should be performed after content has been submitted to a feed.
179 180 |
# File 'app/models/content.rb', line 179 def after_add_callback(unused_submission) end |
- (Object) end_time=(_end_time)
See start_time=.
102 103 104 105 106 107 108 |
# File 'app/models/content.rb', line 102 def end_time=(_end_time) if _end_time.kind_of?(Hash) write_attribute(:end_time, DateTime.strptime("#{_end_time[:date]} #{_end_time[:time]}","%m/%d/%Y %l:%M %p").to_s(:db)) else write_attribute(:end_time, _end_time) end end |
- (Boolean) has_children?
A quick test to see if a content has any children
127 128 129 |
# File 'app/models/content.rb', line 127 def has_children? !self.children.empty? end |
- (Boolean) is_active?
Determine if content is active based on its start and end times. Content is active if two conditions are met:
-
Start date is before now, or nil.
-
End date is after now, or nil.
61 62 63 |
# File 'app/models/content.rb', line 61 def is_active? (start_time.nil? || start_time < Clock.time) && (end_time.nil? || end_time > Clock.time) end |
- (Boolean) is_approved?
Determine if content is approved everywhere
75 76 77 |
# File 'app/models/content.rb', line 75 def is_approved? (self.approved_feeds.count > 0) && ((self.pending_feeds.count + self.denied_feeds.count) == 0) end |
- (Boolean) is_denied?
Determine if content is denied on a feed
85 86 87 |
# File 'app/models/content.rb', line 85 def is_denied? (self.denied_feeds.count > 0) end |
- (Boolean) is_expired?
Determine if content is expired based on its end time.
66 67 68 |
# File 'app/models/content.rb', line 66 def is_expired? (end_time < Clock.time) end |
- (Boolean) is_orphan?
70 71 72 |
# File 'app/models/content.rb', line 70 def is_orphan? self.submissions.empty? end |
- (Boolean) is_pending?
Determine if content is pending on a feed
80 81 82 |
# File 'app/models/content.rb', line 80 def is_pending? (self.pending_feeds.count > 0) end |
- (Object) parent_id_cannot_be_this_content
19 20 21 22 23 |
# File 'app/models/content.rb', line 19 def parent_id_cannot_be_this_content if !parent_id.blank? and parent_id == id errors.add(:parent_id, "can't be this content") end end |
- (Object) perform_action(action_name, options)
Perform custom actions on a piece of content. Accessed via /content/:id/act?action_name=action_name&options. Returns nil if there was a problem, otherwise return the result of the action.
169 170 171 172 173 174 175 |
# File 'app/models/content.rb', line 169 def perform_action(action_name, ) if action_allowed?(action_name, [:current_user]) return send(action_name, ) else return nil end end |
- (Object) pre_render(*arg)
A placeholder for a pre-rendering processing trigger.
112 113 114 |
# File 'app/models/content.rb', line 112 def pre_render(*arg) true end |
- (Object) render_details
The additional data required when rendering this content.
117 118 119 |
# File 'app/models/content.rb', line 117 def render_details {:data => self.data} end |
- (Object) start_time=(_start_time)
Setter for the start time. If a hash is passed, convert that into a DateTime object and then a string. Otherwise, just set it like normal. This is a bit confusing due to the differences in how Ruby handles times between 1.9.x and 1.8.x.
92 93 94 95 96 97 98 99 |
# File 'app/models/content.rb', line 92 def start_time=(_start_time) if _start_time.kind_of?(Hash) #write_attribute(:start_time, Time.parse("#{_start_time[:date]} #{_start_time[:time]}").to_s(:db)) write_attribute(:start_time, DateTime.strptime("#{_start_time[:date]} #{_start_time[:time]}","%m/%d/%Y %l:%M %p").to_s(:db)) else write_attribute(:start_time, _start_time) end end |