Commit 1f922f96 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Finish profile view merge

parent 5aee6323
......@@ -53,15 +53,12 @@ class PluginBlocktypeMyGroups extends SystemBlocktype {
$smarty = smarty_core();
require_once('group.php');
// Group stuff
// if (!$userassocgroups = get_associated_groups($userid, false)) {
if (true) { // TODO RICHARDM!
$userassocgroups = array();
}
$results = group_get_associated_groups($userid, 'member');
foreach ($userassocgroups as $group) {
foreach ($results['groups'] as $group) {
$group->description = str_shorten($group->description, 100, true);
}
$smarty->assign('USERGROUPS',$userassocgroups);
$smarty->assign('USERGROUPS',$results['groups']);
return $smarty->fetch('blocktype:mygroups:mygroups.tpl');
}
......
......@@ -39,83 +39,7 @@ $offset = param_integer('offset', 'all');
$groupsperpage = 20;
$offset = (int)($offset / $groupsperpage) * $groupsperpage;
// Strangely, casting is only needed for invite, request and admin and only in
// postgres
if (is_mysql()) {
$invitesql = "'invite'";
$requestsql = "'request'";
$adminsql = "'admin'";
$empty = "''";
}
else {
$invitesql = "CAST('invite' AS TEXT)";
$requestsql = "CAST('request' AS TEXT)";
$adminsql = "CAST('admin' AS TEXT)";
$empty = "CAST('' AS TEXT)";
}
// Different filters join on the different kinds of association
if ($filter == 'admin') {
$sql = "
INNER JOIN (
SELECT g.id, $adminsql AS membershiptype, $empty AS reason, $empty AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
) t ON t.id = g.id";
$values = array($USER->get('id'));
}
else if ($filter == 'member') {
$sql = "
INNER JOIN (
SELECT g.id, 'admin' AS membershiptype, $empty AS reason, $empty AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS type, $empty AS reason, $empty AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role != 'admin')
) t ON t.id = g.id";
$values = array($USER->get('id'), $USER->get('id'));
}
else if ($filter == 'invite') {
$sql = "
INNER JOIN (
SELECT g.id, $invitesql AS membershiptype, gmi.reason, gmi.role
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
) t ON t.id = g.id";
$values = array($USER->get('id'));
}
else if ($filter == 'request') {
$sql = "
INNER JOIN (
SELECT g.id, $requestsql AS membershiptype, gmr.reason, $empty AS role
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id";
$values = array($USER->get('id'));
}
else { // all or some other text
$filter = 'all';
$sql = "
INNER JOIN (
SELECT g.id, 'admin' AS membershiptype, '' AS reason, '' AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS membershiptype, '' AS reason, '' AS role
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')
UNION
SELECT g.id, 'invite' AS membershiptype, gmi.reason, gmi.role
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION SELECT g.id, 'request' AS membershiptype, gmr.reason, '' AS role
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id";
$values = array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'));
}
$results = group_get_associated_groups($USER->get('id'), $filter, $groupsperpage, $offset);
$form = pieform(array(
'name' => 'filter',
......@@ -140,58 +64,19 @@ $form = pieform(array(
),
));
$values[] = 0;
$count = count_records_sql('SELECT COUNT(*) FROM {group} g ' . $sql . ' WHERE g.deleted = ?', $values);
// almost the same as query used in find - common parts should probably be pulled out
// gets the groups filtered by above
// and the first three members by id
$sql = 'SELECT g.id, g.name, g.description, g.jointype, g.grouptype, t.membershiptype, t.reason, t.role, COUNT(gm.member) AS membercount, COUNT(gmr.member) AS requests
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN {group_member_request} gmr ON (gmr.group = g.id)' .
$sql . '
WHERE g.deleted = ?
GROUP BY g.id, g.name, g.description, g.jointype, g.grouptype, t.membershiptype, t.reason, t.role
ORDER BY g.name';
$groups = get_records_sql_assoc($sql, $values, $offset, $groupsperpage);
if ($groups) {
// Get 3 members from each group in a separate query -- mysql doesn't like including them as subqueries with limit 1 in the above query
$members = get_records_sql_array("
SELECT m1.group, m1.member, u.* FROM {group_member} m1
INNER JOIN {usr} u ON (m1.member = u.id AND u.deleted = 0)
WHERE 3 > (
SELECT COUNT(m2.member)
FROM {group_member} m2
WHERE m1.group = m2.group AND m2.member < m1.member
)
AND m1.group IN (" . join(',', array_keys($groups)) . ")", array());
foreach ($members as $m) {
$groups[$m->group]->members[] = (object) array('id' => $m->id, 'name' => display_name($m));
}
$groups = array_values($groups);
}
else {
$groups = array();
}
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'group/mygroups.php?filter=' . $filter,
'count' => $count,
'count' => $results['count'],
'limit' => $groupsperpage,
'offset' => $offset,
'resultcounttextsingular' => get_string('group', 'group'),
'resultcounttextplural' => get_string('groups', 'group'),
));
group_prepare_usergroups_for_display($groups, 'mygroups');
group_prepare_usergroups_for_display($results['groups'], 'mygroups');
$smarty = smarty();
$smarty->assign('groups', $groups);
$smarty->assign('groups', $results['groups']);
$smarty->assign('form', $form);
$smarty->assign('filter', $filter);
$smarty->assign('pagination', $pagination['html']);
......
......@@ -1315,15 +1315,20 @@ function xmldb_core_upgrade($oldversion=0) {
create_table($table);
insert_record('event_subscription', (object)array('event' => 'createuser', 'callfunction' => 'activity_set_defaults'));
}
if ($oldversion < 2008091601) {
$table = new XMLDBTable('view_type');
$table->addFieldInfo('type', XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('type'));
create_table($table);
$viewtypes = array('portfolio', 'profile');
foreach ($viewtypes as $vt) {
insert_record('view_type', (object)array(
'type' => $vt,
));
}
$table = new XMLDBTable('blocktype_installed_viewtype');
$table->addFieldInfo('blocktype', XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('viewtype', XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
......@@ -1344,13 +1349,6 @@ function xmldb_core_upgrade($oldversion=0) {
$field->setAttributes(XMLDB_TYPE_CHAR, 50, XMLDB_UNSIGNED, XMLDB_NOTNULL);
change_field_notnull($table, $field);
$viewtypes = array('portfolio', 'profile');
foreach ($viewtypes as $vt) {
insert_record('view_type', (object)array(
'type' => $vt,
));
}
if ($blocktypes = plugins_installed('blocktype')) {
foreach ($blocktypes as $bt) {
install_blocktype_viewtypes_for_plugin(blocktype_single_to_namespaced($bt->name, $bt->artefactplugin));
......
......@@ -919,4 +919,127 @@ function group_sideblock() {
}
function group_get_associated_groups($userid, $filter='all', $limit=20, $offset=0) {
// Strangely, casting is only needed for invite, request and admin and only in
// postgres
if (is_mysql()) {
$invitesql = "'invite'";
$requestsql = "'request'";
$adminsql = "'admin'";
$empty = "''";
}
else {
$invitesql = "CAST('invite' AS TEXT)";
$requestsql = "CAST('request' AS TEXT)";
$adminsql = "CAST('admin' AS TEXT)";
$empty = "CAST('' AS TEXT)";
}
// Different filters join on the different kinds of association
if ($filter == 'admin') {
$sql = "
INNER JOIN (
SELECT g.id, $adminsql AS membershiptype, $empty AS reason, $empty AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
) t ON t.id = g.id";
$values = array($userid);
}
else if ($filter == 'member') {
$sql = "
INNER JOIN (
SELECT g.id, 'admin' AS membershiptype, $empty AS reason, $empty AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS type, $empty AS reason, $empty AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role != 'admin')
) t ON t.id = g.id";
$values = array($userid, $userid);
}
else if ($filter == 'invite') {
$sql = "
INNER JOIN (
SELECT g.id, $invitesql AS membershiptype, gmi.reason, gmi.role
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
) t ON t.id = g.id";
$values = array($userid);
}
else if ($filter == 'request') {
$sql = "
INNER JOIN (
SELECT g.id, $requestsql AS membershiptype, gmr.reason, $empty AS role
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id";
$values = array($userid);
}
else { // all or some other text
$filter = 'all';
$sql = "
INNER JOIN (
SELECT g.id, 'admin' AS membershiptype, '' AS reason, '' AS role
FROM {group} g
INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')
UNION
SELECT g.id, 'member' AS membershiptype, '' AS reason, '' AS role
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')
UNION
SELECT g.id, 'invite' AS membershiptype, gmi.reason, gmi.role
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION SELECT g.id, 'request' AS membershiptype, gmr.reason, '' AS role
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id";
$values = array($userid, $userid, $userid, $userid);
}
$values[] = 0;
$count = count_records_sql('SELECT COUNT(*) FROM {group} g ' . $sql . ' WHERE g.deleted = ?', $values);
// almost the same as query used in find - common parts should probably be pulled out
// gets the groups filtered by above
// and the first three members by id
$sql = 'SELECT g.id, g.name, g.description, g.jointype, g.grouptype, t.membershiptype, t.reason, t.role, COUNT(gm.member) AS membercount, COUNT(gmr.member) AS requests
FROM {group} g
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN {group_member_request} gmr ON (gmr.group = g.id)' .
$sql . '
WHERE g.deleted = ?
GROUP BY g.id, g.name, g.description, g.jointype, g.grouptype, t.membershiptype, t.reason, t.role
ORDER BY g.name';
$groups = get_records_sql_assoc($sql, $values, $offset, $limit);
if ($groups) {
// Get 3 members from each group in a separate query -- mysql doesn't like including them as subqueries with limit 1 in the above query
$members = get_records_sql_array("
SELECT m1.group, m1.member, u.* FROM {group_member} m1
INNER JOIN {usr} u ON (m1.member = u.id AND u.deleted = 0)
WHERE 3 > (
SELECT COUNT(m2.member)
FROM {group_member} m2
WHERE m1.group = m2.group AND m2.member < m1.member
)
AND m1.group IN (" . join(',', array_keys($groups)) . ")", array());
foreach ($members as $m) {
$groups[$m->group]->members[] = (object) array('id' => $m->id, 'name' => display_name($m));
}
$groups = array_values($groups);
}
else {
$groups = array();
}
return array('groups' => $groups, 'count' => $count);
}
?>
......@@ -1300,11 +1300,27 @@ function can_view_view($view_id, $user_id=null) {
if (!$USER->is_logged_in()) {
// check public
if (get_config('allowpublicviews') == '1') {
$public = get_record('view_access', 'view', $view_id, 'accesstype', 'public');
return ($public
$publicviews = get_config('allowpublicviews');
$publicprofiles = get_config('allowpublicprofiles');
if ($publicviews || $publicprofiles) {
$public = get_record_sql("
SELECT
v.id, v.type, va.*
FROM
{view} v
LEFT OUTER JOIN {view_access} a ON v.id = a.view
WHERE
v.id = ?
AND (a.accesstype = 'public' OR v.type = 'profile')
", array($view_id));
return $public &&
( ( $publicviews && $public->accesstype == 'public'
&& ( $public->startdate == null || $public->startdate < $now )
&& ( $public->stopdate == null || $public->stopdate > $now ));
&& ( $public->stopdate == null || $public->stopdate > $now )
)
||
( $publicprofiles && $public->type == 'profile' )
);
}
return false;
}
......
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