Commit 582f5220 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Fix position of 'about me' block in profile views

parent 3e4bac1c
......@@ -413,6 +413,7 @@ class User {
private function install_profile_view() {
static $systemprofileviewid = null;
db_begin();
if (is_null($systemprofileviewid)) {
$systemprofileviewid = get_field('view', 'id', 'owner', 0, 'type', 'profile');
}
......@@ -430,7 +431,7 @@ class User {
'title' => get_string('aboutme', 'blocktype.internal/profileinfo'),
'view' => $view->get('id'),
'column' => 1,
'order' => 0,
'order' => 1,
));
$configdata = array('artefactids' => array());
if ($intro = get_field('artefact', 'id', 'owner', $this->get('id'), 'artefacttype', 'introduction')) {
......@@ -443,7 +444,7 @@ class User {
$configdata['profileicon'] = $this->get('profileicon');
}
$aboutme->set('configdata', $configdata);
$aboutme->commit();
$view->addblockinstance($aboutme);
$view->set_access(array(
array(
......@@ -452,6 +453,7 @@ class User {
'stopdate' => null,
),
));
db_commit();
return $view;
}
......
......@@ -838,6 +838,19 @@ function xmldb_core_upgrade($oldversion=0) {
insert_record('cron', $cron);
}
if ($oldversion < 2009022500) {
// Get rid of all blocks with position 0 caused by 'about me' block on profile views
if (count_records('block_instance', 'order', 0) && !count_records_select('block_instance', '"order" < 0')) {
execute_sql('UPDATE {block_instance} SET "order" = -1 * "order" WHERE id IN (
SELECT i.id FROM {block_instance} i
INNER JOIN (SELECT view, "column" FROM {block_instance} WHERE "order" = 0) z
ON (z.view = i.view AND z.column = i.column))'
);
execute_sql('UPDATE {block_instance} SET "order" = 1 WHERE "order" = 0');
execute_sql('UPDATE {block_instance} SET "order" = -1 * ("order" - 1) WHERE "order" < 0');
}
}
return $status;
}
......
......@@ -1323,7 +1323,7 @@ function install_system_profile_view() {
)));
$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 => 1, 2 => 0); // Leave a space for About Me in the first column
$weights = array(1 => 0, 2 => 0);
foreach (array_keys($blocktypes) as $blocktype) {
if (in_array($blocktype, $installed)) {
$weights[$blocktypes[$blocktype]]++;
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009021901;
$config->version = 2009022500;
$config->release = '1.1.0beta5dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.0_RELEASE)';
......
......@@ -1103,6 +1103,25 @@ class View {
}
}
/**
* adds a block instance to a view
* @param array $values parameters for this function
* block => block to add
*/
public function addblockinstance(BlockInstance $bi) {
if (!$bi->get('column')) {
$bi->set('column', 1);
}
if (!$bi->get('order')) {
$bi->set('order', 1);
}
if (!$bi->get('view')) {
$bi->set('view', $this->get('id'));
}
$this->shuffle_column($bi->get('column'), $bi->get('order'));
$bi->commit();
}
/**
* deletes a block instance from the 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