Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 124 lines (94 sloc) 3.402 kB
29df04d Adding base admin moderation
Russell Branca authored
1 require 'active_record'
2
3 module Newscloud
4 module ActiverecordModelExtensions
5
6 def self.included(base)
7 base.send :extend, ClassMethods
8
9 base.send :include, InstanceMethods
10 end
11
12 module ClassMethods
13
8a61078 Added acts as refineable, ajax loading of refined lists, javascript e…
Russell Branca authored
14 def refineable?
15 false
16 end
17
6912061 Switching to using top items algorithm
Russell authored
18 def top_items limit = 100
3f024d6 Adding top items scoring methods
Russell Branca authored
19 # TODO:: this needs work
20 return self.all(:order => "created_at desc", :limit => limit) unless self.columns.select {|col| col.name == 'votes_tally'}
21
22 table = self.name.tableize
870d8c0 @chewbranca Updating top items algorithm to work with utc time
chewbranca authored
23 now = Time.now.utc.strftime("%Y-%m-%d %H:%M:%S")
3f024d6 Adding top items scoring methods
Russell Branca authored
24 # HACK ALERT
25 # This will return an ordered set of results based on number of votes and time since posting
6912061 Switching to using top items algorithm
Russell authored
26 if self.columns.select {|col| col.name == 'is_blocked'}
870d8c0 @chewbranca Updating top items algorithm to work with utc time
chewbranca authored
27 self.find_by_sql %{SELECT ((1 + (votes_tally * 2)) / (((UNIX_TIMESTAMP("#{now}") - UNIX_TIMESTAMP(created_at)) / 3600) + 5)) AS item_score, #{table}.* FROM #{table} JOIN (SELECT ID FROM #{table} WHERE is_blocked = 0 ORDER BY created_at DESC LIMIT 100) AS sub_#{table} ON #{table}.id = sub_#{table}.id ORDER BY item_score DESC LIMIT #{limit};}
6912061 Switching to using top items algorithm
Russell authored
28 else
870d8c0 @chewbranca Updating top items algorithm to work with utc time
chewbranca authored
29 self.find_by_sql %{SELECT ((1 + (votes_tally * 2)) / (((UNIX_TIMESTAMP("#{now}") - UNIX_TIMESTAMP(created_at)) / 3600) + 5)) AS item_score, #{table}.* FROM #{table} JOIN (SELECT ID FROM #{table} ORDER BY created_at DESC LIMIT 100) AS sub_#{table} ON #{table}.id = sub_#{table}.id ORDER BY item_score DESC LIMIT #{limit};}
6912061 Switching to using top items algorithm
Russell authored
30 end
31 #self.find_by_sql %{SELECT ((1 + (votes_tally * 2)) / (((UNIX_TIMESTAMP("2010-03-23 14:20:24") - UNIX_TIMESTAMP(created_at)) / 3600) + 5)) AS item_score, #{table}.* FROM #{table} JOIN (SELECT ID FROM #{table} ORDER BY created_at DESC LIMIT 100) AS sub_#{table} ON #{table}.id = sub_#{table}.id ORDER BY item_score DESC LIMIT #{limit};}
3f024d6 Adding top items scoring methods
Russell Branca authored
32 end
33
29df04d Adding base admin moderation
Russell Branca authored
34 end
35
36 module InstanceMethods
37
6912061 Switching to using top items algorithm
Russell authored
38 # Misc continuity methods for working with mixins
50c7222 adds acts as wall postable mixin
Jeff Reifman authored
39 def wall_postable?
40 false
41 end
42
29df04d Adding base admin moderation
Russell Branca authored
43 def moderatable?
44 false
45 end
46
8a61078 Added acts as refineable, ajax loading of refined lists, javascript e…
Russell Branca authored
47 def refineable?
48 false
49 end
50
51 def featured_item?
52 false
53 end
54
e57266d Adding paperclip, images, videos, acts_as_media_item, initial commit
Russell Branca authored
55 def media_item?
56 false
57 end
58
59 def image_item?
60 false
61 end
62
63 def video_item?
64 false
65 end
66
67 def audio_item?
68 false
69 end
70
6912061 Switching to using top items algorithm
Russell authored
71 def downvoteable?
72 false
73 end
74
870d8c0 @chewbranca Updating top items algorithm to work with utc time
chewbranca authored
75 # model unique identifier
76 def muid
77 "#{self.class.name.underscore}_#{self.id}"
78 end
79
22dfa51 add form feed post checkbox after comments
Jeff Reifman authored
80 def item_link
81 self
82 end
49f14ac patching wall postable mixin
Jeff Reifman authored
83
84 def wall_caption
85 return ''
86 end
f60426a updated attachment and titling in stream feed form attachments
Jeff Reifman authored
87
131e300 Adding default model titles. (Ticket: #69)
Russell Branca authored
88 def item_title
89 [:title, :name, :question].each do |method|
90 return self.send(method) if self.respond_to?(method) and self.send(method).present?
91 end
92 "#{self.class.name.titleize} ##{self.id}"
93 end
94
223e916 Updating fb_share to include meta info
Russell authored
95 def item_description
96 [:description, :caption, :blurb, :details, :details].each do |method|
97 return self.send(method) if self.respond_to?(method) and self.send(method).present?
98 end
99 "#{self.class.name.titleize} ##{self.id}"
100 end
101
862b52a @chewbranca Initial forums commit
chewbranca authored
102 # Breadcrumb parents method
103 # Overwrite as [self.story.crumb_items]
104 def crumb_parents
105 []
106 end
107
108 def crumb_items
109 [self, self.crumb_parents].flatten
110 end
111
112 def crumb_text
113 self.item_title
114 end
115
116 def crumb_link
117 self
118 end
119
29df04d Adding base admin moderation
Russell Branca authored
120 end
121
122 end
123 end
Something went wrong with that request. Please try again.