1 | <?php |
||
10 | class ForumThread extends DataObject |
||
11 | { |
||
12 | |||
13 | private static $db = array( |
||
|
|||
14 | "Title" => "Varchar(255)", |
||
15 | "NumViews" => "Int", |
||
16 | "IsSticky" => "Boolean", |
||
17 | "IsReadOnly" => "Boolean", |
||
18 | "IsGlobalSticky" => "Boolean" |
||
19 | ); |
||
20 | |||
21 | private static $has_one = array( |
||
22 | 'Forum' => 'Forum' |
||
23 | ); |
||
24 | |||
25 | private static $has_many = array( |
||
26 | 'Posts' => 'Post' |
||
27 | ); |
||
28 | |||
29 | private static $defaults = array( |
||
30 | 'NumViews' => 0, |
||
31 | 'IsSticky' => false, |
||
32 | 'IsReadOnly' => false, |
||
33 | 'IsGlobalSticky' => false |
||
34 | ); |
||
35 | |||
36 | private static $indexes = array( |
||
37 | 'IsSticky' => true, |
||
38 | 'IsGlobalSticky' => true |
||
39 | ); |
||
40 | |||
41 | /** |
||
42 | * @var null|boolean Per-request cache, whether we should display signatures on a post. |
||
43 | */ |
||
44 | private static $_cache_displaysignatures = null; |
||
45 | |||
46 | /** |
||
47 | * Check if the user can create new threads and add responses |
||
48 | */ |
||
49 | public function canPost($member = null) |
||
56 | |||
57 | /** |
||
58 | * Check if user can moderate this thread |
||
59 | */ |
||
60 | public function canModerate($member = null) |
||
67 | |||
68 | /** |
||
69 | * Check if user can view the thread |
||
70 | */ |
||
71 | public function canView($member = null) |
||
78 | |||
79 | /** |
||
80 | * Hook up into moderation. |
||
81 | */ |
||
82 | public function canEdit($member = null) |
||
89 | |||
90 | /** |
||
91 | * Hook up into moderation - users cannot delete their own posts/threads because |
||
92 | * we will loose history this way. |
||
93 | */ |
||
94 | public function canDelete($member = null) |
||
101 | |||
102 | /** |
||
103 | * Hook up into canPost check |
||
104 | */ |
||
105 | public function canCreate($member = null) |
||
112 | |||
113 | /** |
||
114 | * Are Forum Signatures on Member profiles allowed. |
||
115 | * This only needs to be checked once, so we cache the initial value once per-request. |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | public function getDisplaySignatures() |
||
129 | |||
130 | /** |
||
131 | * Get the latest post from this thread. Nicer way then using an control |
||
132 | * from the template |
||
133 | * |
||
134 | * @return Post |
||
135 | */ |
||
136 | public function getLatestPost() |
||
140 | |||
141 | /** |
||
142 | * Return the first post from the thread. Useful to working out the original author |
||
143 | * |
||
144 | * @return Post |
||
145 | */ |
||
146 | public function getFirstPost() |
||
150 | |||
151 | /** |
||
152 | * Return the number of posts in this thread. We could use count on |
||
153 | * the dataobject set but that is slower and causes a performance overhead |
||
154 | * |
||
155 | * @return int |
||
156 | */ |
||
157 | public function getNumPosts() |
||
167 | |||
168 | /** |
||
169 | * Check if they have visited this thread before. If they haven't increment |
||
170 | * the NumViews value by 1 and set visited to true. |
||
171 | * |
||
172 | * @return void |
||
173 | */ |
||
174 | public function incNumViews() |
||
187 | |||
188 | /** |
||
189 | * Link to this forum thread |
||
190 | * |
||
191 | * @return String |
||
192 | */ |
||
193 | public function Link($action = "show", $showID = true) |
||
204 | |||
205 | /** |
||
206 | * Check to see if the user has subscribed to this thread |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | public function getHasSubscribed() |
||
216 | |||
217 | /** |
||
218 | * Before deleting the thread remove all the posts |
||
219 | */ |
||
220 | public function onBeforeDelete() |
||
231 | |||
232 | public function onAfterWrite() |
||
245 | |||
246 | /** |
||
247 | * @return Text |
||
248 | */ |
||
249 | public function getEscapedTitle() |
||
254 | } |
||
255 | |||
340 |