Commit 168bebdf authored by Son Nguyen's avatar Son Nguyen
Browse files

Copy institution views and collection to the new member's portfolio (Bug #886080)



Change-Id: Icc209c647602375a83804bae0538a5297b5caed7
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent d79a4099
......@@ -1101,7 +1101,7 @@ class User {
/**
* 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"
* All site views and collections which set to "copy to new user"
* will be copied to this user's profile.
*
* @param $checkviewaccess.
......@@ -1133,6 +1133,44 @@ class User {
}
}
/**
* Makes a literal copy of a list of views and collections for the new institution member.
* 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 $checkviewaccess.
*/
public function copy_institution_views_collections_to_new_member($institution, $checkviewaccess=true) {
if (empty($institution)) {
return;
}
// 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 = ?
AND v.copynewuser = 1", array($institution));
$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 = ?", array($institution));
if ($templatecollectionids) {
require_once('collection.php');
foreach ($templatecollectionids as $templateid) {
Collection::create_from_template(array('owner' => $this->get('id')), $templateid, null, null, true);
}
}
}
}
......
......@@ -220,11 +220,11 @@ class Institution {
WHERE usr = ? AND tag " . db_ilike() . " 'lastinstitution:%'",
array($user->id)
);
// Copy institution views to the user's portfolio
// Copy institution views and collection to the user's portfolio
$checkviewaccess = empty($user->newuser) && !$USER->get('admin');
$userobj = new User();
$userobj->find_by_id($user->id);
$userobj->copy_views(get_column('view', 'id', 'institution', $this->name, 'copynewuser', 1), $checkviewaccess);
$userobj->copy_institution_views_collections_to_new_member($this->name, $checkviewaccess);
require_once('activity.php');
activity_occurred('maharamessage', $message);
handle_event('updateuser', $userinst->usr);
......
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