Commit b3f71a19 authored by Nigel McNie's avatar Nigel McNie
Browse files

Create profile views for users on demand.

This takes the load off the upgrade process, and removes the need for a
user creation event to create them. The cost is that the first time the
user profile page is visited, the view is copied. But the process is
pretty quick for just one view.
parent b1ae9daa
......@@ -1218,20 +1218,19 @@ function copy_views_for_user($userid, $templateids) {
}
/**
* Installs a user's profile view.
*
* This function installs the default profile view for a user
* upon the createuser event (and a migration upgrade)
*
* @param mixed eventdata data that is passed to handle_event
* @param id $userid ID of user to create the profile view for
*/
function install_default_profile_view($eventdata) {
require_once(get_config('libroot') . 'view.php');
function install_profile_view($userid) {
static $systemprofileviewid = null;
$viewid = install_system_profile_view();
if ($eventdata['id'] == 0) {
return;
if (is_null($systemprofileviewid)) {
$systemprofileviewid = get_field('view', 'id', 'owner', 0, 'type', 'profile');
}
$view = copy_view_for_user($eventdata['id'], $viewid);
require_once(get_config('libroot') . 'view.php');
$view = copy_view_for_user($userid, $systemprofileviewid);
$view->set_access(array(
array(
'type' => 'loggedin',
......@@ -1239,6 +1238,9 @@ function install_default_profile_view($eventdata) {
'stopdate' => null,
),
));
$id = $view->get('id');
unset($view);
return $id;
}
......
......@@ -1386,7 +1386,11 @@ class View {
* @param int $userid the user id to fetch the profile view for
*/
public static function profile_view($userid) {
return new View(get_field('view', 'id', 'type', 'profile', 'owner', $userid));
$viewid = get_field('view', 'id', 'type', 'profile', 'owner', $userid);
if (!$viewid) {
$viewid = install_profile_view($userid);
}
return new View($viewid);
}
public static function get_myviews_data($limit=5, $offset=0, $groupid=null, $institution=null) {
......
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