Commit ec3ad995 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

Making subscribing to a forum/topic actually do something

parent 13da8b1d
<?php <?php
$string['addtitle'] = 'Add forum'; $string['addtitle'] = 'Add forum';
$string['addtopic'] = 'Add topic';
$string['body'] = 'Body'; $string['body'] = 'Body';
$string['cancel'] = 'Cancel';
$string['closed'] = 'Closed'; $string['closed'] = 'Closed';
$string['count'] = 'Count'; $string['count'] = 'Count';
$string['currentmoderators'] = 'Current Moderators'; $string['currentmoderators'] = 'Current Moderators';
$string['delete'] = 'Delete'; $string['delete'] = 'Delete';
$string['deleteforum'] = 'Delete forum'; $string['deletepost'] = 'Delete post \'%s\'';
$string['deletepost'] = 'Delete post';
$string['deletepostsure'] = 'Are you sure you want to do this? It cannot be undone.'; $string['deletepostsure'] = 'Are you sure you want to do this? It cannot be undone.';
$string['deletetopic'] = 'Delete topic'; $string['deletetopic'] = 'Delete topic \'%s\'';
$string['deletetopicsure'] = 'Are you sure you want to do this? It cannot be undone.'; $string['deletetopicsure'] = 'Are you sure you want to do this? It cannot be undone.';
$string['edit'] = 'Edit';
$string['edited'] = 'Edited'; $string['edited'] = 'Edited';
$string['editpost'] = 'Edit post'; $string['editpost'] = 'Edit post';
$string['edittitle'] = 'Edit forum'; $string['edittitle'] = 'Edit forum';
...@@ -21,10 +19,16 @@ $string['moderators'] = 'Moderators'; ...@@ -21,10 +19,16 @@ $string['moderators'] = 'Moderators';
$string['name'] = 'Forum'; $string['name'] = 'Forum';
$string['nameplural'] = 'Forums'; $string['nameplural'] = 'Forums';
$string['newforum'] = 'New forum'; $string['newforum'] = 'New forum';
$string['newforumpostin'] = 'New forum post in %s';
$string['newpost'] = 'New post: ';
$string['newtopic'] = 'New topic'; $string['newtopic'] = 'New topic';
$string['noforums'] = 'There are no forums in this group'; $string['noforums'] = 'There are no forums in this group';
$string['noregulartopics'] = 'There are no regular topics in this forum';
$string['nostickytopics'] = 'There are no sticky topics in this forum';
$string['post'] = 'Post'; $string['post'] = 'Post';
$string['postedin'] = '%s posted in %s';
$string['poster'] = 'Poster'; $string['poster'] = 'Poster';
$string['postreply'] = 'Post reply';
$string['posts'] = 'Posts'; $string['posts'] = 'Posts';
$string['potentialmoderators'] = 'Potential Moderators'; $string['potentialmoderators'] = 'Potential Moderators';
$string['re'] ='Re: '; $string['re'] ='Re: ';
...@@ -36,7 +40,6 @@ $string['subject'] = 'Subject'; ...@@ -36,7 +40,6 @@ $string['subject'] = 'Subject';
$string['subscribe'] = 'Subscribe'; $string['subscribe'] = 'Subscribe';
$string['topic'] = 'Topic'; $string['topic'] = 'Topic';
$string['typenewpost'] = 'New post'; $string['typenewpost'] = 'New post';
$string['update'] = 'Update';
$string['unsubscribe'] = 'Unsubscribe'; $string['unsubscribe'] = 'Unsubscribe';
$string['weight'] = 'Weight'; $string['weight'] = 'Weight';
......
...@@ -75,10 +75,74 @@ class PluginInteractionForum extends PluginInteraction { ...@@ -75,10 +75,74 @@ class PluginInteractionForum extends PluginInteraction {
(object)array( (object)array(
'name' => 'newpost', 'name' => 'newpost',
'admin' => 0, 'admin' => 0,
'delay' => 1, 'delay' => 1
) )
); );
} }
public static function get_cron() {
return array(
(object)array(
'callfunction' => 'interaction_forum_new_post',
'minute' => '*/30',
),
);
}
public static function interaction_forum_new_post() {
$currenttime = time();
$posts = get_records_sql_array(
'SELECT s.subscriber, s.type, p.id
FROM (
SELECT st."user" AS subscriber, st.topic AS topic, \'topic\' AS type
FROM {interaction_forum_subscription_topic} st
UNION SELECT sf."user" AS subscriber, t.id AS topic, \'forum\' AS type
FROM {interaction_forum_subscription_forum} sf
INNER JOIN {interaction_forum_topic} t
ON t.forum = sf.forum
) s
INNER JOIN {interaction_forum_topic} t
ON t.deleted != 1 AND t.id = s.topic
INNER JOIN {interaction_forum_post} p
ON p.sent != 1 AND p.ctime < ? AND p.deleted != 1 AND p.topic = t.id
ORDER BY type, p.id',
array(db_format_timestamp($currenttime - 30 * 60))
);
if ($posts) {
$count = count($posts);
for ($i = 0; $i < $count; $i++) {
$posts[$i]->users = array($posts[$i]->subscriber);
$temp = $i;
while (isset($posts[$i+1])
&& $posts[$i+1]->id == $posts[$temp]->id
&& $posts[$i+1]->type == $posts[$temp]->type) {
$i++;
$posts[$temp]->users[] = $posts[$i]->subscriber;
unset($posts[$i]);
}
}
foreach ($posts as $post) {
activity_occurred(
'newpost',
array(
'type' => $post->type,
'postid' => $post->id,
'users' => $post->users
),
'interaction',
'forum'
);
}
execute_sql(
'UPDATE {interaction_forum_post}
SET sent = 1
WHERE ctime < ?
AND deleted != 1
AND sent = 0',
array(db_format_timestamp($currenttime - 30 * 60))
);
}
}
} }
class InteractionForumInstance extends InteractionInstance { class InteractionForumInstance extends InteractionInstance {
...@@ -87,12 +151,60 @@ class InteractionForumInstance extends InteractionInstance { ...@@ -87,12 +151,60 @@ class InteractionForumInstance extends InteractionInstance {
return 'forum'; return 'forum';
} }
public function delete() {
parent::delete();
update_record(
'interaction_forum_topic',
(object)array('deleted' => 1),
array('forum' => $this->id)
);
}
} }
class ActivityTypeInteractionForumNewPost extends ActivityType {
class ActivityTypeInteractionForumNewPost extends ActivityTypePlugin {
protected $postid;
protected $type; // forum/topic
public function __construct($data) {
parent::__construct($data);
$this->users = get_records_sql_array(
'SELECT id, username, preferredname, firstname, lastname, admin, staff
FROM {usr} u
WHERE id in (' . implode(',', $this->users) . ')',
array()
);
$post = get_record_sql(
'SELECT p.subject, p.poster, t.id AS topicid, p2.subject AS topicsubject, f.title AS forumtitle
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t
ON t.id = p.topic
INNER JOIN {interaction_forum_post} p2
ON p2.parent IS NULL AND p2.topic = t.id
INNER JOIN {interaction_instance} f
ON t.forum = f.id
WHERE p.id = ?',
array($this->postid)
);
$this->url = get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $post->topicid;
$this->subject = get_string('newforumpostin', 'interaction.forum', $post->forumtitle);
foreach ($this->users as &$user) {
$user->message = get_string('postedin', 'interaction.forum', display_name($post->poster, $user), $post->topicsubject);
}
}
public function get_plugintype(){
return 'interaction';
}
public function get_pluginname(){
return 'forum';
}
public function get_required_parameters() { public function get_required_parameters() {
return array(); return array('postid', 'type');
} }
} }
...@@ -126,5 +238,4 @@ function is_forum_moderator($forumid, $userid=null) { ...@@ -126,5 +238,4 @@ function is_forum_moderator($forumid, $userid=null) {
); );
} }
?> ?>
...@@ -585,6 +585,11 @@ abstract class ActivityTypePlugin extends ActivityType { ...@@ -585,6 +585,11 @@ abstract class ActivityTypePlugin extends ActivityType {
abstract public function get_pluginname(); abstract public function get_pluginname();
public function get_type() {
$prefix = 'ActivityType' . $this->get_plugintype() . $this->get_pluginname();
return strtolower(substr(get_class($this), strlen($prefix)));
}
public function get_id() { public function get_id() {
if (!isset($this->id)) { if (!isset($this->id)) {
$tmp = activity_locate_typerecord($this->get_type(), $this->get_plugintype(), $this->get_pluginname()); $tmp = activity_locate_typerecord($this->get_type(), $this->get_plugintype(), $this->get_pluginname());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment