Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 10
- Log:
Checking in HEAD from RForum's SVN of 22-Jul-2006, 8pm (revision 906).
- Author:
- adh
- Date:
- Sat Jul 22 20:02:44 +0100 2006
- Size:
- 3614 Bytes
1 | class Forum < ActiveRecord::Base |
2 | has_many :topics, :dependent => true |
3 | belongs_to :site |
4 | |
5 | acts_as_list :scope => :site_id |
6 | |
7 | include ErrorRaising |
8 | |
9 | # Get the list of groups for the NNTP server. |
10 | def self.nntp_grouplist |
11 | |
12 | forums = connection.select_all <<-EOL |
13 | SELECT f.groupname, f.description, |
14 | MAX(posts.nntpid) AS high, |
15 | MIN(posts.nntpid) AS low, |
16 | COUNT(posts.id) AS posts_count |
17 | FROM forums AS f |
18 | LEFT JOIN topics ON f.id = topics.forum_id |
19 | LEFT JOIN posts ON posts.topic_id = topics.id |
20 | GROUP BY f.id, f.groupname, f.description |
21 | ORDER BY f.groupname |
22 | EOL |
23 | |
24 | forums.inject([]) { |list, forum| |
25 | if forum['posts_count'] == '0' |
26 | list << "#{forum['groupname']} 0 1 y" |
27 | else |
28 | list << "#{forum['groupname']} #{forum['high']} #{forum['low']} y" |
29 | end |
30 | } |
31 | end |
32 | |
33 | def get_topics_for_list(range, tagname=nil, include_deleted=false) |
34 | if tagname |
35 | tag = Tag.find_by_name(tagname) |
36 | return [] if tag == nil |
37 | end |
38 | |
39 | Topic.find_by_sql( |
40 | " |
41 | SELECT * FROM topics |
42 | #{"LEFT JOIN topics_tags ON topics.id = topics_tags.topic_id" if tag} |
43 | WHERE |
44 | #{"topics_tags.tag_id = " + tag.id.to_s + " AND " if tag} |
45 | topics.forum_id = #{self.id} |
46 | #{"AND topics.deleted = 0" unless include_deleted} |
47 | ORDER BY last_post_created_at DESC |
48 | LIMIT #{range.end - range.begin + 1} OFFSET #{range.begin} |
49 | " |
50 | ) |
51 | end |
52 | |
53 | # Create a new post & topic in this forum. |
54 | def add_post(post) |
55 | # Transaction is necessary here because more than one entity is being |
56 | # created if saving of post raises an error (e.g., |
57 | # RForum::ValidationError), complete trx must be rolled back |
58 | # Transaction::Simple is not necessary here, because post won't be |
59 | # used anymore |
60 | transaction do |
61 | topic = Topic.create('forum_id' => self.id, 'subject' => post.subject) |
62 | topic.created_at = topic.updated_at = post.created_at = post.updated_at = (post.created_at or Time.now) |
63 | post.topic = topic |
64 | post.parent = nil |
65 | post.save |
66 | # reload topic to see the changes made in Post#after_create |
67 | post.topic(:reload) |
68 | end |
69 | return post |
70 | end |
71 | |
72 | # Find the next free nntpid in a forum. |
73 | def get_next_free_nntpid |
74 | res = ActiveRecord::Base.connection.select_one <<-EOL |
75 | SELECT MAX(posts.nntpid) AS max_nntpid_in_forum |
76 | FROM topics |
77 | LEFT JOIN posts ON topics.id = posts.topic_id |
78 | WHERE topics.forum_id = #{self.id} |
79 | GROUP BY topics.forum_id |
80 | EOL |
81 | if res.nil? |
82 | return 1 |
83 | else |
84 | return res['max_nntpid_in_forum'].to_i + 1 |
85 | end |
86 | end |
87 | |
88 | def get_topics_num |
89 | res = ActiveRecord::Base.connection.select_one <<-EOL |
90 | SELECT COUNT(*) AS count FROM topics |
91 | WHERE forum_id = #{self.id} |
92 | AND topics.deleted = 0 |
93 | EOL |
94 | if res.nil? |
95 | return 0 |
96 | else |
97 | return res['count'].to_i |
98 | end |
99 | end |
100 | |
101 | def get_posts_num |
102 | res = ActiveRecord::Base.connection.select_one <<-EOL |
103 | SELECT COUNT(*) AS count FROM topics, posts |
104 | WHERE topics.forum_id = #{self.id} |
105 | AND posts.topic_id = topics.id |
106 | AND posts.deleted = 0 |
107 | AND topics.deleted = 0 |
108 | EOL |
109 | if res.nil? |
110 | return 0 |
111 | else |
112 | return res['count'].to_i |
113 | end |
114 | end |
115 | |
116 | def get_last_post |
117 | topic = topics.find( |
118 | :first, |
119 | :conditions => 'deleted = 0', |
120 | :order => 'last_post_created_at DESC' |
121 | ) |
122 | |
123 | return nil if topic.nil? |
124 | |
125 | topic.posts.find( |
126 | :first, |
127 | :conditions => 'deleted = 0', |
128 | :order => 'created_at DESC' |
129 | ) |
130 | end |
131 | end |