Browse files

created blocks_execute_repositioning_atomic as an extension of blocks…

…_execute_repositioning, the original did adjust the column that the block was coming from but it did not insert it properly into the target column (adjusting the weights of the other blocks). This is currently only really nessicary for the ajax formats.
  • Loading branch information...
1 parent 78d4711 commit e028ed34da4d898ebac74024f5467a5fb0126841 cap2501 committed Oct 8, 2006
Showing with 27 additions and 2 deletions.
  1. +27 −2 lib/blocklib.php
View
29 lib/blocklib.php
@@ -733,6 +733,31 @@ function blocks_execute_repositioning(&$instance, $newpos, $newweight, $pinned=f
}
}
+//like blocks_execute_repositiong except completely atomic, handles all aspects of the positioning
+function blocks_execute_repositioning_atomic(&$instance, $newpos, $newweight, $pinned=false){
+ global $CFG;
+
+ //make room for block insert
+ if (!empty($pinned)) {
+ $sql = 'UPDATE '. $CFG->prefix .'block_instance SET weight = weight + 1 WHERE pagetype = \''. $instance->pagetype.
+ '\' AND position = \'' .$newpos.
+ '\' AND weight >= '. $newweight;
+ } else {
+ $sql = 'UPDATE '. $CFG->prefix .'block_instance SET weight = weight + 1 WHERE pagetype = \''. $instance->pagetype.
+ '\' AND pageid = '. $instance->pageid .' AND position = \'' .$newpos.
+ '\' AND weight >= '. $newweight;
+ }echo $sql;
+ execute_sql($sql,false);
+
+
+
+ //reposition blocks
+ blocks_execute_repositioning($instance,$newpos,$newweight,$pinned);
+
+
+
+}
+
function blocks_get_pinned($page) {
$visible = true;
@@ -784,7 +809,7 @@ function blocks_get_by_page_pinned($page) {
if (!array_key_exists($pos,$weights)) {
$weights[$pos] = 0;
}
- foreach ($blocks as $block) {
+ foreach ($blocks as $block) {//echo("\r\nid=".$block->id."-");
$pinned[$pos][$weights[$pos]] = $block;
$weights[$pos]++;
}
@@ -805,7 +830,7 @@ function blocks_get_by_page($page) {
return $arr;
}
- foreach($blocks as $block) {
+ foreach($blocks as $block) {//echo("id2=".$block->id);
$arr[$block->position][$block->weight] = $block;
}

0 comments on commit e028ed3

Please sign in to comment.