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

Merge "Bug 1763163: Copy group portfolios automatically to existing group members"

parents ecfd138b 01af3dab
......@@ -1529,6 +1529,26 @@ class User {
$this->copy_collections($templatecollectionids, false);
}
/**
* Makes a literal copy of a list of views and collections for existing group members.
*
* @param array values .
* @param boolean collection
*/
public function copy_group_views_collections_to_existing_members($views, $collection = false) {
if (empty($views)) {
return;
}
if ($collection) {
// Copy the collection to the current users portfolio
$this->copy_collections($views, false);
}
else {
// Copy the page to the current users portfolio
$this->copy_views($views, false);
}
}
}
......
......@@ -422,6 +422,9 @@ $string['confirmadddesc'] = 'Please choose which you would like to create:';
$string['confirmcopytitle'] = 'Confirm copying';
$string['confirmcopydesc'] = 'Please choose which you would like to copy:';
$string['Untitled'] = 'Untitled';
$string['copyforexistingmembersprogress'] = 'Copying portfolios for existing group members';
$string['existinggroupmembercopy'] = 'Copy for existing group members';
$string['existinggroupmembercopydesc1'] = 'Copy the selected pages / collections to the personal portfolio area of all existing group members. People who are added to the group after this setting is enabled will not be affected.';
$string['copyfornewusers'] = 'Copy for new users';
$string['copyfornewusersdescription2'] = 'Whenever a new user is created, automatically make a personal copy of the selected pages / collections in the user\'s account. If you want these users to be able to copy the selected pages / collections later on as well, please allow copying in general.';
$string['copyfornewmembers'] = 'Copy for new institution members';
......
......@@ -806,6 +806,7 @@
<FIELD NAME="locked" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
<FIELD NAME="urlid" TYPE="char" LENGTH="100" NOTNULL="false" />
<FIELD NAME="anonymise" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="existinggroupmembercopy" TYPE="int" LENGTH="1" DEFAULT="0" NOTNULL="true" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -5837,5 +5837,13 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2018050200) {
log_debug('Create new "existinggroupmembercopy" field to "view" table');
$table = new XMLDBTable('view');
$field = new XMLDBField('existinggroupmembercopy');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, 0);
add_field($table, $field);
}
return $status;
}
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/wiki/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2018040900;
$config->version = 2018050200;
$config->series = '18.10';
$config->release = '18.10dev';
$config->minupgradefrom = 2015030409;
......
......@@ -63,6 +63,7 @@ class View {
private $urlid;
private $skin;
private $anonymise = 0;
private $existinggroupmembercopy = 0;
const UNSUBMITTED = 0;
const SUBMITTED = 1;
......@@ -1057,6 +1058,9 @@ class View {
if (isset($config['copynewgroups'])) {
$v->set('copynewgroups', $config['copynewgroups']);
}
if (isset($config['existinggroupmembercopy'])) {
$v->set('existinggroupmembercopy', $config['existinggroupmembercopy']);
}
$v->commit();
}
......
{include file="header.tpl"}
{$form|safe}
{include file="progress_meter.tpl"}
{include file="footer.tpl"}
......@@ -74,9 +74,9 @@
<h2 class="access-title">{str tag=sharedwithothers section=view}</h2>
<!-- Access -->
{$form|safe}
{include file="progress_meter.tpl"}
</div>
</div>
{include file="footer.tpl"}
......@@ -68,6 +68,11 @@ $form = array(
'type' => 'hidden',
'value' => $view->get('id'),
),
'progress_meter_token' => array(
'type' => 'hidden',
'value' => 'copyviewexistingmembersprogress',
'readonly' => TRUE,
),
)
);
......@@ -192,6 +197,16 @@ $form['elements']['more'] = array(
),
);
$admintutorids = group_get_member_ids($group, array('admin', 'tutor'));
if ($group && in_array( $USER->get('id'), $admintutorids, true )) {
$form['elements']['more']['elements'] = array_merge($form['elements']['more']['elements'], array('existinggroupmembercopy' => array(
'type' => 'switchbox',
'title' => get_string('existinggroupmembercopy', 'view'),
'description' => get_string('existinggroupmembercopydesc1', 'view'),
'defaultvalue' => $view->get('existinggroupmembercopy'),
)));
}
$form['elements']['accesslist'] = array(
'type' => 'viewacl',
'allowcomments' => $allowcomments,
......@@ -468,7 +483,7 @@ function editaccess_cancel_submit() {
}
function editaccess_submit(Pieform $form, $values) {
global $SESSION, $institution, $collections, $views, $view;
global $SESSION, $institution, $collections, $views, $view, $group;
if ($values['accesslist']) {
$dateformat = get_string('strftimedatetimeshort');
......@@ -492,6 +507,33 @@ function editaccess_submit(Pieform $form, $values) {
$toupdate = array();
if ($group) {
$viewconfig['existinggroupmembercopy'] = !empty($values['existinggroupmembercopy']) ? $values['existinggroupmembercopy'] : 0;
// Add funtionality here which copies the page into existing group members pages.
if ($viewconfig['existinggroupmembercopy'] && !$view->get('existinggroupmembercopy')) {
$groupmembers = group_get_member_ids($group, array('member'));
$key = 0;
$total = count($groupmembers);
foreach ($groupmembers as $groupmember) {
if (!($key % 25)) {
set_progress_info('copyviewexistingmembersprogress', $key, $total, get_string('copyforexistingmembersprogress', 'view'));
}
$key++;
$userobj = new User();
$userobj->find_by_id($groupmember);
if (!empty($values['collections'])) {
$userobj->copy_group_views_collections_to_existing_members($values['collections'], true);
}
if (!empty($values['views'])) {
$userobj->copy_group_views_collections_to_existing_members($values['views']);
}
}
set_progress_done('copyviewexistingmembersprogress');
}
}
if ($institution) {
if (isset($values['copynewuser'])) {
$viewconfig['copynewuser'] = (int) $values['copynewuser'];
......
......@@ -67,7 +67,7 @@ $form = array(
'class' => 'form-simple stacked block-relative',
'plugintype' => 'core',
'pluginname' => 'view',
'presubmitcallback' => 'beforeFormStartProcessing',
'presubmitcallback' => 'formStartProcessing',
'viewid' => $view->get('id'),
'userview' => (int) $view->get('owner'),
'elements' => array(
......@@ -75,6 +75,11 @@ $form = array(
'type' => 'hidden',
'value' => $view->get('id'),
),
'progress_meter_token' => array(
'type' => 'hidden',
'value' => 'copyviewexistingmembersprogress',
'readonly' => TRUE,
),
)
);
......@@ -124,6 +129,16 @@ $form['elements']['more'] = array(
),
);
$admintutorids = group_get_member_ids($group, array('admin', 'tutor'));
if ($group && in_array($USER->get('id'), $admintutorids, true)) {
$form['elements']['more']['elements'] = array_merge($form['elements']['more']['elements'], array('existinggroupmembercopy' => array(
'type' => 'switchbox',
'title' => get_string('existinggroupmembercopy', 'view'),
'description' => get_string('existinggroupmembercopydesc1', 'view'),
'defaultvalue' => $view->get('existinggroupmembercopy'),
)));
}
$form['elements']['accesslist'] = array(
'type' => 'viewacl',
'allowcomments' => $allowcomments,
......@@ -389,7 +404,7 @@ function accessurl_cancel_submit() {
}
function accessurl_submit(Pieform $form, $values) {
global $SESSION, $institution, $view;
global $SESSION, $institution, $view, $group, $collection;
if ($values['accesslist']) {
$dateformat = get_string('strftimedatetimeshort');
......@@ -411,6 +426,34 @@ function accessurl_submit(Pieform $form, $values) {
'accesslist' => $values['accesslist'],
);
if ($group) {
$viewconfig['existinggroupmembercopy'] = !empty($values['existinggroupmembercopy']) ? $values['existinggroupmembercopy'] : 0;
// Add functionality here which copies the page into existing
// group members pages.
if ($viewconfig['existinggroupmembercopy'] && !$view->get('existinggroupmembercopy')) {
$groupmembers = group_get_member_ids($group, array('member'));
$key = 0;
$total = count($groupmembers);
foreach ($groupmembers as $groupmember) {
if (!($key % 25)) {
set_progress_info('copyviewexistingmembersprogress', $key, $total, get_string('copyforexistingmembersprogress', 'view'));
}
$key++;
$userobj = new User();
$userobj->find_by_id($groupmember);
if (!empty($collection)) {
$userobj->copy_group_views_collections_to_existing_members(array($collection->get('id')), true);
}
else if (!empty($view->get('id'))) {
$userobj->copy_group_views_collections_to_existing_members(array($view->get('id')));
}
}
set_progress_done('copyviewexistingmembersprogress');
}
}
if ($institution) {
if (isset($values['copynewuser'])) {
$viewconfig['copynewuser'] = (int) $values['copynewuser'];
......
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