Commit d13da888 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Create user profile views from a site default

parent a2627eb1
......@@ -1363,6 +1363,23 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2008091603) {
foreach(array('myviews', 'mygroups', 'myfriends', 'wall') as $blocktype) {
$data = check_upgrades("blocktype.$blocktype");
if ($data) {
upgrade_plugin($data);
}
}
$viewid = get_field('view', 'id', 'owner', 0, 'type', 'profile');
if ($viewid) {
require_once(get_config('libroot') . 'view.php');
$systemview = new View($viewid);
$systemview->delete();
}
install_system_profile_view();
insert_record('event_subscription', (object)array('event' => 'createuser', 'callfunction' => 'install_default_profile_view'));
}
return $status;
}
......
......@@ -1155,23 +1155,33 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
function copy_view_for_user($userid, $templateid) {
if (!$templateid) {
return;
}
$template = new View($templateid);
$v = new View(0, (object) array(
'template' => 0,
'numcolumns' => 3,
'owner' => $userid,
'title' => $template->get('title'),
'description' => $template->get('description'),
'type' => $template->get('type'),
));
$v->commit();
$v->copy_contents($template);
$v->commit();
return $v;
}
function copy_views_for_user($userid, $templateids) {
if (!$templateids) {
return;
}
require_once(get_config('libroot') . 'view.php');
foreach ($templateids as $tid) {
$template = new View($tid);
$v = new View(0, (object) array(
'template' => 0,
'numcolumns' => 3,
'owner' => $userid,
'title' => $template->get('title'),
'description' => $template->get('description'),
));
$v->commit();
$v->copy_contents($template);
$v->commit();
copy_view_for_user($userid, $tid);
}
}
......@@ -1184,24 +1194,56 @@ function copy_views_for_user($userid, $templateids) {
*/
function install_default_profile_view($eventdata) {
require_once(get_config('libroot') . 'view.php');
$viewid = get_field('view', 'id', 'owner', 0, 'type', 'profile');
if (!$viewid) {
$viewid = install_system_profile_view();
}
$view = copy_view_for_user($eventdata['id'], $viewid);
$view->set_access(array(
array(
'type' => 'loggedin',
'startdate' => null,
'stopdate' => null,
),
));
}
/**
*
* This function installs the site's default profile view
*
*/
function install_system_profile_view() {
require_once(get_config('libroot') . 'view.php');
$view = new View(0, array(
'type' => 'profile',
'owner' => $eventdata['id'],
'owner' => 0,
'numcolumns' => 2,
'ownerformat' => FORMAT_NAME_PREFERREDNAME,
'title' => get_string('profileviewtitle', 'view'),
'description' => '',
));
$view->commit();
// #TODO add blocks here
$view->set_access(array(
array(
'type' => 'loggedin',
'startdate' => null,
'stopdate' => null,
),
));
$blocktypes = array('myviews' => 1, 'mygroups' => 1, 'myfriends' => 2, 'wall' => 2); // column ids
$installed = get_column_sql('SELECT name FROM {blocktype_installed} WHERE name IN (' . join(',', array_map('db_quote', array_keys($blocktypes))) . ')');
$weights = array(1 => 0, 2 => 0);
foreach (array_keys($blocktypes) as $blocktype) {
if (in_array($blocktype, $installed)) {
$weights[$blocktypes[$blocktype]]++;
$newblock = new BlockInstance(0, array(
'blocktype' => $blocktype,
'title' => get_string('title', 'blocktype.' . $blocktype),
'view' => $view->get('id'),
'column' => $blocktypes[$blocktype],
'order' => $weights[$blocktypes[$blocktype]],
));
$newblock->commit();
}
}
return $view->get('id');
}
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008091601;
$config->version = 2008091603;
$config->release = '1.1.0alpha2dev';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
......@@ -37,6 +37,9 @@ if (!empty($loggedinid)) {
else {
$userid = param_integer('id');
}
if ($userid == 0) {
redirect();
}
if ($userid == $loggedinid) {
define('MENUITEM', 'profile/view');
}
......
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