Commit d79a4099 authored by Son Nguyen's avatar Son Nguyen
Browse files

Copy site views and collections to the new user's profile (Bug #886080)



- Add function copy_site_views_collections_to_new_user()
to copy site views and collections to the new user

Change-Id: If893af92cc86b7f3225e84558f8a71048ec129f0
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent 72b8d771
......@@ -1099,6 +1099,39 @@ class User {
db_commit();
}
/**
* Makes a literal copy of a list of views and collections for the new user.
* All site and institution views and collections which set to "copy to new user"
* will be copied to this user's profile.
*
* @param $checkviewaccess.
*/
public function copy_site_views_collections_to_new_user($checkviewaccess=true) {
// Get list of available views which are not in collections
$templateviewids = get_column_sql("
SELECT v.id
FROM {view} v
LEFT JOIN {collection_view} cv ON v.id = cv.view
WHERE cv.view IS NULL
AND v.institution = 'mahara'
AND v.copynewuser = 1", array());
$this->copy_views($templateviewids, $checkviewaccess);
// Get list of available collections
$templatecollectionids = get_column_sql("
SELECT c.id
FROM {view} v
INNER JOIN {collection_view} cv ON v.id = cv.view
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, null, true);
}
}
}
}
......
......@@ -2053,11 +2053,11 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
}
}
// Copy site views to the new user's profile
// Copy site views and collections to the new user's profile
$checkviewaccess = !$user->newuser;
$userobj = new User();
$userobj->find_by_id($user->id);
$userobj->copy_views(get_column('view', 'id', 'institution', 'mahara', 'copynewuser', 1), $checkviewaccess);
$userobj->copy_site_views_collections_to_new_user($checkviewaccess);
reset_password($user, false, $quickhash);
......
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