Commit bcf844ea authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "Bug 1719216: Include collections in group participation reports"

parents a9ca9431 5d65907d
......@@ -40,8 +40,8 @@ $pagination = array(
'datatable' => 'sharedviewsreport',
'jsonscript' => 'group/participationsharedviews.json.php',
'setlimit' => true,
'resultcounttextsingular' => get_string('view', 'view'),
'resultcounttextplural' => get_string('views', 'view'),
'resultcounttextsingular' => get_string('portfolio', 'view'),
'resultcounttextplural' => get_string('portfolios', 'view'),
);
$sharedviews = View::render_participation_views($sharedviews, 'group/participationsharedviews.tpl', $pagination);
......@@ -54,8 +54,8 @@ $pagination = array(
'datatable' => 'groupviewsreport',
'jsonscript' => 'group/participationgroupviews.json.php',
'setlimit' => true,
'resultcounttextsingular' => get_string('view', 'view'),
'resultcounttextplural' => get_string('views', 'view'),
'resultcounttextsingular' => get_string('portfolio', 'view'),
'resultcounttextplural' => get_string('portfolios', 'view'),
);
$groupviews = View::render_participation_views($groupviews, 'group/participationgroupviews.tpl', $pagination);
......
......@@ -87,6 +87,8 @@ $string['views'] = 'pages';
$string['viewsandcollections'] = 'pages and collections';
$string['View'] = 'Page';
$string['Views'] = 'Pages';
$string['portfolio'] = 'portfolio';
$string['portfolios'] = 'portfolios';
$string['Viewscollections'] = 'Pages and collections';
$string['viewsubmittedtogroup'] = 'This page has been submitted to <a href="%s">%s</a>.';
$string['viewsubmittedtogroupon'] = 'This page was submitted to <a href="%s">%s</a> on %s.';
......@@ -106,8 +108,11 @@ $string['youhavenviews'] = array(
'You have %d pages.',
);
$string['viewsownedbygroup'] = 'Pages owned by this group';
$string['ownedbygroup'] = 'Owned by this group';
$string['nogroupviewsyet'] = 'There are no pages in this group yet';
$string['viewscollectionssharedtogroup'] = 'Pages and collections shared with this group';
$string['viewssharedtogroup'] = 'Pages shared with this group';
$string['sharedtogroup'] = 'Shared with this group';
$string['nosharedviewsyet'] = 'There are no pages shared with this group yet';
$string['viewssharedtogroupbyothers'] = 'Pages shared with this group by others';
$string['sharedviews'] = 'Shared pages';
......
......@@ -5000,6 +5000,61 @@ class View {
);
}
private static function _get_participation_sql($type) {
$sql = "
SELECT CASE WHEN coll IS NOT NULL THEN c.name ELSE v.title END AS title,
CASE WHEN coll IS NOT NULL THEN (SELECT view FROM {collection_view} WHERE collection = coll ORDER BY displayorder ASC LIMIT 1) ELSE vc END AS vid,
coll AS collid,
SUM(mc) AS membercommentcount,
SUM(nmc) AS nonmembercommentcount
FROM (
SELECT c.id AS coll, -- count comments and group by collection or view id
CASE WHEN c.id IS NULL THEN v.id ELSE c.id END AS vc,
COUNT(artefact) AS mc, 0 as nmc
FROM {view} v
LEFT JOIN ( -- Get all comment artefacts
SELECT acc.artefact, acc.onview FROM {artefact_comment_comment} acc
JOIN {artefact} a ON a.id = acc.artefact
WHERE EXISTS ( -- Where author is a group member
SELECT 1 FROM {group_member} m2
WHERE m2.group = ? AND m2.member = a.author
)
) AS sub ON v.id = sub.onview
LEFT JOIN {collection_view} cv ON cv.view = v.id
LEFT JOIN {collection} c ON c.id = cv.collection
GROUP BY CASE WHEN c.id IS NULL THEN v.id ELSE c.id END, coll
UNION
SELECT c.id AS coll, -- count comments and group by collection or view id
CASE WHEN c.id IS NULL THEN v.id ELSE c.id END AS vc,
0 as mc, COUNT(artefact) AS nmc
FROM {view} v
LEFT JOIN ( -- Get all comment artefacts
SELECT acc.artefact, acc.onview FROM {artefact_comment_comment} acc
JOIN {artefact} a ON a.id = acc.artefact
WHERE NOT EXISTS ( -- Where author is not a group member
SELECT 1 FROM {group_member} m2
WHERE m2.group = ? AND m2.member = a.author
)
) AS sub ON v.id = sub.onview
LEFT JOIN {collection_view} cv ON cv.view = v.id
LEFT JOIN {collection} c ON c.id = cv.collection
GROUP BY CASE WHEN c.id IS NULL THEN v.id ELSE c.id END, coll
) AS foo
LEFT JOIN {collection} c ON c.id = coll -- group together member and non member results as one row per collection / view
LEFT JOIN {view} v ON v.id = vc";
if ($type == 'groupview') {
$sql .= " WHERE (v.group = ? OR c.group = ?) ";
}
else if ($type == 'sharedview') {
$sql .= " JOIN {view_access} va ON (va.view = CASE WHEN coll IS NOT NULL THEN (
SELECT view FROM {collection_view} WHERE collection = coll ORDER BY displayorder ASC LIMIT 1
) ELSE vc END AND va.group = ?)";
$sql .= " WHERE ((v.group IS NULL OR v.group != ?) AND (c.group IS NULL OR c.group != ?))";
}
$sql .= " GROUP BY coll, vc, c.name, v.title";
return $sql;
}
/**
* Get all group views and its participation info excluding the view in collections
*
......@@ -5023,64 +5078,28 @@ class View {
if (!group_user_access($groupid)) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
// Query group views with number of member comments
$sql1 = "
SELECT DISTINCT v.id, count(DISTINCT ac.artefact) AS membercommentcount
FROM {view} v
LEFT JOIN (
SELECT c.*
FROM {artefact_comment_comment} c
INNER JOIN {artefact} a ON (a.id = c.artefact)
WHERE EXISTS (SELECT 1 FROM {group_member} m2 WHERE m2.group = ? AND m2.member = a.author)
) ac ON (ac.onview = v.id)
WHERE v.group = ?
AND NOT EXISTS (SELECT 1 FROM {collection_view} cv WHERE cv.view = v.id)
GROUP BY v.id ";
$ph = array($groupid, $groupid);
// Query shared views with number of non-member comments
$sql2 = "
SELECT DISTINCT v.id, count(DISTINCT ac.artefact) AS nonmembercommentcount
FROM {view} v
LEFT JOIN (
SELECT c.*
FROM {artefact_comment_comment} c
INNER JOIN {artefact} a ON (a.id = c.artefact)
WHERE NOT EXISTS (SELECT 1 FROM {group_member} m2 WHERE m2.group = ? AND m2.member = a.author)
) ac ON (ac.onview = v.id)
WHERE v.group = ?
AND NOT EXISTS (SELECT 1 FROM {collection_view} cv WHERE cv.view = v.id)
GROUP BY v.id ";
$ph = array_merge($ph, array($groupid, $groupid));
$from = '
FROM {view} v
INNER JOIN (' . $sql1 . ') pv1 ON (pv1.id = v.id)
INNER JOIN (' . $sql2 . ') pv2 ON (pv2.id = v.id) ';
$count = count_records_sql('SELECT COUNT(DISTINCT(v.id)) ' . $from, $ph);
if (in_array($sort, array('title', 'owner', 'membercommentcount', 'nonmembercommentcount'))
// Get the count of member and non-member comments for both collections and stand alone pages
$selectsql = self::_get_participation_sql('groupview');
$where = array($groupid, $groupid, $groupid, $groupid);
$count = count_records_sql("SELECT COUNT(*) FROM (" . $selectsql . ") as ct", $where);
if (in_array($sort, array('title', 'membercommentcount', 'nonmembercommentcount'))
&& in_array($direction, array('asc', 'desc'))) {
$ordersql = "$sort $direction";
$ordersql = " ORDER BY $sort $direction";
}
else {
$ordersql = "v.title, v.id";
$ordersql = " ORDER BY title DESC";
}
$viewdata = get_records_sql_assoc('
SELECT DISTINCT v.id,v.title,v.startdate,v.stopdate,v.description,v.group,v.owner,v.ownerformat,v.institution,v.urlid, membercommentcount, nonmembercommentcount'
. $from . '
ORDER BY '. $ordersql,
$ph, $offset, $limit
);
if ($viewdata) {
// Get more info about view comments
foreach ($viewdata as &$view) {
if (isset($view->group)) {
$view->groupname = get_field('group', 'name', 'id', $view->group);
}
$viewdata = get_records_sql_assoc($selectsql . $ordersql, $where, $offset, $limit);
if (!empty($viewdata)) {
foreach ($viewdata as &$view) {
$view->id = $view->vid;
$view->collection = $view->collid;
$viewobj = new View($view->id);
$view->url = $viewobj->get_url();
self::get_view_comment_info($view, $groupid);
}
}
......@@ -5120,65 +5139,34 @@ class View {
if (!group_user_access($groupid)) {
throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
// Query shared views with number of member comments
$sql1 = "
SELECT DISTINCT v.id, count(DISTINCT ac.artefact) AS membercommentcount
FROM {view} v
INNER JOIN {view_access} va ON (va.view = v.id)
LEFT JOIN (
SELECT c.*
FROM {artefact_comment_comment} c
INNER JOIN {artefact} a ON (a.id = c.artefact)
WHERE EXISTS (SELECT 1 FROM {group_member} m2 WHERE m2.group = ? AND m2.member = a.author)
) ac ON (ac.onview = v.id)
WHERE va.group = ? AND (v.group IS NULL OR v.group != ?)
AND NOT EXISTS (SELECT 1 FROM {collection_view} cv WHERE cv.view = v.id)
GROUP BY v.id ";
$ph = array($groupid, $groupid, $groupid);
// Query shared views with number of non-member comments
$sql2 = "
SELECT DISTINCT v.id, count(DISTINCT ac.artefact) AS nonmembercommentcount
FROM {view} v
INNER JOIN {view_access} va ON (va.view = v.id)
LEFT JOIN (
SELECT c.*
FROM {artefact_comment_comment} c
INNER JOIN {artefact} a ON (a.id = c.artefact)
WHERE NOT EXISTS (SELECT 1 FROM {group_member} m2 WHERE m2.group = ? AND m2.member = a.author)
) ac ON (ac.onview = v.id)
WHERE va.group = ? AND (v.group IS NULL OR v.group != ?)
AND NOT EXISTS (SELECT 1 FROM {collection_view} cv WHERE cv.view = v.id)
GROUP BY v.id ";
$ph = array_merge($ph, array($groupid, $groupid, $groupid));
$from = '
FROM {view} v
INNER JOIN (' . $sql1 . ') pv1 ON (pv1.id = v.id)
INNER JOIN (' . $sql2 . ') pv2 ON (pv2.id = v.id) ';
$count = count_records_sql('SELECT COUNT(DISTINCT(v.id)) ' . $from, $ph);
if (in_array($sort, array('title', 'owner', 'membercommentcount', 'nonmembercommentcount'))
// Get the count of member and non-member comments for both collections and stand alone pages
$selectsql = self::_get_participation_sql('sharedview');
$where = array($groupid, $groupid, $groupid, $groupid, $groupid);
$count = count_records_sql("SELECT COUNT(*) FROM (" . $selectsql . ") as ct", $where);
if (in_array($sort, array('title', 'membercommentcount', 'nonmembercommentcount'))
&& in_array($direction, array('asc', 'desc'))) {
$ordersql = "$sort $direction";
$ordersql = " ORDER BY $sort $direction";
}
else {
$ordersql = "v.title, v.id";
$ordersql = " ORDER BY title DESC";
}
$viewdata = get_records_sql_assoc('
SELECT DISTINCT v.id,v.title,v.startdate,v.stopdate,v.description,v.group,v.owner,v.ownerformat,v.institution,v.urlid, membercommentcount, nonmembercommentcount'
. $from . '
ORDER BY '. $ordersql,
$ph, $offset, $limit
);
$viewdata = get_records_sql_assoc($selectsql . $ordersql, $where, $offset, $limit);
if ($viewdata) {
// Get more info about view comments
foreach ($viewdata as &$view) {
if (isset($view->group)) {
$view->groupname = get_field('group', 'name', 'id', $view->group);
}
$view->id = $view->vid;
$view->collection = $view->collid;
$viewobj = new View($view->id);
$view->url = $viewobj->get_url();
$view->owner = $viewobj->owner;
$view->group = $viewobj->group;
$view->institution = $viewobj->institution;
if (!empty($view->group)) {
$view->groupname = get_field('group', 'name', 'id', $view->group);
}
self::get_view_comment_info($view, $groupid);
}
......@@ -5207,54 +5195,64 @@ class View {
* @param $groupid a ID of the group that the view is shared with
*/
public static function get_view_comment_info(&$view, $groupid) {
$viewcomments = get_records_sql_array('
SELECT
a.id, a.author, a.authorname, a.ctime, a.mtime, a.description, a.group,
c.private, c.deletedby, c.requestpublic, c.rating, c.lastcontentupdate,
u.username, u.firstname, u.lastname, u.preferredname, u.email, u.staff, u.admin,
u.deleted, u.profileicon, u.urlid
FROM {artefact} a
INNER JOIN {artefact_comment_comment} c ON a.id = c.artefact
LEFT JOIN {usr} u ON a.author = u.id
WHERE c.onview = ?'
, array($view->id));
if (isset($view->collection)) {
$views = get_column('collection_view', 'view', 'collection', $view->collid);
}
else {
$views = array($view->id);
}
$extcommenters = 0;
$membercommenters = 0;
$extcomments = 0;
$membercomments = 0;
$commenters = array();
if ($viewcomments && is_array($viewcomments)) {
foreach ($viewcomments as $c) {
if (empty($c->author)) {
if (!isset($commenters[$c->authorname])) {
$commenters[$c->authorname] = array();
}
$commenters[$c->authorname]['commenter'] = $c->authorname;
$commenters[$c->authorname]['count'] = (isset($commenters[$c->authorname]['count']) ? $commenters[$c->authorname]['count'] + 1 : 1);
if ($commenters[$c->authorname]['count'] == 1) {
$extcommenters++;
}
$extcomments++;
}
else {
if (!isset($commenters[$c->author])) {
$commenters[$c->author] = array();
}
$commenters[$c->author]['commenter'] = (int) $c->author;
$commenters[$c->author]['member'] = group_user_access($groupid, $c->author);
$commenters[$c->author]['count'] = (isset($commenters[$c->author]['count']) ? $commenters[$c->author]['count'] + 1 : 1);
if (empty($commenters[$c->author]['member'])) {
if ($commenters[$c->author]['count'] == 1) {
foreach ($views as $v) {
$viewcomments = get_records_sql_array('
SELECT
a.id, a.author, a.authorname, a.ctime, a.mtime, a.description, a.group,
c.private, c.deletedby, c.requestpublic, c.rating, c.lastcontentupdate,
u.username, u.firstname, u.lastname, u.preferredname, u.email, u.staff, u.admin,
u.deleted, u.profileicon, u.urlid
FROM {artefact} a
INNER JOIN {artefact_comment_comment} c ON a.id = c.artefact
LEFT JOIN {usr} u ON a.author = u.id
WHERE c.onview = ?'
, array($v));
if ($viewcomments && is_array($viewcomments)) {
foreach ($viewcomments as $c) {
if (empty($c->author)) {
if (!isset($commenters[$c->authorname])) {
$commenters[$c->authorname] = array();
}
$commenters[$c->authorname]['commenter'] = $c->authorname;
$commenters[$c->authorname]['count'] = (isset($commenters[$c->authorname]['count']) ? $commenters[$c->authorname]['count'] + 1 : 1);
if ($commenters[$c->authorname]['count'] == 1) {
$extcommenters++;
}
$extcomments++;
}
else {
if ($commenters[$c->author]['count'] == 1) {
$membercommenters++;
if (!isset($commenters[$c->author])) {
$commenters[$c->author] = array();
}
$commenters[$c->author]['commenter'] = (int) $c->author;
$commenters[$c->author]['member'] = group_user_access($groupid, $c->author);
$commenters[$c->author]['count'] = (isset($commenters[$c->author]['count']) ? $commenters[$c->author]['count'] + 1 : 1);
if (empty($commenters[$c->author]['member'])) {
if ($commenters[$c->author]['count'] == 1) {
$extcommenters++;
}
$extcomments++;
}
else {
if ($commenters[$c->author]['count'] == 1) {
$membercommenters++;
}
$membercomments++;
}
$membercomments++;
}
}
}
......@@ -5265,6 +5263,7 @@ class View {
$view->mcomments = $membercomments;
$view->ecomments = $extcomments;
$view->comments = $commenters;
$view->viewcount = count($views);
}
/**
......
{if count($items) > 0}
{foreach from=$items item=view}
<tr class="{cycle values='r0,r1'}">
<td class="sv"><a href="{$view->url}">{$view->title}</a></td>
<td class="sv"><a href="{$view->url}">{$view->title}</a>{if $view->collection} <span class="text-small text-midtone">({str tag='nviews' section='view' arg1=$view->viewcount})</span>{/if}</td>
<td class="mc"><label class="hidden">{str tag=membercommenters section=group}: </label>
<ul class="list-nested list-unstyled">
{foreach from=$view->comments key=commenter item=info}
......
{if $itemcount}
{foreach from=$items item=view}
<tr class="{cycle values='r0,r1'}">
<td class="sv"><a href="{$view->url}">{$view->title}</a></td>
<td class="sv"><a href="{$view->url}">{$view->title}</a>{if $view->collection} <span class="text-small text-midtone">({str tag='nviews' section='view' arg1=$view->viewcount})</span>{/if}</td>
<td class="sb"><label class="hidden">{str tag=sharedby section=view}: </label>
{if $view->owner}
<a href="{$WWWROOT}user/view.php?id={$view->owner}">{$view->owner|display_name:null:true}</a>
......
{include file="header.tpl"}
<h3>{str tag=viewssharedtogroup section=view}</h3>
<h3>{str tag=viewscollectionssharedtogroup section=view}</h3>
{if $sharedviews.count == '0'}
<p class="no-results">
{str tag=noviewssharedwithgroupyet section=group}
......@@ -9,7 +9,7 @@
<thead>
<tr>
<th class="sv {if $sort == title && $direction == asc}asc{elseif $sort == title}sorted{/if}">
<a href="{$baseurl}&sort=title{if $sort == title && $direction == asc}&direction=desc{/if}">{str tag=viewssharedtogroup section=view}</a>
<a href="{$baseurl}&sort=title{if $sort == title && $direction == asc}&direction=desc{/if}">{str tag=sharedtogroup section=view}</a>
</th>
<th class="sb {if $sort == owner && $direction == asc}asc{elseif $sort == owner}sorted{/if}">
<a href="{$baseurl}&sort=owner{if $sort == owner && $direction == asc}&direction=desc{/if}">{str tag=sharedby section=view}</a>
......@@ -45,7 +45,7 @@
<tr>
<th class="sv {if $sort == title && $direction == asc}asc{elseif $sort == title}sorted{/if}">
<a href="{$baseurl}&sort=title{if $sort == title && $direction == asc}&direction=desc{/if}">
{str tag=viewsownedbygroup section=view}
{str tag=ownedbygroup section=view}
</a>
</th>
<th class="mc {if $sort == membercommentcount && $direction == asc}asc{elseif $sort == membercommentcount}sorted{/if}">
......@@ -54,7 +54,7 @@
</a>
</th>
<th class="ec {if $sort == nonmembercommentcount && $direction == asc}asc{elseif $sort == nonmembercommentcount}sorted{/if}">
<a href="{$baseurl}&sort=ecomment{if $sort == nonmembercommentcount && $direction == asc}&direction=desc{/if}">{str tag=extcommenters section=group}
<a href="{$baseurl}&sort=nonmembercommentcount{if $sort == nonmembercommentcount && $direction == asc}&direction=desc{/if}">{str tag=extcommenters section=group}
</a>
</th>
</tr>
......
{if count($items) > 0}
{foreach from=$items item=view}
<tr class="{cycle values='r0,r1'}">
<td class="sv"><a href="{$view->url}">{$view->title}</a></td>
<td class="sv"><a href="{$view->url}">{$view->title}</a>{if $view->collection} <span class="text-small text-midtone">({str tag='nviews' section='view' arg1=$view->viewcount})</span>{/if}</td>
<td class="mc"><label class="hidden">{str tag=membercommenters section=group}: </label>
<ul class="list-nested list-unstyled">
{foreach from=$view->comments key=commenter item=info}
......
{if $itemcount}
{foreach from=$items item=view}
<tr class="{cycle values='r0,r1'}">
<td class="sv"><a href="{$view->url}">{$view->title}</a></td>
<td class="sv"><a href="{$view->url}">{$view->title}</a>{if $view->collection} <span class="text-small text-midtone">({str tag='nviews' section='view' arg1=$view->viewcount})</span>{/if}</td>
<td class="sb"><label class="hidden">{str tag=sharedby section=view}: </label>
{if $view->owner}
<a href="{$WWWROOT}user/view.php?id={$view->owner}">{$view->owner|display_name:null:true}</a>
......
{include file="header.tpl"}
<h3>{str tag=viewssharedtogroup section=view}</h3>
<h3>{str tag=viewscollectionssharedtogroup section=view}</h3>
{if $sharedviews.count == '0'}
<p class="no-results">
{str tag=noviewssharedwithgroupyet section=group}
......@@ -9,7 +9,7 @@
<thead>
<tr>
<th class="sv {if $sort == title && $direction == asc}asc{elseif $sort == title}sorted{/if}">
<a href="{$baseurl}&sort=title{if $sort == title && $direction == asc}&direction=desc{/if}">{str tag=viewssharedtogroup section=view}</a>
<a href="{$baseurl}&sort=title{if $sort == title && $direction == asc}&direction=desc{/if}">{str tag=sharedtogroup section=view}</a>
</th>
<th class="sb {if $sort == owner && $direction == asc}asc{elseif $sort == owner}sorted{/if}">
<a href="{$baseurl}&sort=owner{if $sort == owner && $direction == asc}&direction=desc{/if}">{str tag=sharedby section=view}</a>
......@@ -45,7 +45,7 @@
<tr>
<th class="sv {if $sort == title && $direction == asc}asc{elseif $sort == title}sorted{/if}">
<a href="{$baseurl}&sort=title{if $sort == title && $direction == asc}&direction=desc{/if}">
{str tag=viewsownedbygroup section=view}
{str tag=ownedbygroup section=view}
</a>
</th>
<th class="mc {if $sort == membercommentcount && $direction == asc}asc{elseif $sort == membercommentcount}sorted{/if}">
......@@ -54,7 +54,7 @@
</a>
</th>
<th class="ec {if $sort == nonmembercommentcount && $direction == asc}asc{elseif $sort == nonmembercommentcount}sorted{/if}">
<a href="{$baseurl}&sort=ecomment{if $sort == nonmembercommentcount && $direction == asc}&direction=desc{/if}">{str tag=extcommenters section=group}
<a href="{$baseurl}&sort=nonmembercommentcount{if $sort == nonmembercommentcount && $direction == asc}&direction=desc{/if}">{str tag=extcommenters section=group}
</a>
</th>
</tr>
......
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