mirror of
https://github.com/moodle/moodle.git
synced 2025-04-22 00:42:54 +02:00
Merge branch '43714-27' of git://github.com/samhemelryk/moodle
This commit is contained in:
commit
0eea6f5d99
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -34,16 +33,16 @@ $contextid = required_param('contextid', PARAM_INT);
|
||||
$subpage = optional_param('subpage', '', PARAM_ALPHANUMEXT);
|
||||
$cmid = optional_param('cmid', null, PARAM_INT);
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
// Params for blocks-move actions
|
||||
$bui_moveid = optional_param('bui_moveid', 0, PARAM_INT);
|
||||
$bui_newregion = optional_param('bui_newregion', '', PARAM_ALPHAEXT);
|
||||
$bui_beforeid = optional_param('bui_beforeid', 0, PARAM_INT);
|
||||
// Params for blocks-move actions.
|
||||
$buimoveid = optional_param('bui_moveid', 0, PARAM_INT);
|
||||
$buinewregion = optional_param('bui_newregion', '', PARAM_ALPHAEXT);
|
||||
$buibeforeid = optional_param('bui_beforeid', 0, PARAM_INT);
|
||||
|
||||
// Setting pagetype and URL
|
||||
// Setting pagetype and URL.
|
||||
$PAGE->set_pagetype($pagetype);
|
||||
$PAGE->set_url('/lib/ajax/blocks.php', array('courseid' => $courseid, 'pagelayout' => $pagelayout, 'pagetype' => $pagetype));
|
||||
|
||||
// Verifying login and session
|
||||
// Verifying login and session.
|
||||
$cm = null;
|
||||
if (!is_null($cmid)) {
|
||||
$cm = get_coursemodule_from_id(null, $cmid, $courseid, false, MUST_EXIST);
|
||||
@ -54,7 +53,7 @@ require_sesskey();
|
||||
// Set context from ID, so we don't have to guess it from other info.
|
||||
$PAGE->set_context(context::instance_by_id($contextid));
|
||||
|
||||
// Setting layout to replicate blocks configuration for the page we edit
|
||||
// Setting layout to replicate blocks configuration for the page we edit.
|
||||
$PAGE->set_pagelayout($pagelayout);
|
||||
$PAGE->set_subpage($subpage);
|
||||
$pagetype = explode('-', $pagetype);
|
||||
@ -78,21 +77,27 @@ switch ($pagetype[0]) {
|
||||
break;
|
||||
}
|
||||
|
||||
echo $OUTPUT->header(); // send headers
|
||||
// Send headers.
|
||||
echo $OUTPUT->header();
|
||||
|
||||
switch ($action) {
|
||||
case 'move':
|
||||
// Loading blocks and instances for the region
|
||||
// Loading blocks and instances for the region.
|
||||
$PAGE->blocks->load_blocks();
|
||||
$instances = $PAGE->blocks->get_blocks_for_region($bui_newregion);
|
||||
$instances = $PAGE->blocks->get_blocks_for_region($buinewregion);
|
||||
|
||||
$bui_newweight = null;
|
||||
if ($bui_beforeid == 0) {
|
||||
// Moving to very bottom
|
||||
$last = end($instances);
|
||||
$bui_newweight = $last->instance->weight + 1;
|
||||
$buinewweight = null;
|
||||
if ($buibeforeid == 0) {
|
||||
if (count($instances) === 0) {
|
||||
// Moving the block into an empty region. Give it the default weight.
|
||||
$buinewweight = 0;
|
||||
} else {
|
||||
// Moving to very bottom.
|
||||
$last = end($instances);
|
||||
$buinewweight = $last->instance->weight + 1;
|
||||
}
|
||||
} else {
|
||||
// Moving somewhere
|
||||
// Moving somewhere.
|
||||
$lastweight = 0;
|
||||
$lastblock = 0;
|
||||
$first = reset($instances);
|
||||
@ -101,14 +106,13 @@ switch ($action) {
|
||||
}
|
||||
|
||||
foreach ($instances as $instance) {
|
||||
if ($instance->instance->id == $bui_beforeid) {
|
||||
// Location found, just calculate weight like in
|
||||
// block_manager->create_block_contents() and quit the loop.
|
||||
if ($lastblock == $bui_moveid) {
|
||||
// same block, same place - nothing to move
|
||||
if ($instance->instance->id == $buibeforeid) {
|
||||
// Location found, just calculate weight like in block_manager->create_block_contents() and quit the loop.
|
||||
if ($lastblock == $buimoveid) {
|
||||
// Same block, same place - nothing to move.
|
||||
break;
|
||||
}
|
||||
$bui_newweight = ($lastweight + $instance->instance->weight) / 2;
|
||||
$buinewweight = ($lastweight + $instance->instance->weight) / 2;
|
||||
break;
|
||||
}
|
||||
$lastweight = $instance->instance->weight;
|
||||
@ -116,10 +120,10 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
|
||||
// Move block if we need
|
||||
if (isset($bui_newweight)) {
|
||||
// Nasty hack
|
||||
$_POST['bui_newweight'] = $bui_newweight;
|
||||
// Move block if we need.
|
||||
if (isset($buinewweight)) {
|
||||
// Nasty hack.
|
||||
$_POST['bui_newweight'] = $buinewweight;
|
||||
$PAGE->blocks->process_url_move();
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user