Class Article
In: app/models/article.rb
Parent: ActiveRecord::Base

Methods

Public Class methods

[Source]

     # File app/models/article.rb, line 138
138:   def self.description
139:     raise NotImplementedError, "#{self} does not implement #description"
140:   end

retrives the most commented articles, sorted by the comment count (largest first)

[Source]

     # File app/models/article.rb, line 102
102:   def self.most_commented(limit)
103:     find(:all, :order => 'comments_count DESC', :limit => limit)
104:   end

retrieves the latest limit articles, sorted from the most recent to the oldest.

Only includes articles where advertise == true

[Source]

    # File app/models/article.rb, line 79
79:   def self.recent(limit)
80:     # FIXME this method is a horrible hack
81:     options = { :limit => limit,
82:                 :conditions => {
83:                   :advertise => true,
84:                   :public_article => true,
85:                   :published => true,
86:                   'profiles.public_profile' => true
87:                 },
88:                 :include => 'profile',
89:                 :order => 'articles.created_at desc, articles.id desc'
90:               }
91:     if ( scoped_methods && scoped_methods.last &&
92:          scoped_methods.last[:find] &&
93:          scoped_methods.last[:find][:joins] &&
94:          scoped_methods.last[:find][:joins].index('profiles') )
95:       options.delete(:include)
96:     end
97:     self.find(:all, options)
98:   end

[Source]

     # File app/models/article.rb, line 142
142:   def self.short_description
143:     raise NotImplementedError, "#{self} does not implement #short_description"
144:   end

retrieves all articles belonging to the given profile that are not sub-articles of any other article.

[Source]

    # File app/models/article.rb, line 71
71:   def self.top_level_for(profile)
72:     self.find(:all, :conditions => [ 'parent_id is null and profile_id = ?', profile.id ])
73:   end

Public Instance methods

[Source]

     # File app/models/article.rb, line 178
178:   def accept_category?(cat)
179:     !cat.is_a?(ProductCategory)
180:   end

[Source]

    # File app/models/article.rb, line 22
22:   def add_category(c)
23:     if self.id
24:       ArticleCategorization.add_category_to_article(c, self)
25:     else
26:       pending_categorizations << c
27:     end
28:   end

[Source]

     # File app/models/article.rb, line 154
154:   def allow_children?
155:     true
156:   end

[Source]

     # File app/models/article.rb, line 192
192:   def article_attr_blacklist
193:     ['id', 'profile_id', 'parent_id', 'slug', 'path', 'updated_at', 'created_at', 'last_changed_by_id', 'version', 'lock_version', 'type', 'children_count', 'comments_count']
194:   end

[Source]

    # File app/models/article.rb, line 30
30:   def category_ids=(ids)
31:     ArticleCategorization.remove_all_for(self)
32:     ids.uniq.each do |item|
33:       add_category(Category.find(item))
34:     end
35:   end

[Source]

    # File app/models/article.rb, line 61
61:   def comment_data
62:     comments.map {|item| [item.title, item.body].join(' ') }.join(' ')
63:   end

[Source]

     # File app/models/article.rb, line 174
174:   def comments_updated
175:     ferret_update
176:   end

[Source]

     # File app/models/article.rb, line 186
186:   def copy(options)
187:     attrs = attributes.reject! { |key, value| article_attr_blacklist.include?(key) }
188:     attrs.merge!(options)
189:     self.class.create(attrs)
190:   end

[Source]

    # File app/models/article.rb, line 38
38:   def create_pending_categorizations
39:     pending_categorizations.each do |item|
40:       ArticleCategorization.add_category_to_article(item, self)
41:     end
42:     pending_categorizations.clear
43:   end

returns the data of the article. Must be overriden in each subclass to provide the correct content for the article.

[Source]

     # File app/models/article.rb, line 117
117:   def data
118:     body
119:   end

[Source]

     # File app/models/article.rb, line 162
162:   def display_to?(user)
163:     if self.public_article
164:       self.profile.display_info_to?(user)
165:     else
166:       if user.nil?
167:         false
168:       else
169:         (user == self.profile) || user.memberships.include?(self.profile) || (profile.kind_of?(Person) && profile.friends.include?(user))
170:       end
171:     end
172:   end

[Source]

     # File app/models/article.rb, line 158
158:   def folder?
159:     false
160:   end

provides the icon name to be used for this article. In this class this method just returns ‘text-html’, but subclasses may (and should) override to return their specific icons.

FIXME use mime_type and generate this name dinamically

[Source]

     # File app/models/article.rb, line 126
126:   def icon_name
127:     'text-html'
128:   end

[Source]

     # File app/models/article.rb, line 130
130:   def mime_type
131:     'text/html'
132:   end

[Source]

     # File app/models/article.rb, line 134
134:   def mime_type_description
135:     _('HTML Text document')
136:   end

[Source]

    # File app/models/article.rb, line 18
18:   def pending_categorizations
19:     @pending_categorizations ||= []
20:   end

[Source]

     # File app/models/article.rb, line 182
182:   def public?
183:     profile.public? && public_article
184:   end

[Source]

     # File app/models/article.rb, line 146
146:   def title
147:     name
148:   end

produces the HTML code that is to be displayed as this article‘s contents.

The implementation in this class just provides the body attribute as the HTML. Other article types can override this method to provide customized views of themselves.

[Source]

     # File app/models/article.rb, line 111
111:   def to_html
112:     body
113:   end

[Source]

     # File app/models/article.rb, line 150
150:   def url
151:     self.profile.url.merge(:page => path.split('/'))
152:   end

[Validate]