Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Manage multiblock instances.
19
 *
20
 * @package   block_multiblock
21
 * @copyright 2019 Peter Spicer <peter.spicer@catalyst-eu.net>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
use block_multiblock\helper;
26
use block_multiblock\navigation;
27
 
28
require(__DIR__ . '/../../config.php');
29
 
30
require_once($CFG->libdir.'/tablelib.php');
31
 
32
$blockid = required_param('id', PARAM_INT);
33
$actionableinstance = required_param('instance', PARAM_INT);
34
 
35
require_login();
36
list($block, $blockinstance, $blockmanager) = helper::bootstrap_page($blockid);
37
 
38
$pageurl = new moodle_url('/blocks/multiblock/configinstance.php', ['id' => $blockid, 'instance' => $actionableinstance]);
39
helper::set_page_real_url($pageurl);
40
 
41
$blockmanager->show_only_fake_blocks(true);
42
 
43
$blockctx = context_block::instance($blockid);
44
$multiblockblocks = $blockinstance->load_multiblocks($blockctx->id);
45
if (!isset($multiblockblocks[$actionableinstance])) {
46
    redirect(new moodle_url('/blocks/multiblock/manage.php', ['id' => $blockid, 'sesskey' => sesskey()]));
47
}
48
 
49
$PAGE->navbar->add($multiblockblocks[$actionableinstance]->blockinstance->get_title());
50
 
51
$formfile = $CFG->dirroot . '/blocks/' . $multiblockblocks[$actionableinstance]->blockinstance->name() . '/edit_form.php';
52
$classname = '';
53
if (is_readable($formfile)) {
54
    require_once($CFG->dirroot . '/blocks/edit_form.php');
55
    require_once($formfile);
56
    $classname = 'block_' . $multiblockblocks[$actionableinstance]->blockinstance->name() . '_edit_form';
57
}
58
 
59
if (!$classname || !class_exists($classname)) {
60
    throw new \Exception('Could not load block configuration for ' . $classname);
61
}
62
 
63
class_alias($classname, 'block_multiblock_proxy_edit_form');
64
$editform = helper::get_edit_form($pageurl, $multiblockblocks[$actionableinstance], $PAGE, $blockinstance);
65
 
66
if ($editform->is_cancelled()) {
67
    redirect(new moodle_url('/blocks/multiblock/manage.php', ['id' => $blockid, 'sesskey' => sesskey()]));
68
} else if ($data = $editform->get_data()) {
69
    $config = new stdClass;
70
 
71
    // Totara has some common config that it handles separately to everything else.
72
    if (method_exists($editform->block, 'serialize_common_config')) {
73
 
74
        $editform->block->validate_common_config_value($data);
75
        $commonconfig = $editform->block->serialize_common_config($editform->split_common_settings_data($data));
76
        $multiblockblocks[$actionableinstance]->common_config = $commonconfig;
77
        $DB->update_record('block_instances', $multiblockblocks[$actionableinstance]);
78
    }
79
 
80
    foreach ($data as $configfield => $value) {
81
        if (strpos($configfield, 'config_') !== 0) {
82
            continue;
83
        }
84
        $field = substr($configfield, 7);
85
        $config->$field = $value;
86
    }
87
    $multiblockblocks[$actionableinstance]->blockinstance->instance_config_save($config);
88
 
89
    // If we pressed save and display, go to the page where the block lives.
90
    if (!empty($data->saveanddisplay)) {
91
        redirect(navigation::get_page_url($blockid));
92
    }
93
 
94
    // Otherwise return to the management page.
95
    redirect(new moodle_url('/blocks/multiblock/manage.php', ['id' => $blockid, 'sesskey' => sesskey()]));
96
}
97
 
98
echo $OUTPUT->header();
99
 
100
$editform->set_data($multiblockblocks[$actionableinstance]->blockinstance->instance);
101
$editform->display();
102
 
103
echo $OUTPUT->footer();