Commit 51e9db1f authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Set within-group menu more easily

parent 5f7f8d14
......@@ -34,9 +34,9 @@ safe_require('artefact', 'file');
$javascript = ArtefactTypeFileBase::get_my_files_js(param_integer('folder', null));
$groupid = param_integer('group');
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException("Couldn't find group with id $groupid");
}
define('INGROUP', $groupid);
$group = group_current_group();
if (!group_user_access($groupid)) {
throw new AccessDeniedException();
}
......@@ -62,12 +62,10 @@ $smarty = smarty(
'sideblocks' => array(
interaction_sideblock($groupid),
),
'group' => $group,
)
);
$smarty->assign('heading', $group->name . ' - ' . get_string('Files', 'artefact.file'));
$smarty->assign('groupid', $groupid);
$smarty->assign('grouptabs', group_get_menu_tabs($group));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('artefact:file:index.tpl');
......
......@@ -33,10 +33,9 @@ require_once(get_config('docroot') . 'interaction/lib.php');
$groupid = param_integer('group');
$userid = param_integer('user');
$newrole = param_alpha('role', null);
define('INGROUP', $groupid);
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException("Couldn't find group with id $groupid");
}
$group = group_current_group();
if (!$user = get_record('usr', 'id', $userid, 'deleted', 0)) {
throw new UserNotFoundException("Couldn't find user with id $userid");
}
......@@ -101,10 +100,9 @@ function changerole_submit(Pieform $form, $values) {
define('TITLE', $group->name . ' - ' . get_string('changerole', 'group'));
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($groupid, $role)), 'group' => $group));
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($groupid, $role))));
$smarty->assign('group', $group);
$smarty->assign('groupid', $groupid);
$smarty->assign('grouptabs', group_get_menu_tabs($group));
$smarty->assign('subtitle', get_string('changeroleofuseringroup', 'group', display_name($user), $group->name));
$smarty->assign('changeform', $changeform);
......
......@@ -34,10 +34,9 @@ require_once(get_config('docroot') . 'interaction/lib.php');
$id = param_integer('id');
$membershiptype = param_alpha('membershiptype', null);
if (!$group = get_record('group', 'id', $id, 'deleted', 0)) {
throw new GroupNotFoundException("Couldn't find group with id $id");
}
define('GROUPNAME', str_shorten($group->name, 20, true));
define('INGROUP', $id);
$group = group_current_group();
define('TITLE', $group->name . ' - ' . get_string('Members', 'group'));
$role = group_user_access($id);
......@@ -54,11 +53,9 @@ list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersea
$smarty = smarty(array('groupmembersearch'), array(), array(), array(
'sideblocks' => array(interaction_sideblock($id, $role)),
'group' => $group,
));
$smarty->assign('group', $group);
$smarty->assign('groupid', $id);
$smarty->assign('grouptabs', group_get_menu_tabs($group));
$smarty->assign('query', $query);
$smarty->assign('results', $html);
$smarty->assign('pagination', $pagination['html']);
......
......@@ -34,10 +34,10 @@ require_once(get_config('libroot') . 'view.php');
safe_require('artefact', 'file');
$id = param_integer('id');
define('INGROUP', $id);
$group = group_current_group();
if (!$group = get_record_select('group', 'id = ? AND deleted = 0', array($id), '*, ' . db_format_tsfield('ctime'))) {
throw new GroupNotFoundException("Couldn't find group with id $id");
}
define('TITLE', $group->name);
$group->ctime = strftime(get_string('strftimedate'), $group->ctime);
......@@ -96,10 +96,9 @@ $foruminfo = get_records_sql_array('
p.ctime DESC
LIMIT 5;
', array($id));
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($id, $role)), 'group' => $group));
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($id, $role))));
$smarty->assign('group', $group);
$smarty->assign('groupid', $id);
$smarty->assign('grouptabs', group_get_menu_tabs($group));
$smarty->assign('foruminfo', $foruminfo);
$smarty->assign('membercount', count_records('group_member', 'group', $group->id));
$smarty->assign('viewcount', count_records('view', 'group', $group->id));
......
......@@ -48,6 +48,7 @@ else {
$groupid = param_integer('group');
define('TITLE', get_string('addtitle', 'interaction.' . $plugin));
}
define('INGROUP', $groupid);
safe_require('interaction', $plugin);
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
......
......@@ -25,7 +25,7 @@
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups');
define('MENUITEM', 'groups/forums');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
safe_require('interaction' ,'forum');
require_once('group.php');
......@@ -54,6 +54,8 @@ $post = get_record_sql(
array(0, $postid)
);
define('INGROUP', $post->group);
if (!$post) {
throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $postid));
......
......@@ -54,7 +54,7 @@ else { // edit post
}
$parent = get_record_sql(
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', m.user AS moderator, t.id AS topic, t.forum, t.closed AS topicclosed, p2.subject AS topicsubject, f.group AS "group", f.title AS forumtitle, g.name AS groupname, g.grouptype, COUNT(p3.id)
'SELECT p.subject, p.body, p.topic, p.parent, p.poster, ' . db_format_tsfield('p.ctime', 'ctime') . ', m.user AS moderator, t.id AS topic, t.forum, t.closed AS topicclosed, p2.subject AS topicsubject, f.group AS "group", f.title AS forumtitle, g.name AS groupname, COUNT(p3.id)
FROM {interaction_forum_post} p
INNER JOIN {interaction_forum_topic} t ON (p.topic = t.id AND t.deleted != 1)
INNER JOIN {interaction_forum_post} p2 ON (p2.topic = t.id AND p2.parent IS NULL)
......@@ -70,7 +70,7 @@ $parent = get_record_sql(
INNER JOIN {interaction_instance} f2 ON (t2.forum = f2.id AND f2.deleted != 1 AND f2.group = f.group)
WHERE p.id = ?
AND p.deleted != 1
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15',
GROUP BY 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14',
array(0, $parentid)
);
......@@ -78,6 +78,8 @@ if (!$parent) {
throw new NotFoundException(get_string('cantfindpost', 'interaction.forum', $parentid));
}
define('INGROUP', $parent->group);
$breadcrumbs = array(
array(
get_config('wwwroot') . 'group/view.php?id=' . $parent->group,
......@@ -241,7 +243,6 @@ function addpost_submit(Pieform $form, $values) {
$smarty = smarty(array(), array(), array(), array(
'sideblocks' => array(interaction_sideblock($parent->group)),
'group' => (object) array('id' => $parent->group, 'name' => $parent->groupname, 'grouptype' => $parent->grouptype),
));
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('heading', TITLE);
......
......@@ -33,10 +33,8 @@ require_once('pieforms/pieform.php');
require_once(get_config('docroot') . 'interaction/lib.php');
$groupid = param_integer('group');
if (!record_exists('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', $groupid));
}
define('INGROUP', $groupid);
$group = group_current_group();
$membership = group_user_access($groupid);
......@@ -44,8 +42,6 @@ if (!$membership) {
throw new AccessDeniedException(get_string('cantviewforums', 'interaction.forum'));
}
$group = get_record('group', 'id', $groupid);
define('TITLE', $group->name . ' - ' . get_string('nameplural', 'interaction.forum'));
$breadcrumbs = array(
......@@ -132,7 +128,7 @@ if ($forums) {
}
}
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($groupid)), 'group' => $group));
$smarty = smarty(array(), array(), array(), array('sideblocks' => array(interaction_sideblock($groupid))));
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('groupid', $groupid);
$smarty->assign('heading', TITLE);
......
......@@ -35,7 +35,7 @@ require_once('pieforms/pieform.php');
$topicid = param_integer('id');
$topic = get_record_sql(
'SELECT p.subject, p.poster, p.id AS firstpost, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id, f.group AS groupid, g.name AS groupname, g.grouptype, f.id AS forumid, f.title AS forumtitle, t.closed, sf.forum AS forumsubscribed, st.topic AS topicsubscribed
'SELECT p.subject, p.poster, p.id AS firstpost, ' . db_format_tsfield('p.ctime', 'ctime') . ', t.id, f.group AS groupid, g.name AS groupname, f.id AS forumid, f.title AS forumtitle, t.closed, sf.forum AS forumsubscribed, st.topic AS topicsubscribed
FROM {interaction_forum_topic} t
INNER JOIN {interaction_instance} f ON (t.forum = f.id AND f.deleted != 1)
INNER JOIN {group} g ON (g.id = f.group AND g.deleted = ?)
......@@ -47,6 +47,8 @@ $topic = get_record_sql(
array(0, $USER->get('id'), $USER->get('id'), $topicid)
);
define('INGROUP', $topic->groupid);
if (!$topic) {
throw new NotFoundException(get_string('cantfindtopic', 'interaction.forum', $topicid));
}
......@@ -159,7 +161,6 @@ $posts = buildpost(0, '', $posts);
$smarty = smarty(array(), array(), array(), array(
'sideblocks' => array(interaction_sideblock($topic->groupid)),
'group' => (object) array('id' => $topic->groupid, 'name' => $topic->groupname, 'grouptype' => $topic->grouptype),
));
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('heading', TITLE);
......
......@@ -41,17 +41,19 @@ $topicsperpage = 25;
$offset = (int)($offset / $topicsperpage) * $topicsperpage;
$forum = get_record_sql(
'SELECT f.title, f.description, f.id, COUNT(t.id) AS topiccount, s.forum AS subscribed, g.id AS groupid, g.name AS groupname, g.grouptype
'SELECT f.title, f.description, f.id, COUNT(t.id) AS topiccount, s.forum AS subscribed, g.id AS groupid, g.name AS groupname
FROM {interaction_instance} f
INNER JOIN {group} g ON (g.id = f."group" AND g.deleted = ?)
LEFT JOIN {interaction_forum_topic} t ON (t.forum = f.id AND t.deleted != 1 AND t.sticky != 1)
LEFT JOIN {interaction_forum_subscription_forum} s ON (s.forum = f.id AND s."user" = ?)
WHERE f.id = ?
AND f.deleted != 1
GROUP BY 1, 2, 3, 5, 6, 7, 8',
GROUP BY 1, 2, 3, 5, 6, 7',
array(0, $userid, $forumid)
);
define('INGROUP', $forum->groupid);
if (!$forum) {
throw new InteractionInstanceNotFoundException(get_string('cantfindforum', 'interaction.forum', $forumid));
}
......@@ -247,7 +249,6 @@ EOF;
$smarty = smarty(array(), array(), array(), array(
'sideblocks' => array(interaction_sideblock($forum->groupid)),
'group' => (object) array('id' => $forum->groupid, 'name' => $forum->groupname, 'grouptype' => $forum->grouptype)
));
$smarty->assign('breadcrumbs', $breadcrumbs);
$smarty->assign('heading', TITLE);
......
......@@ -143,6 +143,7 @@ $string['allgroups'] = 'All groups';
$string['trysearchingforgroups'] = 'Try %ssearching for groups%s to join!';
$string['nogroupsfound'] = 'No groups found :(';
$string['group'] = 'group';
$string['Group'] = 'Group';
$string['groups'] = 'groups';
$string['notamember'] = 'You are not a member of this group';
......
......@@ -769,7 +769,8 @@ function group_get_grouptype_options() {
* @param object $group Database record of group to get tabs for
* @return array
*/
function group_get_menu_tabs($group) {
function group_get_menu_tabs() {
$group = group_current_group();
$menu = array(
array(
'path' => 'groups',
......@@ -860,4 +861,22 @@ function group_param_userid($userid) {
return $userid;
}
function group_current_group() {
static $group;
if (defined('INGROUP')) {
$group = get_record_select('group', 'id = ? AND deleted = 0', array(INGROUP), '*, ' . db_format_tsfield('ctime'));
if (!$group) {
throw new GroupNotFoundException(get_string('groupnotfound', 'group', INGROUP));
}
}
else {
$group = null;
}
return $group;
}
?>
......@@ -1799,7 +1799,8 @@ class View {
public static function set_nav($group, $institution) {
if ($group) {
define('MENUITEM', 'groups');
define('MENUITEM', 'groups/views');
define('INGROUP', $group);
}
else if ($institution) {
define('INSTITUTIONALADMIN', 1);
......
......@@ -355,7 +355,7 @@ EOF;
$smarty->assign('LOGGEDIN', $USER->is_logged_in());
if ($USER->is_logged_in()) {
$smarty->assign('MAINNAV', main_nav(isset($extraconfig['group']) ? $extraconfig['group'] : null));
$smarty->assign('MAINNAV', main_nav());
}
else {
$smarty->assign('sitedefaultlang', get_string('sitedefault', 'admin') . ' (' .
......@@ -374,8 +374,8 @@ EOF;
$smarty->assign('PAGEHELPNAME', $help[0]);
$smarty->assign('PAGEHELPICON', $help[1]);
}
if (isset($extraconfig['group'])) {
$smarty->assign('GROUPNAME', str_shorten($extraconfig['group']->name, 20, true));
if (defined('INGROUP')) {
$smarty->assign('INGROUP', INGROUP);
}
// ---------- sideblock stuff ----------
......@@ -1615,7 +1615,7 @@ function institutional_admin_nav() {
/**
* Builds a data structure representing the menu for Mahara.
*/
function main_nav($group=null) {
function main_nav() {
if (defined('ADMIN') || defined('INSTITUTIONALADMIN')) {
global $USER;
$menu = $USER->get('admin') ? admin_nav() : institutional_admin_nav();
......@@ -1679,8 +1679,9 @@ function main_nav($group=null) {
),
);
if ($group) {
foreach (group_get_menu_tabs($group) as $k => $v) {
if (defined('INGROUP')) {
require_once('group.php');
foreach (group_get_menu_tabs() as $k => $v) {
$menu[] = $v;
}
}
......
......@@ -699,7 +699,8 @@ tr.required th,
color: #4c711d;
}
#subnav li.groupname {
color: #000;
background: url(../images/menu-over-bg.gif) repeat-x left;
color: #feef45;
}
/* RIGHT SIDE COLUMN */
......
......@@ -82,10 +82,10 @@
</ul>
</div>
</div>
<div id="subnav"{if $GROUPNAME} class="group"{/if}>
<div id="subnav"{if $INGROUP} class="group"{/if}>
{if $MAINNAVSELECTED.submenu}
<ul>
{if $GROUPNAME}<li class="groupname">{$GROUPNAME} &raquo; </li>{/if}
{if $INGROUP}<li class="groupname">{str tag="Group" section="group"}: </li>{/if}
{foreach from=$MAINNAVSELECTED.submenu item=item}<li{if $item.selected} class="selected"{/if}><a href="{$WWWROOT}{$item.url|escape}">{$item.title|escape}</a></li>{/foreach}
</ul>
{/if}
......
......@@ -41,16 +41,15 @@ require_once('pieforms/pieform.php');
$limit = param_integer('limit', 5);
$offset = param_integer('offset', 0);
$groupid = param_integer('group');
if (!$group = get_record('group', 'id', $groupid, 'deleted', 0)) {
throw new GroupNotFoundException("Couldn't find group with id $groupid");
}
define('INGROUP', $groupid);
$group = group_current_group();
define('TITLE', $group->name . ' - ' . get_string('groupviews', 'view'));
$member = group_user_access($groupid);
$shared = param_boolean('shared', 0) && $member;
$can_edit = group_user_can_edit_views($groupid);
$smarty = smarty(array(), array(), array(), array('group' => $group));
$smarty = smarty();
$smarty->assign('heading', $group->name . ' - ' . get_string('views'));
if ($can_edit) {
......@@ -74,7 +73,6 @@ $pagination = build_pagination(array(
$smarty->assign('groupid', $groupid);
$smarty->assign('groupviews', 1);
$smarty->assign('groupname', $group->name);
$smarty->assign('grouptabs', group_get_menu_tabs($group));
$smarty->assign('member', $member);
$smarty->assign('views', $data->data);
$smarty->assign('pagination', $pagination['html']);
......
Supports Markdown
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