Commit 87ddefc2 authored by Robert Lyon's avatar Robert Lyon
Browse files

Register confirm allow user to copy collection (Bug #1367939)



See bug for testing

Change-Id: Iddc02c10d163ad363b5c0acddd324393c8e00dbc
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent d31efef9
......@@ -1238,7 +1238,8 @@ class User {
require_once(get_config('libroot') . 'view.php');
$views = array();
foreach (get_records_select_array('view', 'id IN (' . implode(', ', db_array_to_ph($templateids)) . ')', $templateids, '', 'id, title, description, type') as $result) {
$results = get_records_select_array('view', 'id IN (' . implode(', ', db_array_to_ph($templateids)) . ')', $templateids, '', 'id, title, description, type');
foreach ($results as $result) {
$views[$result->id] = $result;
}
......@@ -1254,6 +1255,37 @@ class User {
db_commit();
}
/**
* Makes a literal copy of a list of collections for this user.
*
* @param array $templateids A list of collectionids to copy.
*/
public function copy_collections($templateids, $checkviewaccess=true) {
if (!$templateids) {
// Nothing to do
return;
}
if (!is_array($templateids)) {
throw new SystemException('User->copy_collections: templateids must be a list of templates to copy for the user');
}
require_once(get_config('libroot') . 'collection.php');
$collections = array();
$results = get_records_select_array('collection', 'id IN (' . implode(', ', db_array_to_ph($templateids)) . ')', $templateids, '', 'id, name');
foreach ($results as $result) {
$collections[$result->id] = $result;
}
db_begin();
foreach ($templateids as $tid) {
Collection::create_from_template(array(
'owner' => $this->get('id'),
'title' => $collections[$tid]->name,
), $tid, $this->get('id'), $checkviewaccess);
}
db_commit();
}
/**
* Makes a literal copy of a list of views and collections for the new user.
* All site views and collections which set to "copy to new user"
......@@ -1278,12 +1310,7 @@ class User {
INNER JOIN {collection} c ON cv.collection = c.id
WHERE v.copynewuser = 1
AND v.institution = 'mahara'", array());
if ($templatecollectionids) {
require_once('collection.php');
foreach ($templatecollectionids as $templateid) {
Collection::create_from_template(array('owner' => $this->get('id')), $templateid, null, false, true);
}
}
$this->copy_collections($templatecollectionids, false);
}
/**
......@@ -1291,7 +1318,7 @@ class User {
* All institution views and collections which set to "copy to new institution member"
* will be copied to this user's profile.
*
* @param $institution: ID of the institution to join
* @param string $institution ID of the institution to join
*/
public function copy_institution_views_collections_to_new_member($institution) {
if (empty($institution)) {
......@@ -1315,12 +1342,7 @@ class User {
INNER JOIN {collection} c ON cv.collection = c.id
WHERE v.copynewuser = 1
AND v.institution = ?", array($institution));
if ($templatecollectionids) {
require_once('collection.php');
foreach ($templatecollectionids as $templateid) {
Collection::create_from_template(array('owner' => $this->get('id')), $templateid, null, false, true);
}
}
$this->copy_collections($templatecollectionids, false);
}
}
......
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