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

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);
define('MENUITEM', 'groups');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('group.php');
safe_require('interaction', 'forum');
define('TITLE', get_string('nameplural', 'interaction.forum'));
$groupid = param_integer('group');
......@@ -36,12 +37,12 @@ if (!record_exists('group', 'id', $groupid)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
$groupname = get_record_sql(
$groupname = get_field_sql(
'SELECT name
FROM {group}
WHERE id = ?',
array($groupid)
)->name;
);
$membership = user_can_access_group($groupid);
......@@ -52,29 +53,26 @@ if (!$membership) {
$admin = (bool)($membership & GROUP_MEMBERSHIP_OWNER);
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $groupid,
$groupname
),
array(
get_config('wwwroot') . 'interaction/forum/index.php?group=' . $groupid,
get_string('nameplural', 'interaction.forum')
),
array()
)
);
$forums = get_records_sql_array(
'SELECT f.id, f.title, f.description, COUNT(t.*), s.forum AS subscribed
FROM {interaction_instance} f
LEFT JOIN {interaction_forum_topic} t
ON t.forum = f.id
AND t.deleted != 1
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" = ?
LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1)
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 = ?
AND f.deleted != 1
GROUP BY 1, 2, 3, 5, c.value
ORDER BY c.value',
ORDER BY c.value, f.id',
array($USER->get('id'), $groupid)
);
......@@ -85,7 +83,8 @@ if ($forums) {
foreach ($forums as $forum) {
$forum->subscribe = pieform(array(
'name' => 'subscribe'.$i++,
'successcallback' => 'subscribe_submit',
'successcallback' => 'subscribe_forum_submit',
'autofocus' => false,
'elements' => array(
'submit' => array(
'type' => 'submit',
......@@ -94,44 +93,16 @@ if ($forums) {
'forum' => array(
'type' => 'hidden',
'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->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('groupid', $groupid);
......
......@@ -29,6 +29,8 @@ $string['edited'] = 'Edited';
$string['editpost'] = 'Edit post';
$string['edittitle'] = 'Edit forum';
$string['edittopic'] = 'Edit topic';
$string['forumsuccessfulsubscribe'] = 'Forum subscribed successfully';
$string['forumsuccessfulunsubscribe'] = 'Forum unsubscribed successfully';
$string['moderators'] = 'Moderators';
$string['name'] = 'Forum';
$string['nameplural'] = 'Forums';
......@@ -43,16 +45,17 @@ $string['post'] = 'Post';
$string['postedin'] = '%s posted in %s';
$string['poster'] = 'Poster';
$string['postreply'] = 'Post reply';
$string['posts'] = 'Posts';
$string['posts'] = 'Posts: %s';
$string['potentialmoderators'] = 'Potential Moderators';
$string['re'] ='Re: %s';
$string['regulartopics'] = 'Regular topics';
$string['reply'] = 'Reply';
$string['sticky'] = 'Sticky';
$string['stickytopics'] = 'Sticky topics';
$string['subject'] = 'Subject';
$string['subscribe'] = 'Subscribe';
$string['subject'] = 'Subject';
$string['topic'] = 'Topic';
$string['topics'] = 'Topics: %s';
$string['typenewpost'] = 'New post';
$string['unsubscribe'] = 'Unsubscribe';
$string['weight'] = 'Weight';
......
......@@ -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 @@
{include file="columnleftstart.tpl"}
<p>
<a href="{$breadcrumbs[0][0]|escape}">{$breadcrumbs[0][1]|escape}</a>
{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>
<h2>{$groupname|escape} - {str tag=nameplural section=interaction.forum}</h2>
{include file="interaction:forum:breadcrumbs.tpl" breadcrumbs=$breadcrumbs}
{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 $forums}
<ul>
{foreach from=$forums item=forum}
<li>
<a href="{$WWWROOT}interaction/forum/view.php?id={$forum->id|escape}">{$forum->title|escape}</a>
<p>{$forum->description}</p>
<div class="fr">{$forum->count|escape}</div>
<h4><a href="{$WWWROOT}interaction/forum/view.php?id={$forum->id|escape}">{$forum->title|escape}</a></h4>
{$forum->description}
<div class="fr">{str tag=topics section=interaction.forum args=$forum->count}</div>
{if $admin}
<div>
<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}
{$forum->subscribe}
</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