Commit 3e2d1bac authored by Nigel McNie's avatar Nigel McNie
Browse files

Move getting a user's profile view to the User object.

parent bc2e5758
......@@ -386,6 +386,51 @@ class User {
$this->set('accountprefs', $accountprefs);
}
/**
* Return the profile view object for this user.
*
* If the user does not yet have a profile view, one is created for them.
*
* @return View
*/
public function get_profile_view() {
$viewid = get_field('view', 'id', 'type', 'profile', 'owner', $this->get('id'));
if (!$viewid) {
return $this->install_profile_view();
}
return new View($viewid);
}
/**
* Installs a user's profile view.
*
* @return View
*/
private function install_profile_view() {
static $systemprofileviewid = null;
if (is_null($systemprofileviewid)) {
$systemprofileviewid = get_field('view', 'id', 'owner', 0, 'type', 'profile');
}
require_once(get_config('libroot') . 'view.php');
list($view) = View::create_from_template(array(
'owner' => $this->get('id'),
'title' => get_field('view', 'title', 'id', $systemprofileviewid),
'type' => 'profile',
), $systemprofileviewid, $this->get('id'));
$view->set_access(array(
array(
'type' => 'loggedin',
'startdate' => null,
'stopdate' => null,
),
));
return $view;
}
/**
* Determines if the user is currently logged in
......
......@@ -1403,19 +1403,6 @@ class View {
}
}
/**
* Return the profile view object for the given userid
*
* @param int $userid the user id to fetch the profile view for
*/
public static function profile_view($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) {
global $USER;
......
......@@ -51,7 +51,9 @@ if (!$user = get_record('usr', 'id', $userid, 'deleted', 0)) {
}
$is_friend = is_friend($userid, $loggedinid);
$view = View::profile_view($userid);
$userobj = new User();
$userobj->find_by_id($userid);
$view = $userobj->get_profile_view();
# access will either be logged in (always) or public as well
if (!can_view_view($view->get('id'))) {
throw new AccessDeniedException();
......
......@@ -40,7 +40,7 @@ $profile = param_boolean('profile');
if (empty($id)) {
if (!empty($profile)) {
try {
$view = View::profile_view($USER->get('id'));
$view = $USER->get_profile_view();
$id = $view->get('id');
}
catch (ViewNotFoundException $_e) {
......
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