Commit 33c4a9b7 authored by Cecilia Vela Gurovic's avatar Cecilia Vela Gurovic Committed by Cecilia Vela Gurovic

Bug 1386000: Group homepage to only show submitted items once

Change group homepage so that it does not to show repeated pages/collections in different sections shared/submitted
Updated create_group() in TestingDataGenerator.php to set in the DB the correct group role of a user

Change-Id: I07504f38a35d4dda4a3c4f440d94cffed293bbf2
parent dc852194
......@@ -319,6 +319,7 @@ class PluginBlocktypeGroupViews extends MaharaCoreBlocktype {
// For group members, display a list of views that others have
// shared to the group
$hidesubmitted = group_user_can_assess_submitted_views($group->id, $USER->get('id'));
if (empty($configdata['showsharedviews'])) {
$data['sharedviews'] = (object) array(
'data' => array(),
......@@ -333,7 +334,8 @@ class PluginBlocktypeGroupViews extends MaharaCoreBlocktype {
0,
$group->id,
($configdata['showsharedviews'] == 2 ? false : true),
$sortsharedviewsby
$sortsharedviewsby,
$hidesubmitted
);
foreach ($data['sharedviews']->data as &$view) {
if (!$editing && isset($view['template']) && $view['template']) {
......@@ -356,7 +358,8 @@ class PluginBlocktypeGroupViews extends MaharaCoreBlocktype {
0,
$group->id,
($configdata['showsharedcollections'] == 2 ? false : true),
$sortsharedcollectionsby
$sortsharedcollectionsby,
$hidesubmitted
);
}
if (!empty($configdata['showsubmitted'])
......
......@@ -4570,9 +4570,10 @@ class View {
* @param int $groupid
* @param boolean $membersonly Only return pages owned by members of the group
* @param string $orderby Columns to sort by (defaults to (title, id) if empty)
* @param boolean $hidesubmitted Do not return pages submitted to the group
* @throws AccessDeniedException
*/
public static function get_sharedviews_data($limit=10, $offset=0, $groupid, $membersonly = false, $orderby = null) {
public static function get_sharedviews_data($limit=10, $offset=0, $groupid, $membersonly = false, $orderby = null, $hidesubmitted = false) {
global $USER;
$userid = $USER->get('id');
require_once(get_config('libroot') . 'group.php');
......@@ -4591,11 +4592,17 @@ class View {
AND (v.stopdate > CURRENT_TIMESTAMP OR v.stopdate IS NULL)
AND NOT EXISTS (SELECT 1 FROM {collection_view} cv WHERE cv.view = v.id)';
$ph = array($groupid, $userid, $groupid);
if ($hidesubmitted) {
$where .= 'AND (v.submittedgroup IS NULL OR v.submittedgroup != ?)';
$ph[] = $groupid;
}
if ($membersonly) {
$from .= ' INNER JOIN {group_member} m2 ON m2.member = v.owner ';
$where .= ' AND m2.group = ? ';
$ph[] = $groupid;
}
$count = count_records_sql('SELECT COUNT(DISTINCT(v.id)) ' . $from . $where, $ph);
if ($orderby === null) {
$ordersql = ' ORDER BY v.title, v.id';
......@@ -4612,7 +4619,6 @@ class View {
$offset,
$limit
);
if ($viewdata) {
View::get_extra_view_info($viewdata, false);
}
......@@ -4944,9 +4950,10 @@ class View {
* @param integer $groupid
* @param boolean $membersonly Only return collections owned by members of the gorup
* @param array $sort Columns to sort by (defaults to (title, id) if empty)
* @param boolean $hidesubmitted Do not return collections submitted to the group
* @return array of collections
*/
public static function get_sharedcollections_data($limit=10, $offset=0, $groupid, $membersonly = false, $sort = null) {
public static function get_sharedcollections_data($limit=10, $offset=0, $groupid, $membersonly = false, $sort = null, $hidesubmitted = false) {
global $USER;
$userid = $USER->get('id');
......@@ -4979,6 +4986,11 @@ class View {
$ph[] = $groupid;
}
if ($hidesubmitted) {
$where .= 'AND (v.submittedgroup IS NULL OR v.submittedgroup != ?)';
$ph[] = $groupid;
}
$count = count_records_sql('SELECT COUNT(DISTINCT c.id) ' . $from . $where, $ph);
// NOTE: If you change the number of columns here you may need to change the numeric
// column identifier (10) in the sortorder section
......
......@@ -327,13 +327,18 @@ EOD;
$members[$ids[0]->id] = 'member';
}
}
if (!empty($record['staff'])) {
if (!empty($record['staff']) && !empty($record['grouptype'])) {
foreach (explode(',', $record['staff']) as $membername) {
$ids = get_records_sql_array('SELECT id FROM {usr} WHERE LOWER(TRIM(username)) = ?', array(strtolower(trim($membername))));
if (!$ids || count($ids) > 1) {
throw new SystemException("Invalid group staff '" . $membername . "'. The username does not exist or duplicated");
}
$members[$ids[0]->id] = 'staff';
if ($record['grouptype'] == 'course') {
$members[$ids[0]->id] = 'tutor';
}
else {
$members[$ids[0]->id] = 'admin';
}
}
}
if (!empty($record['admins'])) {
......@@ -810,4 +815,4 @@ EOD;
$activity = new ActivityTypeMaharamessage($data, false);
$activity->notify_users();
}
}
\ No newline at end of file
}
......@@ -46,7 +46,7 @@ Scenario: Uploading groups via CSV and editing as an admin (Bug 1420590)
| userB | Kupuhipa1 | test02@example.com | Pete | Mc | mahara | internal | member |
And the following "groups" exist:
| name | owner | description | grouptype | open | invitefriends | editroles | submittableto | allowarchives | members | staff |
| group 01 | userB | This is group 01 | standard | ON | ON | all | ON | ON | admin, userA | admin |
| group 01 | userB | This is group 01 | course | ON | ON | all | ON | ON | admin, userA | admin |
And I follow "Logout"
# Logging back in as a user
And I log in as "userB" with password "Kupuhipa1"
......@@ -59,7 +59,6 @@ Scenario: Uploading groups via CSV and editing as an admin (Bug 1420590)
Then I press "Save group"
# Checking for regression errors
And I should not see "Invalid argument supplied for foreach()"
And I should not see "[WAR]"
And I should see "Group saved successfully"
And I follow "Logout"
# Logging in as Admin
......
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