66use SilverStripe \ORM \DataObject ;
77use FullscreenInteractive \SilverStripe \Forum \PageTypes \Forum ;
88use SilverStripe \ORM \DB ;
9+ use SilverStripe \ORM \FieldType \DBField ;
910use SilverStripe \Security \Security ;
1011
1112class ForumThread extends DataObject
@@ -27,6 +28,10 @@ class ForumThread extends DataObject
2728 'Posts ' => Post::class
2829 ];
2930
31+ private static $ cascade_deletes = [
32+ 'Posts '
33+ ];
34+
3035 private static $ defaults = [
3136 'NumViews ' => 0 ,
3237 'IsSticky ' => false ,
@@ -202,7 +207,7 @@ public function getHasSubscribed()
202207 {
203208 $ member = Security::getCurrentUser ();
204209
205- return ($ member ) ? ForumThread_Subscription:: already_subscribed ($ this ->ID , $ member ->ID ) : false ;
210+ return ($ member ) ? ForumThreadSubscription:: singleton ()-> isSubscribed ($ this ->ID , $ member ->ID ) : false ;
206211 }
207212
208213 /**
@@ -239,92 +244,6 @@ public function onAfterWrite()
239244 */
240245 public function getEscapedTitle ()
241246 {
242- //return DBField::create('Text', $this->dbObject('Title')->XML());
243247 return DBField::create_field ('Text ' , $ this ->dbObject ('Title ' )->XML ());
244248 }
245249}
246-
247-
248- /**
249- * Forum Thread Subscription: Allows members to subscribe to this thread
250- * and receive email notifications when these topics are replied to.
251- *
252- * @package forum
253- */
254- class ForumThread_Subscription extends DataObject
255- {
256-
257- private static $ db = array (
258- "LastSent " => "SS_Datetime "
259- );
260-
261- private static $ has_one = array (
262- "Thread " => "ForumThread " ,
263- "Member " => "Member "
264- );
265-
266- /**
267- * Checks to see if a Member is already subscribed to this thread
268- *
269- * @param int $threadID The ID of the thread to check
270- * @param int $memberID The ID of the currently logged in member (Defaults to Member::currentUserID())
271- *
272- * @return bool true if they are subscribed, false if they're not
273- */
274- static function already_subscribed ($ threadID , $ memberID = null )
275- {
276- if (!$ memberID ) {
277- $ memberID = Member::currentUserID ();
278- }
279- $ SQL_threadID = Convert::raw2sql ($ threadID );
280- $ SQL_memberID = Convert::raw2sql ($ memberID );
281-
282- if ($ SQL_threadID == '' || $ SQL_memberID == '' ) {
283- return false ;
284- }
285-
286- return (DB ::query ("
287- SELECT COUNT( \"ID \")
288- FROM \"ForumThread_Subscription \"
289- WHERE \"ThreadID \" = ' $ SQL_threadID' AND \"MemberID \" = $ SQL_memberID " )->value () > 0 ) ? true : false ;
290- }
291-
292- /**
293- * Notifies everybody that has subscribed to this topic that a new post has been added.
294- * To get emailed, people subscribed to this topic must have visited the forum
295- * since the last time they received an email
296- *
297- * @param Post $post The post that has just been added
298- */
299- static function notify (Post $ post )
300- {
301- $ list = DataObject::get (
302- "ForumThread_Subscription " ,
303- "\"ThreadID \" = ' " . $ post ->ThreadID . "' AND \"MemberID \" != ' $ post ->AuthorID ' "
304- );
305-
306- if ($ list ) {
307- foreach ($ list as $ obj ) {
308- $ SQL_id = Convert::raw2sql ((int )$ obj ->MemberID );
309-
310- // Get the members details
311- $ member = DataObject::get_one ("Member " , "\"Member \". \"ID \" = ' $ SQL_id' " );
312- $ adminEmail = Config::inst ()->get ('Email ' , 'admin_email ' );
313-
314- if ($ member ) {
315- $ email = new Email ();
316- $ email ->setFrom ($ adminEmail );
317- $ email ->setTo ($ member ->Email );
318- $ email ->setSubject (_t ('Post.NEWREPLY ' , 'New reply for {title} ' , array ('title ' => $ post ->Title )));
319- $ email ->setTemplate ('ForumMember_TopicNotification ' );
320- $ email ->populateTemplate ($ member );
321- $ email ->populateTemplate ($ post );
322- $ email ->populateTemplate (array (
323- 'UnsubscribeLink ' => Director::absoluteBaseURL () . $ post ->Thread ()->Forum ()->Link () . '/unsubscribe/ ' . $ post ->ID
324- ));
325- $ email ->send ();
326- }
327- }
328- }
329- }
330- }
0 commit comments