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

Changes to breadcrumbs, moved forum_subscribe_submit function, changing how...

Changes to breadcrumbs, moved forum_subscribe_submit function, changing how page looks + minor stuff
parent bdb2c734
...@@ -28,6 +28,7 @@ define('INTERNAL', 1); ...@@ -28,6 +28,7 @@ define('INTERNAL', 1);
define('MENUITEM', 'groups'); define('MENUITEM', 'groups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php'); require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('group.php'); require_once('group.php');
safe_require('interaction', 'forum');
define('TITLE', get_string('nameplural', 'interaction.forum')); define('TITLE', get_string('nameplural', 'interaction.forum'));
$groupid = param_integer('group'); $groupid = param_integer('group');
...@@ -36,12 +37,12 @@ if (!record_exists('group', 'id', $groupid)) { ...@@ -36,12 +37,12 @@ if (!record_exists('group', 'id', $groupid)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid)); throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
} }
$groupname = get_record_sql( $groupname = get_field_sql(
'SELECT name 'SELECT name
FROM {group} FROM {group}
WHERE id = ?', WHERE id = ?',
array($groupid) array($groupid)
)->name; );
$membership = user_can_access_group($groupid); $membership = user_can_access_group($groupid);
...@@ -52,29 +53,26 @@ if (!$membership) { ...@@ -52,29 +53,26 @@ if (!$membership) {
$admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER); $admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$breadcrumbs = array( $breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $groupid,
$groupname
),
array( array(
get_config('wwwroot') . 'interaction/forum/index.php?group=' . $groupid, get_config('wwwroot') . 'interaction/forum/index.php?group=' . $groupid,
get_string('nameplural', 'interaction.forum') get_string('nameplural', 'interaction.forum')
), )
array()
); );
$forums = get_records_sql_array( $forums = get_records_sql_array(
'SELECT f.id, f.title, f.description, COUNT(t.*), s.forum AS subscribed 'SELECT f.id, f.title, f.description, COUNT(t.*), s.forum AS subscribed
FROM {interaction_instance} f FROM {interaction_instance} f
LEFT JOIN {interaction_forum_topic} t LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1)
ON t.forum = f.id INNER JOIN {interaction_forum_instance_config} c ON (c.forum = f.id AND c.field = \'weight\')
AND t.deleted != 1 LEFT JOIN {interaction_forum_subscription_forum} s ON (s.forum = f.id AND s."user" = ?)
INNER JOIN {interaction_forum_instance_config} c
ON c.forum = f.id
AND c.field = \'weight\'
LEFT JOIN {interaction_forum_subscription_forum} s
ON s.forum = f.id
AND s."user" = ?
WHERE f.group = ? WHERE f.group = ?
AND f.deleted != 1 AND f.deleted != 1
GROUP BY 1, 2, 3, 5, c.value GROUP BY 1, 2, 3, 5, c.value
ORDER BY c.value', ORDER BY c.value, f.id',
array($USER->get('id'), $groupid) array($USER->get('id'), $groupid)
); );
...@@ -85,7 +83,8 @@ if ($forums) { ...@@ -85,7 +83,8 @@ if ($forums) {
foreach ($forums as $forum) { foreach ($forums as $forum) {
$forum->subscribe = pieform(array( $forum->subscribe = pieform(array(
'name' => 'subscribe'.$i++, 'name' => 'subscribe'.$i++,
'successcallback' => 'subscribe_submit', 'successcallback' => 'subscribe_forum_submit',
'autofocus' => false,
'elements' => array( 'elements' => array(
'submit' => array( 'submit' => array(
'type' => 'submit', 'type' => 'submit',
...@@ -94,44 +93,16 @@ if ($forums) { ...@@ -94,44 +93,16 @@ if ($forums) {
'forum' => array( 'forum' => array(
'type' => 'hidden', 'type' => 'hidden',
'value' => $forum->id 'value' => $forum->id
),
'group' => array(
'type' => 'hidden',
'value' => $groupid
) )
) )
)); ));
} }
} }
function subscribe_submit(Pieform $form, $values) {
global $USER;
global $groupid;
if ($values['submit'] == get_string('subscribe', 'interaction.forum')) {
insert_record(
'interaction_forum_subscription_forum',
(object)array(
'forum' => $values['forum'],
'user' => $USER->get('id')
)
);
delete_records_sql(
'DELETE FROM {interaction_forum_subscription_topic}
WHERE topic IN (
SELECT id
FROM {interaction_forum_topic}
WHERE forum = ?
AND "user" = ?
)',
array($values['forum'], $USER->get('id'))
);
}
else {
delete_records(
'interaction_forum_subscription_forum',
'forum', $values['forum'],
'user', $USER->get('id')
);
}
redirect('/interaction/forum/index.php?group=' . $groupid);
}
$smarty = smarty(); $smarty = smarty();
$smarty->assign('breadcrumbs', $breadcrumbs); $smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('groupid', $groupid); $smarty->assign('groupid', $groupid);
......
...@@ -29,6 +29,8 @@ $string['edited'] = 'Edited'; ...@@ -29,6 +29,8 @@ $string['edited'] = 'Edited';
$string['editpost'] = 'Edit post'; $string['editpost'] = 'Edit post';
$string['edittitle'] = 'Edit forum'; $string['edittitle'] = 'Edit forum';
$string['edittopic'] = 'Edit topic'; $string['edittopic'] = 'Edit topic';
$string['forumsuccessfulsubscribe'] = 'Forum subscribed successfully';
$string['forumsuccessfulunsubscribe'] = 'Forum unsubscribed successfully';
$string['moderators'] = 'Moderators'; $string['moderators'] = 'Moderators';
$string['name'] = 'Forum'; $string['name'] = 'Forum';
$string['nameplural'] = 'Forums'; $string['nameplural'] = 'Forums';
...@@ -43,16 +45,17 @@ $string['post'] = 'Post'; ...@@ -43,16 +45,17 @@ $string['post'] = 'Post';
$string['postedin'] = '%s posted in %s'; $string['postedin'] = '%s posted in %s';
$string['poster'] = 'Poster'; $string['poster'] = 'Poster';
$string['postreply'] = 'Post reply'; $string['postreply'] = 'Post reply';
$string['posts'] = 'Posts'; $string['posts'] = 'Posts: %s';
$string['potentialmoderators'] = 'Potential Moderators'; $string['potentialmoderators'] = 'Potential Moderators';
$string['re'] ='Re: %s'; $string['re'] ='Re: %s';
$string['regulartopics'] = 'Regular topics'; $string['regulartopics'] = 'Regular topics';
$string['reply'] = 'Reply'; $string['reply'] = 'Reply';
$string['sticky'] = 'Sticky'; $string['sticky'] = 'Sticky';
$string['stickytopics'] = 'Sticky topics'; $string['stickytopics'] = 'Sticky topics';
$string['subject'] = 'Subject';
$string['subscribe'] = 'Subscribe'; $string['subscribe'] = 'Subscribe';
$string['subject'] = 'Subject';
$string['topic'] = 'Topic'; $string['topic'] = 'Topic';
$string['topics'] = 'Topics: %s';
$string['typenewpost'] = 'New post'; $string['typenewpost'] = 'New post';
$string['unsubscribe'] = 'Unsubscribe'; $string['unsubscribe'] = 'Unsubscribe';
$string['weight'] = 'Weight'; $string['weight'] = 'Weight';
......
...@@ -240,4 +240,45 @@ function is_forum_moderator($forumid, $userid=null) { ...@@ -240,4 +240,45 @@ function is_forum_moderator($forumid, $userid=null) {
); );
} }
/**
* For a pieform with forum, group and subscribe elements.
* forum and group are the forum and group ids
* subscribe has value get_string('subscribe', 'interaction.forum') if the user should be subscribed
* get_string('unsubscribe', 'interaction.forum') if the user should be unsubscribed
*/
function subscribe_forum_submit(Pieform $form, $values) {
global $USER, $SESSION;
db_begin();
if ($values['submit'] == get_string('subscribe', 'interaction.forum')) {
insert_record(
'interaction_forum_subscription_forum',
(object)array(
'forum' => $values['forum'],
'user' => $USER->get('id')
)
);
delete_records_sql(
'DELETE FROM {interaction_forum_subscription_topic}
WHERE topic IN (
SELECT id
FROM {interaction_forum_topic}
WHERE forum = ?
AND "user" = ?
)',
array($values['forum'], $USER->get('id'))
);
$SESSION->add_ok_msg(get_string('forumsuccessfulsubscribe', 'interaction.forum'));
}
else {
delete_records(
'interaction_forum_subscription_forum',
'forum', $values['forum'],
'user', $USER->get('id')
);
$SESSION->add_ok_msg(get_string('forumsuccessfulunsubscribe', 'interaction.forum'));
}
db_commit();
redirect('/interaction/forum/index.php?group=' . $values['group']);
}
?> ?>
...@@ -3,28 +3,27 @@ ...@@ -3,28 +3,27 @@
{include file="columnleftstart.tpl"} {include file="columnleftstart.tpl"}
<p> <h2>{$groupname|escape} - {str tag=nameplural section=interaction.forum}</h2>
<a href="{$breadcrumbs[0][0]|escape}">{$breadcrumbs[0][1]|escape}</a> {include file="interaction:forum:breadcrumbs.tpl" breadcrumbs=$breadcrumbs}
{foreach from=$breadcrumbs[1] item=item}
&raquo <a href="{$item[0]|escape}">{$item[1]|escape}</a>
{/foreach}
</p>
<h2>{$groupname|escape}</h2>
<h3>{str tag=nameplural section=interaction.forum}</h3>
{if $admin} {if $admin}
<a href="{$WWWROOT}interaction/edit.php?group={$groupid|escape}&plugin=forum">{str tag="newforum" section=interaction.forum}</a> <div class="fr">
<span class="addicon">
<a href="{$WWWROOT}interaction/edit.php?group={$groupid|escape}&amp;plugin=forum">{str tag="newforum" section=interaction.forum}</a>
</span>
</div>
{/if} {/if}
{if $forums} {if $forums}
<ul> <ul>
{foreach from=$forums item=forum} {foreach from=$forums item=forum}
<li> <li>
<a href="{$WWWROOT}interaction/forum/view.php?id={$forum->id|escape}">{$forum->title|escape}</a> <h4><a href="{$WWWROOT}interaction/forum/view.php?id={$forum->id|escape}">{$forum->title|escape}</a></h4>
<p>{$forum->description}</p> {$forum->description}
<div class="fr">{$forum->count|escape}</div> <div class="fr">{str tag=topics section=interaction.forum args=$forum->count}</div>
{if $admin} {if $admin}
<div>
<a href="{$WWWROOT}interaction/edit.php?id={$forum->id|escape}">{str tag=edit}</a> <a href="{$WWWROOT}interaction/edit.php?id={$forum->id|escape}">{str tag=edit}</a>
<a href="{$WWWROOT}interaction/delete.php?id={$forum->id|escape}">{str tag=delete}</a> | <a href="{$WWWROOT}interaction/delete.php?id={$forum->id|escape}">{str tag=delete}</a>
</div>
{/if} {/if}
{$forum->subscribe} {$forum->subscribe}
</li> </li>
......
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