Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 243... Línea 243...
243
 
243
 
244
     * @param string $blockname - the basic name of a block (eg "navigation")
244
     * @param string $blockname - the basic name of a block (eg "navigation")
245
     * @return boolean - is there one of these blocks in the current page?
245
     * @return boolean - is there one of these blocks in the current page?
246
     */
246
     */
247
    public function is_block_present($blockname) {
247
    public function is_block_present($blockname) {
248
        if (empty($this->blockinstances)) {
248
        if (empty($this->birecordsbyregion)) {
249
            return false;
249
            return false;
Línea 250... Línea 250...
250
        }
250
        }
251
 
251
 
252
        $requiredbythemeblocks = $this->get_required_by_theme_block_types();
252
        $requiredbythemeblocks = $this->get_required_by_theme_block_types();
253
        foreach ($this->blockinstances as $region) {
253
        foreach ($this->birecordsbyregion as $region) {
254
            foreach ($region as $instance) {
254
            foreach ($region as $instance) {
255
                if (empty($instance->instance->blockname)) {
255
                if (empty($instance->blockname)) {
256
                    continue;
256
                    continue;
257
                }
257
                }
258
                if ($instance->instance->blockname == $blockname) {
258
                if ($instance->blockname == $blockname) {
259
                    if ($instance->instance->requiredbytheme) {
259
                    if ($instance->requiredbytheme) {
260
                        if (!in_array($blockname, $requiredbythemeblocks)) {
260
                        if (!in_array($blockname, $requiredbythemeblocks)) {
261
                            continue;
261
                            continue;
262
                        }
262
                        }
Línea 832... Línea 832...
832
 
832
 
833
        if (empty($pagetypepattern)) {
833
        if (empty($pagetypepattern)) {
834
            $pagetypepattern = $this->page->pagetype;
834
            $pagetypepattern = $this->page->pagetype;
Línea -... Línea 835...
-
 
835
        }
-
 
836
 
-
 
837
        if (!empty($this->birecordsbyregion)) {
-
 
838
            $addableblocks = $this->get_addable_blocks();
-
 
839
 
-
 
840
            if (!array_key_exists($blockname, $addableblocks)) {
-
 
841
                throw new moodle_exception('blockcannotadd');
-
 
842
            }
835
        }
843
        }
836
 
844
 
837
        $blockinstance = new stdClass;
845
        $blockinstance = new stdClass;
838
        $blockinstance->blockname = $blockname;
846
        $blockinstance->blockname = $blockname;
839
        $blockinstance->parentcontextid = $this->page->context->id;
847
        $blockinstance->parentcontextid = $this->page->context->id;
Línea 944... Línea 952...
944
            }
952
            }
945
        }
953
        }
946
    }
954
    }
Línea 947... Línea 955...
947
 
955
 
-
 
956
    /**
-
 
957
     * Given an array of blocks in the format used by {@see add_blocks}, removes any blocks from
-
 
958
     * the list if they are not installed in the system.
-
 
959
     *
-
 
960
     * @param array $blocks Array keyed by region
-
 
961
     * @return array Updated array
-
 
962
     */
-
 
963
    public function filter_nonexistent_blocks(array $blocks): array {
-
 
964
        $installed = array_fill_keys(
-
 
965
            array_map(fn($block) => $block->name, $this->get_installed_blocks()),
-
 
966
            true,
-
 
967
        );
-
 
968
        $result = [];
-
 
969
        foreach ($blocks as $region => $regionblocks) {
-
 
970
            $result[$region] = [];
-
 
971
            foreach ($regionblocks as $blockname) {
-
 
972
                if (array_key_exists($blockname, $installed)) {
-
 
973
                    $result[$region][] = $blockname;
-
 
974
                }
-
 
975
            }
-
 
976
        }
-
 
977
        return $result;
-
 
978
    }
-
 
979
 
948
    /**
980
    /**
949
     * Move a block to a new position on this page.
981
     * Move a block to a new position on this page.
950
     *
982
     *
951
     * If this block cannot appear on any other pages, then we change defaultposition/weight
983
     * If this block cannot appear on any other pages, then we change defaultposition/weight
952
     * in the block_instances table. Otherwise we just set the position on this page.
984
     * in the block_instances table. Otherwise we just set the position on this page.
Línea 1340... Línea 1372...
1340
                $editactionurl->param('cache', 1);
1372
                $editactionurl->param('cache', 1);
1341
            }
1373
            }
Línea 1342... Línea 1374...
1342
 
1374
 
1343
            $controls[] = new action_menu_link_secondary(
1375
            $controls[] = new action_menu_link_secondary(
1344
                $editactionurl,
1376
                $editactionurl,
1345
                new pix_icon('t/edit', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')),
1377
                new pix_icon('i/settings', $str, 'moodle', ['class' => 'iconsmall', 'title' => '']),
1346
                $str,
1378
                $str,
1347
                [
1379
                [
1348
                    'class' => 'editing_edit',
1380
                    'class' => 'editing_edit',
1349
                    'data-action' => 'editblock',
1381
                    'data-action' => 'editblock',
Línea 1421... Línea 1453...
1421
            $deleteconfirmationurl = new moodle_url($actionurl, [
1453
            $deleteconfirmationurl = new moodle_url($actionurl, [
1422
                'bui_deleteid' => $block->instance->id,
1454
                'bui_deleteid' => $block->instance->id,
1423
                'bui_confirm' => 1,
1455
                'bui_confirm' => 1,
1424
                'sesskey' => sesskey(),
1456
                'sesskey' => sesskey(),
1425
            ]);
1457
            ]);
-
 
1458
 
-
 
1459
            $deleteblockmessage = json_encode(['deleteblockcheck', 'block', $blocktitle]);
-
 
1460
 
-
 
1461
            // If the block is being shown in sub contexts display a warning.
-
 
1462
            if ($block->instance->showinsubcontexts == 1) {
-
 
1463
                $parentcontext = context::instance_by_id($block->instance->parentcontextid);
-
 
1464
                $systemcontext = context_system::instance();
1426
            $blocktitle = $block->get_title();
1465
                $messagestring = new stdClass();
-
 
1466
                $messagestring->location = $parentcontext->get_context_name();
-
 
1467
 
-
 
1468
                // Checking for blocks that may have visibility on the front page and pages added on that.
-
 
1469
                if ($parentcontext->id != $systemcontext->id && is_inside_frontpage($parentcontext)) {
-
 
1470
                    $messagestring->pagetype = get_string('showonfrontpageandsubs', 'block');
-
 
1471
                } else {
-
 
1472
                    $pagetypes = generate_page_type_patterns($this->page->pagetype, $parentcontext);
-
 
1473
                    $messagestring->pagetype = $block->instance->pagetypepattern;
-
 
1474
                    if (isset($pagetypes[$block->instance->pagetypepattern])) {
-
 
1475
                        $messagestring->pagetype = $pagetypes[$block->instance->pagetypepattern];
-
 
1476
                    }
-
 
1477
                }
-
 
1478
 
-
 
1479
                $deleteblockmessage = json_encode(['deleteblockwarning', 'block', $messagestring]);
-
 
1480
            }
Línea 1427... Línea 1481...
1427
 
1481
 
1428
            $controls[] = new action_menu_link_secondary(
1482
            $controls[] = new action_menu_link_secondary(
1429
                $deleteactionurl,
1483
                $deleteactionurl,
1430
                new pix_icon('t/delete', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')),
1484
                new pix_icon('t/delete', $str, 'moodle', array('class' => 'iconsmall', 'title' => '')),
1431
                $str,
1485
                $str,
1432
                [
1486
                [
1433
                    'class' => 'editing_delete',
1487
                    'class' => 'editing_delete',
1434
                    'data-modal' => 'confirmation',
1488
                    'data-modal' => 'confirmation',
1435
                    'data-modal-title-str' => json_encode(['deletecheck_modal', 'block']),
1489
                    'data-modal-title-str' => json_encode(['deletecheck_modal', 'block']),
1436
                    'data-modal-content-str' => json_encode(['deleteblockcheck', 'block', $blocktitle]),
1490
                    'data-modal-content-str' => $deleteblockmessage,
1437
                    'data-modal-yes-button-str' => json_encode(['delete', 'core']),
1491
                    'data-modal-yes-button-str' => json_encode(['delete', 'core']),
1438
                    'data-modal-toast' => 'true',
1492
                    'data-modal-toast' => 'true',
1439
                    'data-modal-toast-confirmation-str' => json_encode(['deleteblockinprogress', 'block', $blocktitle]),
1493
                    'data-modal-toast-confirmation-str' => json_encode(['deleteblockinprogress', 'block', $blocktitle]),
1440
                    'data-modal-destination' => $deleteconfirmationurl->out(false),
1494
                    'data-modal-destination' => $deleteconfirmationurl->out(false),
Línea 1724... Línea 1778...
1724
 
1778
 
1725
    /**
1779
    /**
1726
     * Convenience function to check whether a block is implementing a secondary nav class and return it
1780
     * Convenience function to check whether a block is implementing a secondary nav class and return it
1727
     * initialised to the calling function
1781
     * initialised to the calling function
1728
     *
-
 
1729
     * @todo MDL-74939 Remove support for old 'local\views\secondary' class location
1782
     *
1730
     * @param block_base $block
1783
     * @param block_base $block
1731
     * @return \core\navigation\views\secondary
1784
     * @return \core\navigation\views\secondary
1732
     */
1785
     */
1733
    protected function get_secondarynav(block_base $block): \core\navigation\views\secondary {
1786
    protected function get_secondarynav(block_base $block): \core\navigation\views\secondary {
-
 
1787
        $class = "core_block\\navigation\\views\\secondary";
-
 
1788
 
1734
        $class = "core_block\\navigation\\views\\secondary";
1789
        // Check whether block defines its own secondary navigation.
1735
        if (class_exists("block_{$block->name()}\\navigation\\views\\secondary")) {
1790
        if (class_exists("block_{$block->name()}\\navigation\\views\\secondary")) {
1736
            $class = "block_{$block->name()}\\navigation\\views\\secondary";
-
 
1737
        } else if (class_exists("block_{$block->name()}\\local\\views\\secondary")) {
-
 
1738
            // For backwards compatibility, support the old location for this class (it was in a
-
 
1739
            // 'local' namespace which shouldn't be used for core APIs).
-
 
1740
            debugging("The class block_{$block->name()}\\local\\views\\secondary uses a deprecated " .
-
 
1741
                    "namespace. Please move it to block_{$block->name()}\\navigation\\views\\secondary.",
-
 
1742
                    DEBUG_DEVELOPER);
-
 
1743
            $class = "block_{$block->name()}\\local\\views\\secondary";
1791
            $class = "block_{$block->name()}\\navigation\\views\\secondary";
-
 
1792
        }
1744
        }
1793
 
1745
        $secondarynav = new $class($this->page);
1794
        $secondarynav = new $class($this->page);
1746
        $secondarynav->initialise();
1795
        $secondarynav->initialise();
1747
        return $secondarynav;
1796
        return $secondarynav;
Línea 2683... Línea 2732...
2683
}
2732
}
Línea 2684... Línea 2733...
2684
 
2733
 
2685
/**
2734
/**
2686
 * Add the default blocks to a course.
2735
 * Add the default blocks to a course.
-
 
2736
 *
-
 
2737
 * Because this function is used on install, we skip over any default blocks that do not exist
-
 
2738
 * so that install can complete successfully even if blocks are removed.
2687
 *
2739
 *
2688
 * @param object $course a course object.
2740
 * @param object $course a course object.
2689
 */
2741
 */
2690
function blocks_add_default_course_blocks($course) {
2742
function blocks_add_default_course_blocks($course) {
Línea 2710... Línea 2762...
2710
    } else {
2762
    } else {
2711
        $pagetypepattern = 'course-view-*';
2763
        $pagetypepattern = 'course-view-*';
2712
    }
2764
    }
2713
    $page = new moodle_page();
2765
    $page = new moodle_page();
2714
    $page->set_course($course);
2766
    $page->set_course($course);
-
 
2767
    $page->blocks->add_blocks(
2715
    $page->blocks->add_blocks($blocknames, $pagetypepattern);
2768
        $page->blocks->filter_nonexistent_blocks($blocknames),
-
 
2769
        $pagetypepattern,
-
 
2770
    );
2716
}
2771
}
Línea 2717... Línea 2772...
2717
 
2772
 
2718
/**
2773
/**
-
 
2774
 * Add the default system-context blocks. E.g. the admin tree.
-
 
2775
 *
-
 
2776
 * Because this function is used on install, we skip over any default blocks that do not exist
2719
 * Add the default system-context blocks. E.g. the admin tree.
2777
 * so that install can complete successfully even if blocks are removed.
2720
 */
2778
 */
2721
function blocks_add_default_system_blocks() {
2779
function blocks_add_default_system_blocks() {
Línea 2722... Línea 2780...
2722
    global $DB;
2780
    global $DB;
2723
 
2781
 
2724
    $page = new moodle_page();
2782
    $page = new moodle_page();
-
 
2783
    $page->set_context(context_system::instance());
2725
    $page->set_context(context_system::instance());
2784
    // We don't add blocks required by the theme, they will be auto-created.
-
 
2785
    $page->blocks->add_blocks(
-
 
2786
        $page->blocks->filter_nonexistent_blocks([
-
 
2787
            BLOCK_POS_LEFT => [
-
 
2788
                'admin_bookmarks',
-
 
2789
            ],
-
 
2790
        ]),
-
 
2791
        'admin-*',
-
 
2792
        null,
-
 
2793
        false,
Línea 2726... Línea 2794...
2726
    // We don't add blocks required by the theme, they will be auto-created.
2794
        2,
2727
    $page->blocks->add_blocks(array(BLOCK_POS_LEFT => array('admin_bookmarks')), 'admin-*', null, null, 2);
2795
    );
2728
 
2796
 
2729
    if ($defaultmypage = $DB->get_record('my_pages', array('userid' => null, 'name' => '__default', 'private' => 1))) {
2797
    if ($defaultmypage = $DB->get_record('my_pages', array('userid' => null, 'name' => '__default', 'private' => 1))) {
Línea 2736... Línea 2804...
2736
        $mycoursesubpagepattern = $defaultmycoursespage->id;
2804
        $mycoursesubpagepattern = $defaultmycoursespage->id;
2737
    } else {
2805
    } else {
2738
        $mycoursesubpagepattern = null;
2806
        $mycoursesubpagepattern = null;
2739
    }
2807
    }
Línea 2740... Línea 2808...
2740
 
2808
 
2741
    $page->blocks->add_blocks([
2809
    $page->blocks->add_blocks($page->blocks->filter_nonexistent_blocks([
2742
        BLOCK_POS_RIGHT => [
2810
        BLOCK_POS_RIGHT => [
2743
            'recentlyaccesseditems',
2811
            'recentlyaccesseditems',
2744
        ],
2812
        ],
2745
        'content' => [
2813
        'content' => [
2746
            'timeline',
2814
            'timeline',
2747
            'calendar_month',
2815
            'calendar_month',
2748
        ]],
2816
        ]]),
2749
        'my-index',
2817
        'my-index',
2750
        $subpagepattern
2818
        $subpagepattern
Línea 2751... Línea 2819...
2751
    );
2819
    );
2752
 
2820
 
2753
    $page->blocks->add_blocks([
2821
    $page->blocks->add_blocks($page->blocks->filter_nonexistent_blocks([
2754
        'content' => [
2822
        'content' => [
2755
            'myoverview'
2823
            'myoverview'
2756
        ]],
2824
        ]]),
2757
        'my-index',
2825
        'my-index',
2758
        $mycoursesubpagepattern
2826
        $mycoursesubpagepattern