Proyectos de Subversion Moodle

Rev

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

Rev 1468 Rev 1469
Línea 105... Línea 105...
105
 * @property-read string $subpage The subpage identifier, if any.
105
 * @property-read string $subpage The subpage identifier, if any.
106
 * @property-read theme_config $theme The theme for this page.
106
 * @property-read theme_config $theme The theme for this page.
107
 * @property-read string $title The title that should go in the <head> section of the HTML of this page.
107
 * @property-read string $title The title that should go in the <head> section of the HTML of this page.
108
 * @property-read moodle_url $url The moodle url object for this page.
108
 * @property-read moodle_url $url The moodle url object for this page.
109
 */
109
 */
110
class moodle_page {
110
class moodle_page
-
 
111
{
Línea 111... Línea 112...
111
 
112
 
112
    /** The state of the page before it has printed the header **/
113
    /** The state of the page before it has printed the header **/
Línea 113... Línea 114...
113
    const STATE_BEFORE_HEADER = 0;
114
    const STATE_BEFORE_HEADER = 0;
Línea 442... Línea 443...
442
     * settings menu on an activity / resource page that is being displayed on a theme that
443
     * settings menu on an activity / resource page that is being displayed on a theme that
443
     * uses a settings menu.
444
     * uses a settings menu.
444
     *
445
     *
445
     * @param bool $forced default of true, can be sent false to turn off the force.
446
     * @param bool $forced default of true, can be sent false to turn off the force.
446
     */
447
     */
447
    public function force_settings_menu($forced = true) {
448
    public function force_settings_menu($forced = true)
-
 
449
    {
448
        $this->_forcesettingsmenu = $forced;
450
        $this->_forcesettingsmenu = $forced;
449
    }
451
    }
Línea 450... Línea 452...
450
 
452
 
451
    /**
453
    /**
452
     * Check to see if the settings menu is forced to display on this activity / resource page.
454
     * Check to see if the settings menu is forced to display on this activity / resource page.
453
     * This only applies to themes that use the settings menu.
455
     * This only applies to themes that use the settings menu.
454
     *
456
     *
455
     * @return bool True if the settings menu is forced to display.
457
     * @return bool True if the settings menu is forced to display.
456
     */
458
     */
-
 
459
    public function is_settings_menu_forced()
457
    public function is_settings_menu_forced() {
460
    {
458
        return $this->_forcesettingsmenu;
461
        return $this->_forcesettingsmenu;
Línea 459... Línea 462...
459
    }
462
    }
460
 
463
 
Línea 467... Línea 470...
467
     * @return integer one of the STATE_XXX constants. You should not normally need
470
     * @return integer one of the STATE_XXX constants. You should not normally need
468
     * to use this in your code. It is intended for internal use by this class
471
     * to use this in your code. It is intended for internal use by this class
469
     * and its friends like print_header, to check that everything is working as
472
     * and its friends like print_header, to check that everything is working as
470
     * expected. Also accessible as $PAGE->state.
473
     * expected. Also accessible as $PAGE->state.
471
     */
474
     */
472
    protected function magic_get_state() {
475
    protected function magic_get_state()
-
 
476
    {
473
        return $this->_state;
477
        return $this->_state;
474
    }
478
    }
Línea 475... Línea 479...
475
 
479
 
476
    /**
480
    /**
477
     * Please do not call this method directly, use the ->headerprinted syntax. {@link moodle_page::__get()}.
481
     * Please do not call this method directly, use the ->headerprinted syntax. {@link moodle_page::__get()}.
478
     * @return bool has the header already been printed?
482
     * @return bool has the header already been printed?
479
     */
483
     */
-
 
484
    protected function magic_get_headerprinted()
480
    protected function magic_get_headerprinted() {
485
    {
481
        return $this->_state >= self::STATE_IN_BODY;
486
        return $this->_state >= self::STATE_IN_BODY;
Línea 482... Línea 487...
482
    }
487
    }
483
 
488
 
484
    /**
489
    /**
485
     * Please do not call this method directly, use the ->course syntax. {@link moodle_page::__get()}.
490
     * Please do not call this method directly, use the ->course syntax. {@link moodle_page::__get()}.
486
     * @return stdClass the current course that we are inside - a row from the
491
     * @return stdClass the current course that we are inside - a row from the
487
     * course table. (Also available as $COURSE global.) If we are not inside
492
     * course table. (Also available as $COURSE global.) If we are not inside
488
     * an actual course, this will be the site course.
493
     * an actual course, this will be the site course.
-
 
494
     */
489
     */
495
    protected function magic_get_course()
490
    protected function magic_get_course() {
496
    {
491
        global $SITE;
497
        global $SITE;
492
        if (is_null($this->_course)) {
498
        if (is_null($this->_course)) {
493
            return $SITE;
499
            return $SITE;
Línea 500... Línea 506...
500
     * @return cm_info the course_module that this page belongs to. Will be null
506
     * @return cm_info the course_module that this page belongs to. Will be null
501
     * if this page is not within a module. This is a full cm object, as loaded
507
     * if this page is not within a module. This is a full cm object, as loaded
502
     * by get_coursemodule_from_id or get_coursemodule_from_instance,
508
     * by get_coursemodule_from_id or get_coursemodule_from_instance,
503
     * so the extra modname and name fields are present.
509
     * so the extra modname and name fields are present.
504
     */
510
     */
505
    protected function magic_get_cm() {
511
    protected function magic_get_cm()
-
 
512
    {
506
        return $this->_cm;
513
        return $this->_cm;
507
    }
514
    }
Línea 508... Línea 515...
508
 
515
 
509
    /**
516
    /**
510
     * Please do not call this method directly, use the ->activityrecord syntax. {@link moodle_page::__get()}.
517
     * Please do not call this method directly, use the ->activityrecord syntax. {@link moodle_page::__get()}.
511
     * @return stdClass the row from the activities own database table (for example
518
     * @return stdClass the row from the activities own database table (for example
512
     * the forum or quiz table) that this page belongs to. Will be null
519
     * the forum or quiz table) that this page belongs to. Will be null
513
     * if this page is not within a module.
520
     * if this page is not within a module.
514
     */
521
     */
-
 
522
    protected function magic_get_activityrecord()
515
    protected function magic_get_activityrecord() {
523
    {
516
        if (is_null($this->_module) && !is_null($this->_cm)) {
524
        if (is_null($this->_module) && !is_null($this->_cm)) {
517
            $this->load_activity_record();
525
            $this->load_activity_record();
518
        }
526
        }
519
        return $this->_module;
527
        return $this->_module;
Línea 522... Línea 530...
522
    /**
530
    /**
523
     * Please do not call this method directly, use the ->activityname syntax. {@link moodle_page::__get()}.
531
     * Please do not call this method directly, use the ->activityname syntax. {@link moodle_page::__get()}.
524
     * @return string the The type of activity we are in, for example 'forum' or 'quiz'.
532
     * @return string the The type of activity we are in, for example 'forum' or 'quiz'.
525
     * Will be null if this page is not within a module.
533
     * Will be null if this page is not within a module.
526
     */
534
     */
527
    protected function magic_get_activityname() {
535
    protected function magic_get_activityname()
-
 
536
    {
528
        if (is_null($this->_cm)) {
537
        if (is_null($this->_cm)) {
529
            return null;
538
            return null;
530
        }
539
        }
531
        return $this->_cm->modname;
540
        return $this->_cm->modname;
532
    }
541
    }
Línea 534... Línea 543...
534
    /**
543
    /**
535
     * Please do not call this method directly, use the ->category syntax. {@link moodle_page::__get()}.
544
     * Please do not call this method directly, use the ->category syntax. {@link moodle_page::__get()}.
536
     * @return stdClass|null the category that the page course belongs to. If there isn't one
545
     * @return stdClass|null the category that the page course belongs to. If there isn't one
537
     * (that is, if this is the front page course) returns null.
546
     * (that is, if this is the front page course) returns null.
538
     */
547
     */
539
    protected function magic_get_category() {
548
    protected function magic_get_category()
-
 
549
    {
540
        $this->ensure_category_loaded();
550
        $this->ensure_category_loaded();
541
        if (!empty($this->_categories)) {
551
        if (!empty($this->_categories)) {
542
            return reset($this->_categories);
552
            return reset($this->_categories);
543
        } else {
553
        } else {
544
            return null;
554
            return null;
Línea 550... Línea 560...
550
     * @return array an array of all the categories the page course belongs to,
560
     * @return array an array of all the categories the page course belongs to,
551
     * starting with the immediately containing category, and working out to
561
     * starting with the immediately containing category, and working out to
552
     * the top-level category. This may be the empty array if we are in the
562
     * the top-level category. This may be the empty array if we are in the
553
     * front page course.
563
     * front page course.
554
     */
564
     */
555
    protected function magic_get_categories() {
565
    protected function magic_get_categories()
-
 
566
    {
556
        $this->ensure_categories_loaded();
567
        $this->ensure_categories_loaded();
557
        return $this->_categories;
568
        return $this->_categories;
558
    }
569
    }
Línea 559... Línea 570...
559
 
570
 
560
    /**
571
    /**
561
     * Please do not call this method directly, use the ->context syntax. {@link moodle_page::__get()}.
572
     * Please do not call this method directly, use the ->context syntax. {@link moodle_page::__get()}.
562
     * @return context the main context to which this page belongs.
573
     * @return context the main context to which this page belongs.
563
     */
574
     */
-
 
575
    protected function magic_get_context()
564
    protected function magic_get_context() {
576
    {
565
        global $CFG;
577
        global $CFG;
566
        if (is_null($this->_context)) {
578
        if (is_null($this->_context)) {
567
            if (CLI_SCRIPT or NO_MOODLE_COOKIES) {
579
            if (CLI_SCRIPT or NO_MOODLE_COOKIES) {
568
                // Cli scripts work in system context, do not annoy devs with debug info.
580
                // Cli scripts work in system context, do not annoy devs with debug info.
569
                // Very few scripts do not use cookies, we can safely use system as default context there.
581
                // Very few scripts do not use cookies, we can safely use system as default context there.
570
            } else if (AJAX_SCRIPT && $CFG->debugdeveloper) {
582
            } else if (AJAX_SCRIPT && $CFG->debugdeveloper) {
571
                // Throw exception inside AJAX script in developer mode, otherwise the debugging message may be missed.
583
                // Throw exception inside AJAX script in developer mode, otherwise the debugging message may be missed.
572
                throw new coding_exception('$PAGE->context was not set. You may have forgotten '
584
                throw new coding_exception('$PAGE->context was not set. You may have forgotten '
573
                    .'to call require_login() or $PAGE->set_context()');
585
                    . 'to call require_login() or $PAGE->set_context()');
574
            } else {
586
            } else {
575
                debugging('Coding problem: $PAGE->context was not set. You may have forgotten '
587
                debugging('Coding problem: $PAGE->context was not set. You may have forgotten '
576
                    .'to call require_login() or $PAGE->set_context(). The page may not display '
588
                    . 'to call require_login() or $PAGE->set_context(). The page may not display '
577
                    .'correctly as a result');
589
                    . 'correctly as a result');
578
            }
590
            }
579
            $this->_context = context_system::instance();
591
            $this->_context = context_system::instance();
580
        }
592
        }
581
        return $this->_context;
593
        return $this->_context;
Línea 582... Línea 594...
582
    }
594
    }
583
 
595
 
584
    /**
596
    /**
585
     * Please do not call this method directly, use the ->pagetype syntax. {@link moodle_page::__get()}.
597
     * Please do not call this method directly, use the ->pagetype syntax. {@link moodle_page::__get()}.
586
     * @return string e.g. 'my-index' or 'mod-quiz-attempt'.
598
     * @return string e.g. 'my-index' or 'mod-quiz-attempt'.
-
 
599
     */
587
     */
600
    protected function magic_get_pagetype()
588
    protected function magic_get_pagetype() {
601
    {
589
        global $CFG;
602
        global $CFG;
590
        if (is_null($this->_pagetype) || isset($CFG->pagepath)) {
603
        if (is_null($this->_pagetype) || isset($CFG->pagepath)) {
591
            $this->initialise_default_pagetype();
604
            $this->initialise_default_pagetype();
Línea 595... Línea 608...
595
 
608
 
596
    /**
609
    /**
597
     * Please do not call this method directly, use the ->pagetype syntax. {@link moodle_page::__get()}.
610
     * Please do not call this method directly, use the ->pagetype syntax. {@link moodle_page::__get()}.
598
     * @return string The id to use on the body tag, uses {@link magic_get_pagetype()}.
611
     * @return string The id to use on the body tag, uses {@link magic_get_pagetype()}.
599
     */
612
     */
-
 
613
    protected function magic_get_bodyid()
600
    protected function magic_get_bodyid() {
614
    {
601
        return 'page-'.$this->pagetype;
615
        return 'page-' . $this->pagetype;
Línea 602... Línea 616...
602
    }
616
    }
603
 
617
 
604
    /**
618
    /**
605
     * Please do not call this method directly, use the ->pagelayout syntax. {@link moodle_page::__get()}.
619
     * Please do not call this method directly, use the ->pagelayout syntax. {@link moodle_page::__get()}.
606
     * @return string the general type of page this is. For example 'standard', 'popup', 'home'.
620
     * @return string the general type of page this is. For example 'standard', 'popup', 'home'.
607
     *      Allows the theme to display things differently, if it wishes to.
621
     *      Allows the theme to display things differently, if it wishes to.
-
 
622
     */
608
     */
623
    protected function magic_get_pagelayout()
609
    protected function magic_get_pagelayout() {
624
    {
Línea 610... Línea 625...
610
        return $this->_pagelayout;
625
        return $this->_pagelayout;
611
    }
626
    }
612
 
627
 
613
    /**
628
    /**
614
     * Please do not call this method directly, use the ->layout_options syntax. {@link moodle_page::__get()}.
629
     * Please do not call this method directly, use the ->layout_options syntax. {@link moodle_page::__get()}.
-
 
630
     * @return array returns arrays with options for layout file
615
     * @return array returns arrays with options for layout file
631
     */
616
     */
632
    protected function magic_get_layout_options()
617
    protected function magic_get_layout_options() {
633
    {
618
        if (!is_array($this->_layout_options)) {
634
        if (!is_array($this->_layout_options)) {
619
            $this->_layout_options = $this->theme->pagelayout_options($this->pagelayout);
635
            $this->_layout_options = $this->theme->pagelayout_options($this->pagelayout);
Línea 620... Línea 636...
620
        }
636
        }
621
        return $this->_layout_options;
637
        return $this->_layout_options;
622
    }
638
    }
623
 
639
 
624
    /**
640
    /**
-
 
641
     * Please do not call this method directly, use the ->subpage syntax. {@link moodle_page::__get()}.
625
     * Please do not call this method directly, use the ->subpage syntax. {@link moodle_page::__get()}.
642
     * @return string The subpage identifier, if any.
626
     * @return string The subpage identifier, if any.
643
     */
Línea 627... Línea 644...
627
     */
644
    protected function magic_get_subpage()
628
    protected function magic_get_subpage() {
645
    {
629
        return $this->_subpage;
646
        return $this->_subpage;
630
    }
647
    }
631
 
648
 
-
 
649
    /**
632
    /**
650
     * Please do not call this method directly, use the ->bodyclasses syntax. {@link moodle_page::__get()}.
633
     * Please do not call this method directly, use the ->bodyclasses syntax. {@link moodle_page::__get()}.
651
     * @return string the class names to put on the body element in the HTML.
Línea 634... Línea 652...
634
     * @return string the class names to put on the body element in the HTML.
652
     */
635
     */
653
    protected function magic_get_bodyclasses()
636
    protected function magic_get_bodyclasses() {
654
    {
637
        return implode(' ', array_keys($this->_bodyclasses));
655
        return implode(' ', array_keys($this->_bodyclasses));
638
    }
656
    }
-
 
657
 
639
 
658
    /**
640
    /**
659
     * Please do not call this method directly, use the ->title syntax. {@link moodle_page::__get()}.
Línea 641... Línea 660...
641
     * Please do not call this method directly, use the ->title syntax. {@link moodle_page::__get()}.
660
     * @return string the title that should go in the <head> section of the HTML of this page.
642
     * @return string the title that should go in the <head> section of the HTML of this page.
661
     */
643
     */
662
    protected function magic_get_title()
644
    protected function magic_get_title() {
663
    {
645
        return $this->_title;
664
        return $this->_title;
-
 
665
    }
646
    }
666
 
647
 
667
    /**
Línea 648... Línea 668...
648
    /**
668
     * Please do not call this method directly, use the ->heading syntax. {@link moodle_page::__get()}.
649
     * Please do not call this method directly, use the ->heading syntax. {@link moodle_page::__get()}.
669
     * @return string the main heading that should be displayed at the top of the <body>.
650
     * @return string the main heading that should be displayed at the top of the <body>.
670
     */
651
     */
671
    protected function magic_get_heading()
652
    protected function magic_get_heading() {
672
    {
-
 
673
        return $this->_heading;
653
        return $this->_heading;
674
    }
654
    }
675
 
Línea 655... Línea 676...
655
 
676
    /**
656
    /**
677
     * Please do not call this method directly, use the ->heading syntax. {@link moodle_page::__get()}.
657
     * Please do not call this method directly, use the ->heading syntax. {@link moodle_page::__get()}.
678
     * @return string The menu (or actions) to display in the heading
658
     * @return string The menu (or actions) to display in the heading
679
     */
659
     */
680
    protected function magic_get_headingmenu()
-
 
681
    {
660
    protected function magic_get_headingmenu() {
682
        return $this->_headingmenu;
661
        return $this->_headingmenu;
683
    }
662
    }
684
 
663
 
685
    /**
664
    /**
686
     * Please do not call this method directly, use the ->docspath syntax. {@link moodle_page::__get()}.
Línea 676... Línea 698...
676
    /**
698
    /**
677
     * Please do not call this method directly, use the ->url syntax. {@link moodle_page::__get()}.
699
     * Please do not call this method directly, use the ->url syntax. {@link moodle_page::__get()}.
678
     * @return moodle_url the clean URL required to load the current page. (You
700
     * @return moodle_url the clean URL required to load the current page. (You
679
     * should normally use this in preference to $ME or $FULLME.)
701
     * should normally use this in preference to $ME or $FULLME.)
680
     */
702
     */
681
    protected function magic_get_url() {
703
    protected function magic_get_url()
-
 
704
    {
682
        global $FULLME;
705
        global $FULLME;
683
        if (is_null($this->_url)) {
706
        if (is_null($this->_url)) {
684
            debugging('This page did not call $PAGE->set_url(...). Using '.s($FULLME), DEBUG_DEVELOPER);
707
            debugging('This page did not call $PAGE->set_url(...). Using ' . s($FULLME), DEBUG_DEVELOPER);
685
            $this->_url = new moodle_url($FULLME);
708
            $this->_url = new moodle_url($FULLME);
686
            // Make sure the guessed URL cannot lead to dangerous redirects.
709
            // Make sure the guessed URL cannot lead to dangerous redirects.
687
            $this->_url->remove_params('sesskey');
710
            $this->_url->remove_params('sesskey');
688
        }
711
        }
689
        return new moodle_url($this->_url); // Return a clone for safety.
712
        return new moodle_url($this->_url); // Return a clone for safety.
Línea 691... Línea 714...
691
 
714
 
692
    /**
715
    /**
693
     * The list of alternate versions of this page.
716
     * The list of alternate versions of this page.
694
     * @return array mime type => object with ->url and ->title.
717
     * @return array mime type => object with ->url and ->title.
695
     */
718
     */
-
 
719
    protected function magic_get_alternateversions()
696
    protected function magic_get_alternateversions() {
720
    {
697
        return $this->_alternateversions;
721
        return $this->_alternateversions;
Línea 698... Línea 722...
698
    }
722
    }
699
 
723
 
700
    /**
724
    /**
701
     * Please do not call this method directly, use the ->blocks syntax. {@link moodle_page::__get()}.
725
     * Please do not call this method directly, use the ->blocks syntax. {@link moodle_page::__get()}.
702
     * @return block_manager the blocks manager object for this page.
726
     * @return block_manager the blocks manager object for this page.
-
 
727
     */
703
     */
728
    protected function magic_get_blocks()
704
    protected function magic_get_blocks() {
729
    {
705
        global $CFG;
730
        global $CFG;
706
        if (is_null($this->_blocks)) {
731
        if (is_null($this->_blocks)) {
707
            if (!empty($CFG->blockmanagerclass)) {
732
            if (!empty($CFG->blockmanagerclass)) {
Línea 719... Línea 744...
719
 
744
 
720
    /**
745
    /**
721
     * Please do not call this method directly, use the ->requires syntax. {@link moodle_page::__get()}.
746
     * Please do not call this method directly, use the ->requires syntax. {@link moodle_page::__get()}.
722
     * @return page_requirements_manager tracks the JavaScript, CSS files, etc. required by this page.
747
     * @return page_requirements_manager tracks the JavaScript, CSS files, etc. required by this page.
723
     */
748
     */
-
 
749
    protected function magic_get_requires()
724
    protected function magic_get_requires() {
750
    {
725
        if (is_null($this->_requires)) {
751
        if (is_null($this->_requires)) {
726
            $this->_requires = new page_requirements_manager();
752
            $this->_requires = new page_requirements_manager();
727
        }
753
        }
728
        return $this->_requires;
754
        return $this->_requires;
Línea 729... Línea 755...
729
    }
755
    }
730
 
756
 
731
    /**
757
    /**
732
     * Please do not call this method directly, use the ->cacheable syntax. {@link moodle_page::__get()}.
758
     * Please do not call this method directly, use the ->cacheable syntax. {@link moodle_page::__get()}.
733
     * @return bool can this page be cached by the user's browser.
759
     * @return bool can this page be cached by the user's browser.
-
 
760
     */
734
     */
761
    protected function magic_get_cacheable()
735
    protected function magic_get_cacheable() {
762
    {
Línea 736... Línea 763...
736
        return $this->_cacheable;
763
        return $this->_cacheable;
737
    }
764
    }
738
 
765
 
739
    /**
766
    /**
740
     * Please do not call this method directly, use the ->focuscontrol syntax. {@link moodle_page::__get()}.
767
     * Please do not call this method directly, use the ->focuscontrol syntax. {@link moodle_page::__get()}.
-
 
768
     * @return string the id of the HTML element to be focused when the page has loaded.
741
     * @return string the id of the HTML element to be focused when the page has loaded.
769
     */
742
     */
770
    protected function magic_get_focuscontrol()
Línea 743... Línea 771...
743
    protected function magic_get_focuscontrol() {
771
    {
744
        return $this->_focuscontrol;
772
        return $this->_focuscontrol;
745
    }
773
    }
746
 
774
 
747
    /**
775
    /**
-
 
776
     * Please do not call this method directly, use the ->button syntax. {@link moodle_page::__get()}.
748
     * Please do not call this method directly, use the ->button syntax. {@link moodle_page::__get()}.
777
     * @return string the HTML to go where the Turn editing on button normally goes.
749
     * @return string the HTML to go where the Turn editing on button normally goes.
778
     */
Línea 750... Línea 779...
750
     */
779
    protected function magic_get_button()
751
    protected function magic_get_button() {
780
    {
752
        return $this->_button;
781
        return $this->_button;
753
    }
782
    }
754
 
783
 
-
 
784
    /**
755
    /**
785
     * Please do not call this method directly, use the ->theme syntax. {@link moodle_page::__get()}.
756
     * Please do not call this method directly, use the ->theme syntax. {@link moodle_page::__get()}.
786
     * @return theme_config the initialised theme for this page.
757
     * @return theme_config the initialised theme for this page.
787
     */
758
     */
788
    protected function magic_get_theme()
759
    protected function magic_get_theme() {
789
    {
Línea 767... Línea 797...
767
     * Returns an array of minipulations or false if there are none to make.
797
     * Returns an array of minipulations or false if there are none to make.
768
     *
798
     *
769
     * @since Moodle 2.5.1 2.6
799
     * @since Moodle 2.5.1 2.6
770
     * @return bool|array
800
     * @return bool|array
771
     */
801
     */
772
    protected function magic_get_blockmanipulations() {
802
    protected function magic_get_blockmanipulations()
-
 
803
    {
773
        if (!right_to_left()) {
804
        if (!right_to_left()) {
774
            return false;
805
            return false;
775
        }
806
        }
776
        if (is_null($this->_theme)) {
807
        if (is_null($this->_theme)) {
777
            $this->initialise_theme_and_output();
808
            $this->initialise_theme_and_output();
Línea 781... Línea 812...
781
 
812
 
782
    /**
813
    /**
783
     * Please do not call this method directly, use the ->devicetypeinuse syntax. {@link moodle_page::__get()}.
814
     * Please do not call this method directly, use the ->devicetypeinuse syntax. {@link moodle_page::__get()}.
784
     * @return string The device type being used.
815
     * @return string The device type being used.
785
     */
816
     */
-
 
817
    protected function magic_get_devicetypeinuse()
786
    protected function magic_get_devicetypeinuse() {
818
    {
787
        if (empty($this->_devicetypeinuse)) {
819
        if (empty($this->_devicetypeinuse)) {
788
            $this->_devicetypeinuse = core_useragent::get_user_device_type();
820
            $this->_devicetypeinuse = core_useragent::get_user_device_type();
789
        }
821
        }
790
        return $this->_devicetypeinuse;
822
        return $this->_devicetypeinuse;
Línea 793... Línea 825...
793
    /**
825
    /**
794
     * Please do not call this method directly use the ->periodicrefreshdelay syntax
826
     * Please do not call this method directly use the ->periodicrefreshdelay syntax
795
     * {@link moodle_page::__get()}
827
     * {@link moodle_page::__get()}
796
     * @return int The periodic refresh delay to use with meta refresh
828
     * @return int The periodic refresh delay to use with meta refresh
797
     */
829
     */
798
    protected function magic_get_periodicrefreshdelay() {
830
    protected function magic_get_periodicrefreshdelay()
-
 
831
    {
799
        return $this->_periodicrefreshdelay;
832
        return $this->_periodicrefreshdelay;
800
    }
833
    }
Línea 801... Línea 834...
801
 
834
 
802
    /**
835
    /**
803
     * Please do not call this method directly use the ->opencontainers syntax. {@link moodle_page::__get()}
836
     * Please do not call this method directly use the ->opencontainers syntax. {@link moodle_page::__get()}
804
     * @return xhtml_container_stack tracks XHTML tags on this page that have been opened but not closed.
837
     * @return xhtml_container_stack tracks XHTML tags on this page that have been opened but not closed.
805
     *      mainly for internal use by the rendering code.
838
     *      mainly for internal use by the rendering code.
806
     */
839
     */
-
 
840
    protected function magic_get_opencontainers()
807
    protected function magic_get_opencontainers() {
841
    {
808
        if (is_null($this->_opencontainers)) {
842
        if (is_null($this->_opencontainers)) {
809
            $this->_opencontainers = new xhtml_container_stack();
843
            $this->_opencontainers = new xhtml_container_stack();
810
        }
844
        }
811
        return $this->_opencontainers;
845
        return $this->_opencontainers;
Línea 812... Línea 846...
812
    }
846
    }
813
 
847
 
814
    /**
848
    /**
815
     * Return the navigation object
849
     * Return the navigation object
816
     * @return global_navigation
850
     * @return global_navigation
-
 
851
     */
817
     */
852
    protected function magic_get_navigation()
818
    protected function magic_get_navigation() {
853
    {
819
        if ($this->_navigation === null) {
854
        if ($this->_navigation === null) {
820
            $this->_navigation = new global_navigation($this);
855
            $this->_navigation = new global_navigation($this);
821
        }
856
        }
Línea 822... Línea 857...
822
        return $this->_navigation;
857
        return $this->_navigation;
823
    }
858
    }
824
 
859
 
825
    /**
860
    /**
826
     * Return a navbar object
861
     * Return a navbar object
-
 
862
     * @return navbar
827
     * @return navbar
863
     */
828
     */
864
    protected function magic_get_navbar()
829
    protected function magic_get_navbar() {
865
    {
830
        if ($this->_navbar === null) {
866
        if ($this->_navbar === null) {
831
            $this->_navbar = new navbar($this);
867
            $this->_navbar = new navbar($this);
Línea 832... Línea 868...
832
        }
868
        }
833
        return $this->_navbar;
869
        return $this->_navbar;
834
    }
870
    }
835
 
871
 
836
    /**
872
    /**
-
 
873
     * Returns the settings navigation object
837
     * Returns the settings navigation object
874
     * @return settings_navigation
838
     * @return settings_navigation
875
     */
839
     */
876
    protected function magic_get_settingsnav()
840
    protected function magic_get_settingsnav() {
877
    {
841
        if ($this->_settingsnav === null) {
878
        if ($this->_settingsnav === null) {
Línea 847... Línea 884...
847
 
884
 
848
    /**
885
    /**
849
     * Returns the flat navigation object
886
     * Returns the flat navigation object
850
     * @return flat_navigation
887
     * @return flat_navigation
851
     */
888
     */
-
 
889
    protected function magic_get_flatnav()
852
    protected function magic_get_flatnav() {
890
    {
853
        if ($this->_flatnav === null) {
891
        if ($this->_flatnav === null) {
854
            $this->_flatnav = new flat_navigation($this);
892
            $this->_flatnav = new flat_navigation($this);
855
            $this->_flatnav->initialise();
893
            $this->_flatnav->initialise();
856
        }
894
        }
Línea 859... Línea 897...
859
 
897
 
860
    /**
898
    /**
861
     * Returns the activity header object
899
     * Returns the activity header object
862
     * @return activity_header
900
     * @return activity_header
863
     */
901
     */
-
 
902
    protected function magic_get_activityheader(): activity_header
864
    protected function magic_get_activityheader(): activity_header {
903
    {
865
        global $USER;
904
        global $USER;
866
        if ($this->_activityheader === null) {
905
        if ($this->_activityheader === null) {
867
            $class = activity_header::class;
906
            $class = activity_header::class;
868
            // Try and load a custom class first.
907
            // Try and load a custom class first.
Línea 878... Línea 917...
878
    /**
917
    /**
879
     * Returns the secondary navigation object
918
     * Returns the secondary navigation object
880
     *
919
     *
881
     * @return secondary
920
     * @return secondary
882
     */
921
     */
883
    protected function magic_get_secondarynav() {
922
    protected function magic_get_secondarynav()
-
 
923
    {
884
        if ($this->_secondarynav === null) {
924
        if ($this->_secondarynav === null) {
885
            $class = 'core\navigation\views\secondary';
925
            $class = 'core\navigation\views\secondary';
Línea 886... Línea 926...
886
 
926
 
887
            // Check whether activity defines its own secondary navigation.
927
            // Check whether activity defines its own secondary navigation.
Línea 897... Línea 937...
897
 
937
 
898
    /**
938
    /**
899
     * Returns the primary navigation object
939
     * Returns the primary navigation object
900
     * @return primary
940
     * @return primary
901
     */
941
     */
-
 
942
    protected function magic_get_primarynav()
902
    protected function magic_get_primarynav() {
943
    {
903
        if ($this->_primarynav === null) {
944
        if ($this->_primarynav === null) {
904
            $this->_primarynav = new primary($this);
945
            $this->_primarynav = new primary($this);
905
            $this->_primarynav->initialise();
946
            $this->_primarynav->initialise();
906
        }
947
        }
Línea 909... Línea 950...
909
 
950
 
910
    /**
951
    /**
911
     * Returns the primary navigation object
952
     * Returns the primary navigation object
912
     * @return primaryoutput
953
     * @return primaryoutput
913
     */
954
     */
-
 
955
    protected function magic_get_primarynavcombined()
914
    protected function magic_get_primarynavcombined() {
956
    {
915
        if ($this->_primarynavcombined === null) {
957
        if ($this->_primarynavcombined === null) {
916
            $this->_primarynavcombined = new primaryoutput($this);
958
            $this->_primarynavcombined = new primaryoutput($this);
917
        }
959
        }
918
        return $this->_primarynavcombined;
960
        return $this->_primarynavcombined;
Línea 921... Línea 963...
921
    /**
963
    /**
922
     * Returns request IP address.
964
     * Returns request IP address.
923
     *
965
     *
924
     * @return string IP address or null if unknown
966
     * @return string IP address or null if unknown
925
     */
967
     */
926
    protected function magic_get_requestip() {
968
    protected function magic_get_requestip()
-
 
969
    {
927
        return getremoteaddr(null);
970
        return getremoteaddr(null);
928
    }
971
    }
Línea 929... Línea 972...
929
 
972
 
930
    /**
973
    /**
931
     * Returns the origin of current request.
974
     * Returns the origin of current request.
932
     *
975
     *
933
     * Note: constants are not required because we need to use these values in logging and reports.
976
     * Note: constants are not required because we need to use these values in logging and reports.
934
     *
977
     *
935
     * @return string 'web', 'ws', 'cli', 'restore', etc.
978
     * @return string 'web', 'ws', 'cli', 'restore', etc.
936
     */
979
     */
-
 
980
    protected function magic_get_requestorigin()
937
    protected function magic_get_requestorigin() {
981
    {
938
        if (class_exists('restore_controller', false) && restore_controller::is_executing()) {
982
        if (class_exists('restore_controller', false) && restore_controller::is_executing()) {
939
            return 'restore';
983
            return 'restore';
Línea 940... Línea 984...
940
        }
984
        }
Línea 957... Línea 1001...
957
     *
1001
     *
958
     * @param string $name property name
1002
     * @param string $name property name
959
     * @return mixed
1003
     * @return mixed
960
     * @throws coding_exception
1004
     * @throws coding_exception
961
     */
1005
     */
962
    public function __get($name) {
1006
    public function __get($name)
-
 
1007
    {
963
        $getmethod = 'magic_get_' . $name;
1008
        $getmethod = 'magic_get_' . $name;
964
        if (method_exists($this, $getmethod)) {
1009
        if (method_exists($this, $getmethod)) {
965
            return $this->$getmethod();
1010
            return $this->$getmethod();
966
        } else {
1011
        } else {
967
            throw new coding_exception('Unknown property ' . $name . ' of $PAGE.');
1012
            throw new coding_exception('Unknown property ' . $name . ' of $PAGE.');
Línea 979... Línea 1024...
979
     * @param string $name property name
1024
     * @param string $name property name
980
     * @param mixed $value Value
1025
     * @param mixed $value Value
981
     * @return void Throws exception if field not defined in page class
1026
     * @return void Throws exception if field not defined in page class
982
     * @throws coding_exception
1027
     * @throws coding_exception
983
     */
1028
     */
984
    public function __set($name, $value) {
1029
    public function __set($name, $value)
-
 
1030
    {
985
        if (method_exists($this, 'set_' . $name)) {
1031
        if (method_exists($this, 'set_' . $name)) {
986
            throw new coding_exception('Invalid attempt to modify page object', "Use \$PAGE->set_$name() instead.");
1032
            throw new coding_exception('Invalid attempt to modify page object', "Use \$PAGE->set_$name() instead.");
987
        } else {
1033
        } else {
988
            throw new coding_exception('Invalid attempt to modify page object', "Unknown property $name");
1034
            throw new coding_exception('Invalid attempt to modify page object', "Unknown property $name");
989
        }
1035
        }
Línea 997... Línea 1043...
997
     * @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
1043
     * @param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
998
     * @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
1044
     * @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
999
     * @param string $target one of rendering target constants
1045
     * @param string $target one of rendering target constants
1000
     * @return renderer_base
1046
     * @return renderer_base
1001
     */
1047
     */
1002
    public function get_renderer($component, $subtype = null, $target = null) {
1048
    public function get_renderer($component, $subtype = null, $target = null)
-
 
1049
    {
1003
        if ($this->pagelayout === 'maintenance') {
1050
        if ($this->pagelayout === 'maintenance') {
1004
            // If the page is using the maintenance layout then we're going to force target to maintenance.
1051
            // If the page is using the maintenance layout then we're going to force target to maintenance.
1005
            // This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this
1052
            // This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this
1006
            // page layout.
1053
            // page layout.
1007
            $target = RENDERER_TARGET_MAINTENANCE;
1054
            $target = RENDERER_TARGET_MAINTENANCE;
Línea 1012... Línea 1059...
1012
    /**
1059
    /**
1013
     * Checks to see if there are any items on the navbar object
1060
     * Checks to see if there are any items on the navbar object
1014
     *
1061
     *
1015
     * @return bool true if there are, false if not
1062
     * @return bool true if there are, false if not
1016
     */
1063
     */
1017
    public function has_navbar() {
1064
    public function has_navbar()
-
 
1065
    {
1018
        if ($this->_navbar === null) {
1066
        if ($this->_navbar === null) {
1019
            $this->_navbar = new navbar($this);
1067
            $this->_navbar = new navbar($this);
1020
        }
1068
        }
1021
        return $this->_navbar->has_items();
1069
        return $this->_navbar->has_items();
1022
    }
1070
    }
Línea 1024... Línea 1072...
1024
    /**
1072
    /**
1025
     * Switches from the regular requirements manager to the fragment requirements manager to
1073
     * Switches from the regular requirements manager to the fragment requirements manager to
1026
     * capture all necessary JavaScript to display a chunk of HTML such as an mform. This is for use
1074
     * capture all necessary JavaScript to display a chunk of HTML such as an mform. This is for use
1027
     * by the get_fragment() web service and not for use elsewhere.
1075
     * by the get_fragment() web service and not for use elsewhere.
1028
     */
1076
     */
1029
    public function start_collecting_javascript_requirements() {
1077
    public function start_collecting_javascript_requirements()
-
 
1078
    {
1030
        // Check that the requirements manager has not already been switched.
1079
        // Check that the requirements manager has not already been switched.
1031
        if (get_class($this->_requires) == 'fragment_requirements_manager') {
1080
        if (get_class($this->_requires) == 'fragment_requirements_manager') {
1032
            throw new coding_exception('JavaScript collection has already been started.');
1081
            throw new coding_exception('JavaScript collection has already been started.');
1033
        }
1082
        }
1034
        // The header needs to have been called to flush out the generic JavaScript for the page. This allows only
1083
        // The header needs to have been called to flush out the generic JavaScript for the page. This allows only
Línea 1043... Línea 1092...
1043
    }
1092
    }
Línea 1044... Línea 1093...
1044
 
1093
 
1045
    /**
1094
    /**
1046
     * Switches back from collecting fragment JS requirement to the original requirement manager
1095
     * Switches back from collecting fragment JS requirement to the original requirement manager
1047
     */
1096
     */
-
 
1097
    public function end_collecting_javascript_requirements()
1048
    public function end_collecting_javascript_requirements() {
1098
    {
1049
        if ($this->savedrequires === null) {
1099
        if ($this->savedrequires === null) {
1050
            throw new coding_exception('JavaScript collection has not been started.');
1100
            throw new coding_exception('JavaScript collection has not been started.');
1051
        }
1101
        }
1052
        $this->_requires = $this->savedrequires;
1102
        $this->_requires = $this->savedrequires;
Línea 1057... Línea 1107...
1057
     * Should the current user see this page in editing mode.
1107
     * Should the current user see this page in editing mode.
1058
     * That is, are they allowed to edit this page, and are they currently in
1108
     * That is, are they allowed to edit this page, and are they currently in
1059
     * editing mode.
1109
     * editing mode.
1060
     * @return bool
1110
     * @return bool
1061
     */
1111
     */
1062
    public function user_is_editing() {
1112
    public function user_is_editing()
-
 
1113
    {
1063
        global $USER;
1114
        global $USER;
1064
        return !empty($USER->editing) && $this->user_allowed_editing();
1115
        return !empty($USER->editing) && $this->user_allowed_editing();
1065
    }
1116
    }
Línea 1066... Línea 1117...
1066
 
1117
 
1067
    /**
1118
    /**
1068
     * Does the user have permission to edit blocks on this page.
1119
     * Does the user have permission to edit blocks on this page.
1069
     * Can be forced to false by calling the force_lock_all_blocks() method.
1120
     * Can be forced to false by calling the force_lock_all_blocks() method.
1070
     *
1121
     *
1071
     * @return bool
1122
     * @return bool
1072
     */
1123
     */
-
 
1124
    public function user_can_edit_blocks()
1073
    public function user_can_edit_blocks() {
1125
    {
1074
        return $this->_forcelockallblocks ? false : has_capability($this->_blockseditingcap, $this->_context);
1126
        return $this->_forcelockallblocks ? false : has_capability($this->_blockseditingcap, $this->_context);
Línea 1075... Línea 1127...
1075
    }
1127
    }
1076
 
1128
 
1077
    /**
1129
    /**
1078
     * Does the user have permission to see this page in editing mode.
1130
     * Does the user have permission to see this page in editing mode.
1079
     * @return bool
1131
     * @return bool
-
 
1132
     */
1080
     */
1133
    public function user_allowed_editing()
1081
    public function user_allowed_editing() {
1134
    {
Línea 1082... Línea 1135...
1082
        return has_any_capability($this->all_editing_caps(), $this->_context);
1135
        return has_any_capability($this->all_editing_caps(), $this->_context);
1083
    }
1136
    }
1084
 
1137
 
1085
    /**
1138
    /**
1086
     * Get a description of this page. Normally displayed in the footer in developer debug mode.
1139
     * Get a description of this page. Normally displayed in the footer in developer debug mode.
-
 
1140
     * @return string
1087
     * @return string
1141
     */
1088
     */
1142
    public function debug_summary()
1089
    public function debug_summary() {
1143
    {
1090
        $summary = '';
1144
        $summary = '';
1091
        $summary .= 'General type: ' . $this->pagelayout . '. ';
1145
        $summary .= 'General type: ' . $this->pagelayout . '. ';
Línea 1119... Línea 1173...
1119
     * The state must be one of that STATE_... constants, and the state is only allowed to advance one step at a time.
1173
     * The state must be one of that STATE_... constants, and the state is only allowed to advance one step at a time.
1120
     *
1174
     *
1121
     * @param int $state The new state.
1175
     * @param int $state The new state.
1122
     * @throws coding_exception
1176
     * @throws coding_exception
1123
     */
1177
     */
1124
    public function set_state($state) {
1178
    public function set_state($state)
-
 
1179
    {
1125
        if ($state != $this->_state + 1 || $state > self::STATE_DONE) {
1180
        if ($state != $this->_state + 1 || $state > self::STATE_DONE) {
1126
            throw new coding_exception('Invalid state passed to moodle_page::set_state. We are in state ' .
1181
            throw new coding_exception('Invalid state passed to moodle_page::set_state. We are in state ' .
1127
                    $this->_state . ' and state ' . $state . ' was requested.');
1182
                $this->_state . ' and state ' . $state . ' was requested.');
1128
        }
1183
        }
Línea 1129... Línea 1184...
1129
 
1184
 
1130
        if ($state == self::STATE_PRINTING_HEADER) {
1185
        if ($state == self::STATE_PRINTING_HEADER) {
1131
            $this->starting_output();
1186
            $this->starting_output();
Línea 1145... Línea 1200...
1145
     * Sets $PAGE->context to the course context, if it is not already set.
1200
     * Sets $PAGE->context to the course context, if it is not already set.
1146
     *
1201
     *
1147
     * @param stdClass $course the course to set as the global course.
1202
     * @param stdClass $course the course to set as the global course.
1148
     * @throws coding_exception
1203
     * @throws coding_exception
1149
     */
1204
     */
1150
    public function set_course($course) {
1205
    public function set_course($course)
-
 
1206
    {
1151
        global $COURSE, $PAGE, $CFG, $SITE;
1207
        global $COURSE, $PAGE, $CFG, $SITE;
Línea 1152... Línea 1208...
1152
 
1208
 
1153
        if (empty($course->id)) {
1209
        if (empty($course->id)) {
1154
            throw new coding_exception('$course passed to moodle_page::set_course does not look like a proper course object.');
1210
            throw new coding_exception('$course passed to moodle_page::set_course does not look like a proper course object.');
Línea 1158... Línea 1214...
1158
 
1214
 
1159
        if (!empty($this->_course->id) && $this->_course->id != $course->id) {
1215
        if (!empty($this->_course->id) && $this->_course->id != $course->id) {
1160
            $this->_categories = null;
1216
            $this->_categories = null;
Línea 1161... Línea 1217...
1161
        }
1217
        }
Línea 1162... Línea 1218...
1162
 
1218
 
1163
        $this->_course = clone($course);
1219
        $this->_course = clone ($course);
1164
 
1220
 
1165
        if ($this === $PAGE) {
1221
        if ($this === $PAGE) {
Línea 1171... Línea 1227...
1171
            $this->set_context(context_course::instance($this->_course->id));
1227
            $this->set_context(context_course::instance($this->_course->id));
1172
        }
1228
        }
Línea 1173... Línea 1229...
1173
 
1229
 
1174
        // Notify course format that this page is set for the course.
1230
        // Notify course format that this page is set for the course.
1175
        if ($this->_course->id != $SITE->id) {
1231
        if ($this->_course->id != $SITE->id) {
1176
            require_once($CFG->dirroot.'/course/lib.php');
1232
            require_once($CFG->dirroot . '/course/lib.php');
1177
            $courseformat = course_get_format($this->_course);
1233
            $courseformat = course_get_format($this->_course);
1178
            $this->add_body_class('format-'. $courseformat->get_format());
1234
            $this->add_body_class('format-' . $courseformat->get_format());
1179
            $courseformat->page_set_course($this);
1235
            $courseformat->page_set_course($this);
1180
        } else {
1236
        } else {
1181
            $this->add_body_class('format-site');
1237
            $this->add_body_class('format-site');
1182
        }
1238
        }
Línea 1185... Línea 1241...
1185
    /**
1241
    /**
1186
     * Set the main context to which this page belongs.
1242
     * Set the main context to which this page belongs.
1187
     *
1243
     *
1188
     * @param ?context $context a context object. You normally get this with context_xxxx::instance().
1244
     * @param ?context $context a context object. You normally get this with context_xxxx::instance().
1189
     */
1245
     */
1190
    public function set_context($context) {
1246
    public function set_context($context)
-
 
1247
    {
1191
        if ($context === null) {
1248
        if ($context === null) {
1192
            // Extremely ugly hack which sets context to some value in order to prevent warnings,
1249
            // Extremely ugly hack which sets context to some value in order to prevent warnings,
1193
            // use only for core error handling!!!!
1250
            // use only for core error handling!!!!
1194
            if (!$this->_context) {
1251
            if (!$this->_context) {
1195
                $this->_context = context_system::instance();
1252
                $this->_context = context_system::instance();
Línea 1199... Línea 1256...
1199
        // Ideally we should set context only once.
1256
        // Ideally we should set context only once.
1200
        if (isset($this->_context) && $context->id !== $this->_context->id) {
1257
        if (isset($this->_context) && $context->id !== $this->_context->id) {
1201
            $current = $this->_context->contextlevel;
1258
            $current = $this->_context->contextlevel;
1202
            if ($current == CONTEXT_SYSTEM or $current == CONTEXT_COURSE) {
1259
            if ($current == CONTEXT_SYSTEM or $current == CONTEXT_COURSE) {
1203
                // Hmm - not ideal, but it might produce too many warnings due to the design of require_login.
1260
                // Hmm - not ideal, but it might produce too many warnings due to the design of require_login.
-
 
1261
            } else if (
1204
            } else if ($current == CONTEXT_MODULE and ($parentcontext = $context->get_parent_context()) and
1262
                $current == CONTEXT_MODULE and ($parentcontext = $context->get_parent_context()) and
1205
                $this->_context->id == $parentcontext->id) {
1263
                $this->_context->id == $parentcontext->id
-
 
1264
            ) {
1206
                // Hmm - most probably somebody did require_login() and after that set the block context.
1265
                // Hmm - most probably somebody did require_login() and after that set the block context.
1207
            } else {
1266
            } else {
1208
                // We do not want devs to do weird switching of context levels on the fly because we might have used
1267
                // We do not want devs to do weird switching of context levels on the fly because we might have used
1209
                // the context already such as in text filter in page title.
1268
                // the context already such as in text filter in page title.
1210
                debugging("Coding problem: unsupported modification of PAGE->context from {$current} to {$context->contextlevel}");
1269
                debugging("Coding problem: unsupported modification of PAGE->context from {$current} to {$context->contextlevel}");
Línea 1221... Línea 1280...
1221
     * @param stdClass $course
1280
     * @param stdClass $course
1222
     * @param stdClass $module
1281
     * @param stdClass $module
1223
     * @return void
1282
     * @return void
1224
     * @throws coding_exception
1283
     * @throws coding_exception
1225
     */
1284
     */
1226
    public function set_cm($cm, $course = null, $module = null) {
1285
    public function set_cm($cm, $course = null, $module = null)
-
 
1286
    {
1227
        global $DB, $CFG, $SITE;
1287
        global $DB, $CFG, $SITE;
Línea 1228... Línea 1288...
1228
 
1288
 
1229
        if (!isset($cm->id) || !isset($cm->course)) {
1289
        if (!isset($cm->id) || !isset($cm->course)) {
1230
            throw new coding_exception('Invalid $cm. It has to be instance of cm_info or record from the course_modules table.');
1290
            throw new coding_exception('Invalid $cm. It has to be instance of cm_info or record from the course_modules table.');
Línea 1258... Línea 1318...
1258
            $this->set_activity_record($module);
1318
            $this->set_activity_record($module);
1259
        }
1319
        }
Línea 1260... Línea 1320...
1260
 
1320
 
1261
        // Notify course format that this page is set for the course module.
1321
        // Notify course format that this page is set for the course module.
1262
        if ($this->_course->id != $SITE->id) {
1322
        if ($this->_course->id != $SITE->id) {
1263
            require_once($CFG->dirroot.'/course/lib.php');
1323
            require_once($CFG->dirroot . '/course/lib.php');
1264
            course_get_format($this->_course)->page_set_cm($this);
1324
            course_get_format($this->_course)->page_set_cm($this);
1265
        }
1325
        }
Línea 1266... Línea 1326...
1266
    }
1326
    }
Línea 1271... Línea 1331...
1271
     * from the forum table.
1331
     * from the forum table.
1272
     *
1332
     *
1273
     * @param stdClass $module A row from the main database table for the module that this page belongs to.
1333
     * @param stdClass $module A row from the main database table for the module that this page belongs to.
1274
     * @throws coding_exception
1334
     * @throws coding_exception
1275
     */
1335
     */
1276
    public function set_activity_record($module) {
1336
    public function set_activity_record($module)
-
 
1337
    {
1277
        if (is_null($this->_cm)) {
1338
        if (is_null($this->_cm)) {
1278
            throw new coding_exception('You cannot call $PAGE->set_activity_record until after $PAGE->cm has been set.');
1339
            throw new coding_exception('You cannot call $PAGE->set_activity_record until after $PAGE->cm has been set.');
1279
        }
1340
        }
1280
        if ($module->id != $this->_cm->instance || $module->course != $this->_course->id) {
1341
        if ($module->id != $this->_cm->instance || $module->course != $this->_course->id) {
1281
            throw new coding_exception('The activity record does not seem to correspond to the cm that has been set.');
1342
            throw new coding_exception('The activity record does not seem to correspond to the cm that has been set.');
Línea 1292... Línea 1353...
1292
     * for example 'course-view-weeks'. This gets used as the id attribute on
1353
     * for example 'course-view-weeks'. This gets used as the id attribute on
1293
     * <body> and also for determining which blocks are displayed.
1354
     * <body> and also for determining which blocks are displayed.
1294
     *
1355
     *
1295
     * @param string $pagetype e.g. 'my-index' or 'mod-quiz-attempt'.
1356
     * @param string $pagetype e.g. 'my-index' or 'mod-quiz-attempt'.
1296
     */
1357
     */
1297
    public function set_pagetype($pagetype) {
1358
    public function set_pagetype($pagetype)
-
 
1359
    {
1298
        $this->_pagetype = $pagetype;
1360
        $this->_pagetype = $pagetype;
1299
    }
1361
    }
Línea 1300... Línea 1362...
1300
 
1362
 
1301
    /**
1363
    /**
Línea 1315... Línea 1377...
1315
     * The only place to find an accurate up-to-date list of the page layouts
1377
     * The only place to find an accurate up-to-date list of the page layouts
1316
     * available for your version of Moodle is {@link theme/base/config.php}
1378
     * available for your version of Moodle is {@link theme/base/config.php}
1317
     *
1379
     *
1318
     * @param string $pagelayout the page layout this is. For example 'popup', 'home'.
1380
     * @param string $pagelayout the page layout this is. For example 'popup', 'home'.
1319
     */
1381
     */
1320
    public function set_pagelayout($pagelayout) {
1382
    public function set_pagelayout($pagelayout)
-
 
1383
    {
1321
        global $SESSION;
1384
        global $SESSION;
Línea 1322... Línea 1385...
1322
 
1385
 
1323
        if (!empty($SESSION->forcepagelayout)) {
1386
        if (!empty($SESSION->forcepagelayout)) {
1324
            $this->_pagelayout = $SESSION->forcepagelayout;
1387
            $this->_pagelayout = $SESSION->forcepagelayout;
Línea 1335... Línea 1398...
1335
     * then you can set a subpage id as well. For example, the tags page sets
1398
     * then you can set a subpage id as well. For example, the tags page sets
1336
     *
1399
     *
1337
     * @param string $subpage an arbitrary identifier that, along with context->id
1400
     * @param string $subpage an arbitrary identifier that, along with context->id
1338
     *      and pagetype, uniquely identifies this page.
1401
     *      and pagetype, uniquely identifies this page.
1339
     */
1402
     */
1340
    public function set_subpage($subpage) {
1403
    public function set_subpage($subpage)
-
 
1404
    {
1341
        if (empty($subpage)) {
1405
        if (empty($subpage)) {
1342
            $this->_subpage = '';
1406
            $this->_subpage = '';
1343
        } else {
1407
        } else {
1344
            $this->_subpage = $subpage;
1408
            $this->_subpage = $subpage;
1345
        }
1409
        }
Línea 1347... Línea 1411...
1347
 
1411
 
1348
    /**
1412
    /**
1349
     * Force set secondary_nav. Useful in cases where we dealing with non course modules. e.g. blocks, tools.
1413
     * Force set secondary_nav. Useful in cases where we dealing with non course modules. e.g. blocks, tools.
1350
     * @param secondary $nav
1414
     * @param secondary $nav
1351
     */
1415
     */
-
 
1416
    public function set_secondarynav(secondary $nav)
1352
    public function set_secondarynav(secondary $nav) {
1417
    {
1353
        $this->_secondarynav = $nav;
1418
        $this->_secondarynav = $nav;
Línea 1354... Línea 1419...
1354
    }
1419
    }
1355
 
1420
 
1356
    /**
1421
    /**
1357
     * Adds a CSS class to the body tag of the page.
1422
     * Adds a CSS class to the body tag of the page.
1358
     *
1423
     *
1359
     * @param string $class add this class name ot the class attribute on the body tag.
1424
     * @param string $class add this class name ot the class attribute on the body tag.
1360
     * @throws coding_exception
1425
     * @throws coding_exception
-
 
1426
     */
1361
     */
1427
    public function add_body_class($class)
1362
    public function add_body_class($class) {
1428
    {
1363
        if ($this->_state > self::STATE_BEFORE_HEADER) {
1429
        if ($this->_state > self::STATE_BEFORE_HEADER) {
1364
            throw new coding_exception('Cannot call moodle_page::add_body_class after output has been started.');
1430
            throw new coding_exception('Cannot call moodle_page::add_body_class after output has been started.');
1365
        }
1431
        }
Línea 1369... Línea 1435...
1369
    /**
1435
    /**
1370
     * Adds an array of body classes to the body tag of this page.
1436
     * Adds an array of body classes to the body tag of this page.
1371
     *
1437
     *
1372
     * @param array $classes this utility method calls add_body_class for each array element.
1438
     * @param array $classes this utility method calls add_body_class for each array element.
1373
     */
1439
     */
1374
    public function add_body_classes($classes) {
1440
    public function add_body_classes($classes)
-
 
1441
    {
1375
        foreach ($classes as $class) {
1442
        foreach ($classes as $class) {
1376
            $this->add_body_class($class);
1443
            $this->add_body_class($class);
1377
        }
1444
        }
1378
    }
1445
    }
Línea 1396... Línea 1463...
1396
     * @param string $title the title that should go in the <head> section of the HTML of this page.
1463
     * @param string $title the title that should go in the <head> section of the HTML of this page.
1397
     * @param bool $appendsitename Appends site name at the end of the given title. It is encouraged to append the site name as this
1464
     * @param bool $appendsitename Appends site name at the end of the given title. It is encouraged to append the site name as this
1398
     *                              especially helps with accessibility. If it's necessary to override this, please keep in mind
1465
     *                              especially helps with accessibility. If it's necessary to override this, please keep in mind
1399
     *                              to ensure that the title provides a concise summary of the page being displayed.
1466
     *                              to ensure that the title provides a concise summary of the page being displayed.
1400
     */
1467
     */
1401
    public function set_title($title, bool $appendsitename = true) {
1468
    public function set_title($title, bool $appendsitename = true)
-
 
1469
    {
1402
        global $CFG;
1470
        global $CFG;
Línea 1403... Línea 1471...
1403
 
1471
 
1404
        $title = format_string($title);
1472
        $title = format_string($title);
1405
        $title = strip_tags($title);
1473
        $title = strip_tags($title);
Línea 1429... Línea 1497...
1429
     *
1497
     *
1430
     * @param string $heading the main heading that should be displayed at the top of the <body>.
1498
     * @param string $heading the main heading that should be displayed at the top of the <body>.
1431
     * @param bool $applyformatting apply format_string() - by default true.
1499
     * @param bool $applyformatting apply format_string() - by default true.
1432
     * @param bool $clean whether the heading should be cleaned or not when no formatting is applied - by default true.
1500
     * @param bool $clean whether the heading should be cleaned or not when no formatting is applied - by default true.
1433
     */
1501
     */
1434
    public function set_heading($heading, bool $applyformatting = true, bool $clean = true) {
1502
    public function set_heading($heading, bool $applyformatting = true, bool $clean = true)
-
 
1503
    {
1435
        $this->_heading = $applyformatting ? format_string($heading) : ($clean ? clean_text($heading) : $heading);
1504
        $this->_heading = $applyformatting ? format_string($heading) : ($clean ? clean_text($heading) : $heading);
1436
    }
1505
    }
Línea 1437... Línea 1506...
1437
 
1506
 
1438
    /**
1507
    /**
1439
     * Sets some HTML to use next to the heading {@link moodle_page::set_heading()}
1508
     * Sets some HTML to use next to the heading {@link moodle_page::set_heading()}
1440
     *
1509
     *
1441
     * @param string $menu The menu/content to show in the heading
1510
     * @param string $menu The menu/content to show in the heading
1442
     */
1511
     */
-
 
1512
    public function set_headingmenu($menu)
1443
    public function set_headingmenu($menu) {
1513
    {
1444
        $this->_headingmenu = $menu;
1514
        $this->_headingmenu = $menu;
Línea 1445... Línea 1515...
1445
    }
1515
    }
1446
 
1516
 
Línea 1453... Línea 1523...
1453
     * automatically sets the page context to the category context.
1523
     * automatically sets the page context to the category context.
1454
     *
1524
     *
1455
     * @param int $categoryid The id of the category to set.
1525
     * @param int $categoryid The id of the category to set.
1456
     * @throws coding_exception
1526
     * @throws coding_exception
1457
     */
1527
     */
1458
    public function set_category_by_id($categoryid) {
1528
    public function set_category_by_id($categoryid)
-
 
1529
    {
1459
        global $SITE;
1530
        global $SITE;
1460
        if (!is_null($this->_course)) {
1531
        if (!is_null($this->_course)) {
1461
            throw new coding_exception('Course has already been set. You cannot change the category now.');
1532
            throw new coding_exception('Course has already been set. You cannot change the category now.');
1462
        }
1533
        }
1463
        if (is_array($this->_categories)) {
1534
        if (is_array($this->_categories)) {
Línea 1476... Línea 1547...
1476
     * script name. So, for example, for mod/quiz/attempt.php, pagetype is
1547
     * script name. So, for example, for mod/quiz/attempt.php, pagetype is
1477
     * mod-quiz-attempt, and so docspath is mod/quiz/attempt.
1548
     * mod-quiz-attempt, and so docspath is mod/quiz/attempt.
1478
     *
1549
     *
1479
     * @param string $path the path to use at the end of the moodle docs URL.
1550
     * @param string $path the path to use at the end of the moodle docs URL.
1480
     */
1551
     */
1481
    public function set_docs_path($path) {
1552
    public function set_docs_path($path)
-
 
1553
    {
1482
        $this->_docspath = $path;
1554
        $this->_docspath = $path;
1483
    }
1555
    }
Línea 1484... Línea 1556...
1484
 
1556
 
1485
    /**
1557
    /**
Línea 1493... Línea 1565...
1493
     *
1565
     *
1494
     * @param moodle_url|string $url URL relative to $CFG->wwwroot or {@link moodle_url} instance
1566
     * @param moodle_url|string $url URL relative to $CFG->wwwroot or {@link moodle_url} instance
1495
     * @param array $params parameters to add to the URL
1567
     * @param array $params parameters to add to the URL
1496
     * @throws coding_exception
1568
     * @throws coding_exception
1497
     */
1569
     */
1498
    public function set_url($url, ?array $params = null) {
1570
    public function set_url($url, ?array $params = null)
-
 
1571
    {
1499
        global $CFG;
1572
        global $CFG;
Línea 1500... Línea 1573...
1500
 
1573
 
1501
        if (is_string($url) && strpos($url, 'http') !== 0) {
1574
        if (is_string($url) && strpos($url, 'http') !== 0) {
1502
            if (strpos($url, '/') === 0) {
1575
            if (strpos($url, '/') === 0) {
Línea 1530... Línea 1603...
1530
     * before doing any redirect.
1603
     * before doing any redirect.
1531
     *
1604
     *
1532
     * @param string $param the name of the parameter to make sure is not in the
1605
     * @param string $param the name of the parameter to make sure is not in the
1533
     * page URL.
1606
     * page URL.
1534
     */
1607
     */
1535
    public function ensure_param_not_in_url($param) {
1608
    public function ensure_param_not_in_url($param)
-
 
1609
    {
1536
        $this->_url->remove_params($param);
1610
        $this->_url->remove_params($param);
1537
    }
1611
    }
Línea 1538... Línea 1612...
1538
 
1612
 
1539
    /**
1613
    /**
Línea 1546... Línea 1620...
1546
     * @param string $title The title to give the alternate version.
1620
     * @param string $title The title to give the alternate version.
1547
     * @param string|moodle_url $url The URL of the alternate version.
1621
     * @param string|moodle_url $url The URL of the alternate version.
1548
     * @param string $mimetype The mime-type of the alternate version.
1622
     * @param string $mimetype The mime-type of the alternate version.
1549
     * @throws coding_exception
1623
     * @throws coding_exception
1550
     */
1624
     */
1551
    public function add_alternate_version($title, $url, $mimetype) {
1625
    public function add_alternate_version($title, $url, $mimetype)
-
 
1626
    {
1552
        if ($this->_state > self::STATE_BEFORE_HEADER) {
1627
        if ($this->_state > self::STATE_BEFORE_HEADER) {
1553
            throw new coding_exception('Cannot call moodle_page::add_alternate_version after output has been started.');
1628
            throw new coding_exception('Cannot call moodle_page::add_alternate_version after output has been started.');
1554
        }
1629
        }
1555
        $alt = new stdClass;
1630
        $alt = new stdClass;
1556
        $alt->title = $title;
1631
        $alt->title = $title;
Línea 1561... Línea 1636...
1561
    /**
1636
    /**
1562
     * Specify a form control should be focused when the page has loaded.
1637
     * Specify a form control should be focused when the page has loaded.
1563
     *
1638
     *
1564
     * @param string $controlid the id of the HTML element to be focused.
1639
     * @param string $controlid the id of the HTML element to be focused.
1565
     */
1640
     */
1566
    public function set_focuscontrol($controlid) {
1641
    public function set_focuscontrol($controlid)
-
 
1642
    {
1567
        $this->_focuscontrol = $controlid;
1643
        $this->_focuscontrol = $controlid;
1568
    }
1644
    }
Línea 1569... Línea 1645...
1569
 
1645
 
1570
    /**
1646
    /**
1571
     * Specify a fragment of HTML that goes where the 'Turn editing on' button normally goes.
1647
     * Specify a fragment of HTML that goes where the 'Turn editing on' button normally goes.
1572
     *
1648
     *
1573
     * @param string $html the HTML to display there.
1649
     * @param string $html the HTML to display there.
1574
     */
1650
     */
-
 
1651
    public function set_button($html)
1575
    public function set_button($html) {
1652
    {
1576
        $this->_button = $html;
1653
        $this->_button = $html;
Línea 1577... Línea 1654...
1577
    }
1654
    }
1578
 
1655
 
Línea 1583... Línea 1660...
1583
     * pages like the My Moodle page need to use a different capability
1660
     * pages like the My Moodle page need to use a different capability
1584
     * like 'moodle/my:manageblocks'.
1661
     * like 'moodle/my:manageblocks'.
1585
     *
1662
     *
1586
     * @param string $capability a capability.
1663
     * @param string $capability a capability.
1587
     */
1664
     */
1588
    public function set_blocks_editing_capability($capability) {
1665
    public function set_blocks_editing_capability($capability)
-
 
1666
    {
1589
        $this->_blockseditingcap = $capability;
1667
        $this->_blockseditingcap = $capability;
1590
    }
1668
    }
Línea 1591... Línea 1669...
1591
 
1669
 
1592
    /**
1670
    /**
1593
     * Some pages let you turn editing on for reasons other than editing blocks.
1671
     * Some pages let you turn editing on for reasons other than editing blocks.
1594
     * If that is the case, you can pass other capabilities that let the user
1672
     * If that is the case, you can pass other capabilities that let the user
1595
     * edit this page here.
1673
     * edit this page here.
1596
     *
1674
     *
1597
     * @param string|array $capability either a capability, or an array of capabilities.
1675
     * @param string|array $capability either a capability, or an array of capabilities.
1598
     */
1676
     */
-
 
1677
    public function set_other_editing_capability($capability)
1599
    public function set_other_editing_capability($capability) {
1678
    {
1600
        if (is_array($capability)) {
1679
        if (is_array($capability)) {
1601
            $this->_othereditingcaps = array_unique($this->_othereditingcaps + $capability);
1680
            $this->_othereditingcaps = array_unique($this->_othereditingcaps + $capability);
1602
        } else {
1681
        } else {
1603
            $this->_othereditingcaps[] = $capability;
1682
            $this->_othereditingcaps[] = $capability;
Línea 1607... Línea 1686...
1607
    /**
1686
    /**
1608
     * Sets whether the browser should cache this page or not.
1687
     * Sets whether the browser should cache this page or not.
1609
     *
1688
     *
1610
     * @param bool $cacheable can this page be cached by the user's browser.
1689
     * @param bool $cacheable can this page be cached by the user's browser.
1611
     */
1690
     */
1612
    public function set_cacheable($cacheable) {
1691
    public function set_cacheable($cacheable)
-
 
1692
    {
1613
        $this->_cacheable = $cacheable;
1693
        $this->_cacheable = $cacheable;
1614
    }
1694
    }
Línea 1615... Línea 1695...
1615
 
1695
 
1616
    /**
1696
    /**
Línea 1620... Línea 1700...
1620
     * a coding exception will be thrown.
1700
     * a coding exception will be thrown.
1621
     *
1701
     *
1622
     * @param int $delay Sets the delay before refreshing the page, if set to null refresh is cancelled.
1702
     * @param int $delay Sets the delay before refreshing the page, if set to null refresh is cancelled.
1623
     * @throws coding_exception
1703
     * @throws coding_exception
1624
     */
1704
     */
1625
    public function set_periodic_refresh_delay($delay = null) {
1705
    public function set_periodic_refresh_delay($delay = null)
-
 
1706
    {
1626
        if ($this->_state > self::STATE_BEFORE_HEADER) {
1707
        if ($this->_state > self::STATE_BEFORE_HEADER) {
1627
            throw new coding_exception('You cannot set a periodic refresh delay after the header has been printed');
1708
            throw new coding_exception('You cannot set a periodic refresh delay after the header has been printed');
1628
        }
1709
        }
1629
        if ($delay === null) {
1710
        if ($delay === null) {
1630
            $this->_periodicrefreshdelay = null;
1711
            $this->_periodicrefreshdelay = null;
Línea 1639... Línea 1720...
1639
     * Please use this cautiously.
1720
     * Please use this cautiously.
1640
     * It is only intended to be used by the themes selector admin page.
1721
     * It is only intended to be used by the themes selector admin page.
1641
     *
1722
     *
1642
     * @param string $themename the name of the theme to use.
1723
     * @param string $themename the name of the theme to use.
1643
     */
1724
     */
1644
    public function force_theme($themename) {
1725
    public function force_theme($themename)
-
 
1726
    {
1645
        $this->ensure_theme_not_set();
1727
        $this->ensure_theme_not_set();
1646
        $this->_theme = theme_config::load($themename);
1728
        $this->_theme = theme_config::load($themename);
1647
    }
1729
    }
Línea 1648... Línea 1730...
1648
 
1730
 
1649
    /**
1731
    /**
1650
     * Reload theme settings.
1732
     * Reload theme settings.
1651
     *
1733
     *
1652
     * This is used when we need to reset settings
1734
     * This is used when we need to reset settings
1653
     * because they are now double cached in theme.
1735
     * because they are now double cached in theme.
1654
     */
1736
     */
-
 
1737
    public function reload_theme()
1655
    public function reload_theme() {
1738
    {
1656
        if (!is_null($this->_theme)) {
1739
        if (!is_null($this->_theme)) {
1657
            $this->_theme = theme_config::load($this->_theme->name);
1740
            $this->_theme = theme_config::load($this->_theme->name);
1658
        }
1741
        }
Línea 1663... Línea 1746...
1663
     * This overrides any capabilities and is intended only for pages where no user (including admins) should be able to
1746
     * This overrides any capabilities and is intended only for pages where no user (including admins) should be able to
1664
     * modify blocks on the page (eg My Courses).
1747
     * modify blocks on the page (eg My Courses).
1665
     *
1748
     *
1666
     * @return void
1749
     * @return void
1667
     */
1750
     */
1668
    public function force_lock_all_blocks(): void {
1751
    public function force_lock_all_blocks(): void
-
 
1752
    {
1669
        $this->_forcelockallblocks = true;
1753
        $this->_forcelockallblocks = true;
1670
    }
1754
    }
Línea 1671... Línea 1755...
1671
 
1755
 
1672
    /**
1756
    /**
Línea 1681... Línea 1765...
1681
     * as an argument to web services in AJAX requests and retrieve all data associated with
1765
     * as an argument to web services in AJAX requests and retrieve all data associated with
1682
     * the page without actually executing PHP code on that page.
1766
     * the page without actually executing PHP code on that page.
1683
     *
1767
     *
1684
     * @return string|null
1768
     * @return string|null
1685
     */
1769
     */
1686
    public function get_edited_page_hash(): ?string {
1770
    public function get_edited_page_hash(): ?string
-
 
1771
    {
1687
        global $SESSION;
1772
        global $SESSION;
1688
        if (!$this->user_is_editing()) {
1773
        if (!$this->user_is_editing()) {
1689
            return null;
1774
            return null;
1690
        }
1775
        }
1691
        
1776
 
1692
        // Check if session is still active to prevent mutation after close
1777
        // Check if session is still active to prevent mutation after close
-
 
1778
        // If we're in shutdown phase or session was already closed, don't modify session
-
 
1779
        if (
-
 
1780
            defined('ABORT_AFTER_CONFIG') || !session_id() || session_status() !== PHP_SESSION_ACTIVE ||
1693
        if (!\core\session\manager::session_exists(session_id()) || !\core\session\manager::is_session_active()) {
1781
            !\core\session\manager::is_session_active()
-
 
1782
        ) {
1694
            return null;
1783
            return null;
1695
        }
1784
        }
1696
        
1785
 
1697
        $url = new moodle_url($this->url);
1786
        $url = new moodle_url($this->url);
1698
        $url->set_anchor(null);
1787
        $url->set_anchor(null);
1699
        $data = [
1788
        $data = [
1700
            'contextid' => $this->context->id,
1789
            'contextid' => $this->context->id,
1701
            'url' => $url->out_as_local_url(false),
1790
            'url' => $url->out_as_local_url(false),
Línea 1733... Línea 1822...
1733
     *
1822
     *
1734
     * @param string $hash
1823
     * @param string $hash
1735
     * @param int $strictness
1824
     * @param int $strictness
1736
     * @return self|null
1825
     * @return self|null
1737
     */
1826
     */
1738
    public static function retrieve_edited_page(string $hash, $strictness = IGNORE_MISSING): ?self {
1827
    public static function retrieve_edited_page(string $hash, $strictness = IGNORE_MISSING): ?self
-
 
1828
    {
1739
        global $CFG, $SESSION;
1829
        global $CFG, $SESSION;
1740
        $data = $SESSION->editedpages[$hash] ?? null;
1830
        $data = $SESSION->editedpages[$hash] ?? null;
-
 
1831
        if (
1741
        if (!$data || !is_array($data)
1832
            !$data || !is_array($data)
1742
                || $hash !== md5(json_encode($data + ['sesskey' => sesskey()]))) {
1833
            || $hash !== md5(json_encode($data + ['sesskey' => sesskey()]))
-
 
1834
        ) {
1743
            // This can happen if the session cache becomes corrupt or the user logged out and back
1835
            // This can happen if the session cache becomes corrupt or the user logged out and back
1744
            // in in another window and changed their session. Refreshing the page will generate
1836
            // in in another window and changed their session. Refreshing the page will generate
1745
            // and store the correct page hash.
1837
            // and store the correct page hash.
1746
            if ($strictness === MUST_EXIST) {
1838
            if ($strictness === MUST_EXIST) {
1747
                throw new moodle_exception('editedpagenotfound');
1839
                throw new moodle_exception('editedpagenotfound');
Línea 1794... Línea 1886...
1794
 
1886
 
1795
    /**
1887
    /**
1796
     * This method is called when the page first moves out of the STATE_BEFORE_HEADER
1888
     * This method is called when the page first moves out of the STATE_BEFORE_HEADER
1797
     * state. This is our last change to initialise things.
1889
     * state. This is our last change to initialise things.
1798
     */
1890
     */
-
 
1891
    protected function starting_output()
1799
    protected function starting_output() {
1892
    {
Línea 1800... Línea 1893...
1800
        global $CFG;
1893
        global $CFG;
1801
 
1894
 
1802
        if (!during_initial_install()) {
1895
        if (!during_initial_install()) {
Línea 1811... Línea 1904...
1811
        }
1904
        }
Línea 1812... Línea 1905...
1812
 
1905
 
1813
        // If maintenance mode is on, change the page header.
1906
        // If maintenance mode is on, change the page header.
1814
        if (!empty($CFG->maintenance_enabled)) {
1907
        if (!empty($CFG->maintenance_enabled)) {
1815
            $this->set_button('<a href="' . $CFG->wwwroot . '/' . $CFG->admin .
1908
            $this->set_button('<a href="' . $CFG->wwwroot . '/' . $CFG->admin .
1816
                    '/settings.php?section=maintenancemode">' . get_string('maintenancemode', 'admin') .
1909
                '/settings.php?section=maintenancemode">' . get_string('maintenancemode', 'admin') .
Línea 1817... Línea 1910...
1817
                    '</a> ' . $this->button);
1910
                '</a> ' . $this->button);
1818
 
1911
 
Línea 1819... Línea 1912...
1819
            $this->set_title(get_string('maintenancemode', 'admin'));
1912
            $this->set_title(get_string('maintenancemode', 'admin'));
Línea 1830... Línea 1923...
1830
     * blocks_manager about the theme block regions, and then, if
1923
     * blocks_manager about the theme block regions, and then, if
1831
     * we are $PAGE, set up the global $OUTPUT.
1924
     * we are $PAGE, set up the global $OUTPUT.
1832
     *
1925
     *
1833
     * @return void
1926
     * @return void
1834
     */
1927
     */
1835
    public function initialise_theme_and_output() {
1928
    public function initialise_theme_and_output()
-
 
1929
    {
1836
        global $OUTPUT, $PAGE, $SITE, $CFG;
1930
        global $OUTPUT, $PAGE, $SITE, $CFG;
Línea 1837... Línea 1931...
1837
 
1931
 
1838
        if (!empty($this->_wherethemewasinitialised)) {
1932
        if (!empty($this->_wherethemewasinitialised)) {
1839
            return;
1933
            return;
Línea 1877... Línea 1971...
1877
    /**
1971
    /**
1878
     * For diagnostic/debugging purposes, find where the theme setup was triggered.
1972
     * For diagnostic/debugging purposes, find where the theme setup was triggered.
1879
     *
1973
     *
1880
     * @return null|array null if theme not yet setup. Stacktrace if it was.
1974
     * @return null|array null if theme not yet setup. Stacktrace if it was.
1881
     */
1975
     */
1882
    public function get_where_theme_was_initialised() {
1976
    public function get_where_theme_was_initialised()
-
 
1977
    {
1883
        return $this->_wherethemewasinitialised;
1978
        return $this->_wherethemewasinitialised;
1884
    }
1979
    }
Línea 1885... Línea 1980...
1885
 
1980
 
1886
    /**
1981
    /**
1887
     * Reset the theme and output for a new context. This only makes sense from
1982
     * Reset the theme and output for a new context. This only makes sense from
1888
     * external::validate_context(). Do not cheat.
1983
     * external::validate_context(). Do not cheat.
1889
     */
1984
     */
-
 
1985
    public function reset_theme_and_output()
1890
    public function reset_theme_and_output() {
1986
    {
Línea 1891... Línea 1987...
1891
        global $COURSE, $SITE;
1987
        global $COURSE, $SITE;
1892
 
1988
 
1893
        $COURSE = clone($SITE);
1989
        $COURSE = clone ($SITE);
1894
        $this->_theme = null;
1990
        $this->_theme = null;
1895
        $this->_wherethemewasinitialised = null;
1991
        $this->_wherethemewasinitialised = null;
1896
        $this->_course = null;
1992
        $this->_course = null;
Línea 1904... Línea 2000...
1904
     *
2000
     *
1905
     * This depends on numerous $CFG settings, and the properties of this page.
2001
     * This depends on numerous $CFG settings, and the properties of this page.
1906
     *
2002
     *
1907
     * @return string the name of the theme that should be used on this page.
2003
     * @return string the name of the theme that should be used on this page.
1908
     */
2004
     */
1909
    protected function resolve_theme() {
2005
    protected function resolve_theme()
-
 
2006
    {
1910
        global $CFG, $USER, $SESSION;
2007
        global $CFG, $USER, $SESSION;
Línea 1911... Línea 2008...
1911
 
2008
 
1912
        if (empty($CFG->themeorder)) {
2009
        if (empty($CFG->themeorder)) {
1913
            $themeorder = array('course', 'category', 'session', 'user', 'cohort', 'site');
2010
            $themeorder = array('course', 'category', 'session', 'user', 'cohort', 'site');
Línea 1918... Línea 2015...
1918
        }
2015
        }
Línea 1919... Línea 2016...
1919
 
2016
 
1920
        $mnetpeertheme = '';
2017
        $mnetpeertheme = '';
1921
        $mnetvarsok = isset($CFG->mnet_localhost_id) && isset($USER->mnethostid);
2018
        $mnetvarsok = isset($CFG->mnet_localhost_id) && isset($USER->mnethostid);
1922
        if (isloggedin() and $mnetvarsok and $USER->mnethostid != $CFG->mnet_localhost_id) {
2019
        if (isloggedin() and $mnetvarsok and $USER->mnethostid != $CFG->mnet_localhost_id) {
1923
            require_once($CFG->dirroot.'/mnet/peer.php');
2020
            require_once($CFG->dirroot . '/mnet/peer.php');
1924
            $mnetpeer = new mnet_peer();
2021
            $mnetpeer = new mnet_peer();
1925
            $mnetpeer->set_id($USER->mnethostid);
2022
            $mnetpeer->set_id($USER->mnethostid);
1926
            if ($mnetpeer->force_theme == 1 && $mnetpeer->theme != '') {
2023
            if ($mnetpeer->force_theme == 1 && $mnetpeer->theme != '') {
1927
                $mnetpeertheme = $mnetpeer->theme;
2024
                $mnetpeertheme = $mnetpeer->theme;
Línea 1933... Línea 2030...
1933
            switch ($themetype) {
2030
            switch ($themetype) {
1934
                case 'course':
2031
                case 'course':
1935
                    if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme)) {
2032
                    if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme)) {
1936
                        return $this->_course->theme;
2033
                        return $this->_course->theme;
1937
                    }
2034
                    }
1938
                break;
2035
                    break;
Línea 1939... Línea 2036...
1939
 
2036
 
1940
                case 'category':
2037
                case 'category':
1941
                    if (!empty($CFG->allowcategorythemes) && !empty($this->_course)) {
2038
                    if (!empty($CFG->allowcategorythemes) && !empty($this->_course)) {
1942
                        $categories = $this->categories;
2039
                        $categories = $this->categories;
1943
                        foreach ($categories as $category) {
2040
                        foreach ($categories as $category) {
1944
                            if (!empty($category->theme)) {
2041
                            if (!empty($category->theme)) {
1945
                                return $category->theme;
2042
                                return $category->theme;
1946
                            }
2043
                            }
1947
                        }
2044
                        }
1948
                    }
2045
                    }
Línea 1949... Línea 2046...
1949
                break;
2046
                    break;
1950
 
2047
 
1951
                case 'session':
2048
                case 'session':
1952
                    if (!empty($SESSION->theme)) {
2049
                    if (!empty($SESSION->theme)) {
1953
                        return $SESSION->theme;
2050
                        return $SESSION->theme;
Línea 1954... Línea 2051...
1954
                    }
2051
                    }
1955
                break;
2052
                    break;
1956
 
2053
 
1957
                case 'user':
2054
                case 'user':
1958
                    if (!empty($CFG->allowuserthemes) && !empty($USER->theme)) {
2055
                    if (!empty($CFG->allowuserthemes) && !empty($USER->theme)) {
1959
                        if ($mnetpeertheme) {
2056
                        if ($mnetpeertheme) {
1960
                            return $mnetpeertheme;
2057
                            return $mnetpeertheme;
1961
                        } else {
2058
                        } else {
1962
                            return $USER->theme;
2059
                            return $USER->theme;
Línea 1963... Línea 2060...
1963
                        }
2060
                        }
1964
                    }
2061
                    }
1965
                break;
2062
                    break;
1966
 
2063
 
1967
                case 'cohort':
2064
                case 'cohort':
Línea 1968... Línea 2065...
1968
                    if (!empty($CFG->allowcohortthemes) && !empty($USER->cohorttheme)) {
2065
                    if (!empty($CFG->allowcohortthemes) && !empty($USER->cohorttheme)) {
1969
                        return $USER->cohorttheme;
2066
                        return $USER->cohorttheme;
1970
                    }
2067
                    }
1971
                break;
2068
                    break;
Línea 1997... Línea 2094...
1997
     * @param string $script the path to the script that should be used to
2094
     * @param string $script the path to the script that should be used to
1998
     * initialise ->pagetype. If not passed the $SCRIPT global will be used.
2095
     * initialise ->pagetype. If not passed the $SCRIPT global will be used.
1999
     * If legacy code has set $CFG->pagepath that will be used instead, and a
2096
     * If legacy code has set $CFG->pagepath that will be used instead, and a
2000
     * developer warning issued.
2097
     * developer warning issued.
2001
     */
2098
     */
2002
    protected function initialise_default_pagetype($script = null) {
2099
    protected function initialise_default_pagetype($script = null)
-
 
2100
    {
2003
        global $CFG, $SCRIPT;
2101
        global $CFG, $SCRIPT;
Línea 2004... Línea 2102...
2004
 
2102
 
2005
        if (isset($CFG->pagepath)) {
2103
        if (isset($CFG->pagepath)) {
2006
            debugging('Some code appears to have set $CFG->pagepath. That was a horrible deprecated thing. ' .
2104
            debugging('Some code appears to have set $CFG->pagepath. That was a horrible deprecated thing. ' .
2007
                    'Don\'t do it! Try calling $PAGE->set_pagetype() instead.');
2105
                'Don\'t do it! Try calling $PAGE->set_pagetype() instead.');
2008
            $script = $CFG->pagepath;
2106
            $script = $CFG->pagepath;
2009
            unset($CFG->pagepath);
2107
            unset($CFG->pagepath);
Línea 2010... Línea 2108...
2010
        }
2108
        }
Línea 2039... Línea 2137...
2039
     *    - Language direction
2137
     *    - Language direction
2040
     *    - YUI CSS initialisation
2138
     *    - YUI CSS initialisation
2041
     *    - Pagelayout
2139
     *    - Pagelayout
2042
     * These are commonly used in CSS to target specific types of pages.
2140
     * These are commonly used in CSS to target specific types of pages.
2043
     */
2141
     */
2044
    protected function initialise_standard_body_classes() {
2142
    protected function initialise_standard_body_classes()
-
 
2143
    {
2045
        global $CFG, $USER;
2144
        global $CFG, $USER;
Línea 2046... Línea 2145...
2046
 
2145
 
2047
        $pagetype = $this->pagetype;
2146
        $pagetype = $this->pagetype;
2048
        if ($pagetype == 'site-index') {
2147
        if ($pagetype == 'site-index') {
Línea 2131... Línea 2230...
2131
     * This will load {@link moodle_page::$_module} with a row from the related
2230
     * This will load {@link moodle_page::$_module} with a row from the related
2132
     * module table in the database.
2231
     * module table in the database.
2133
     * For instance if {@link moodle_page::$_cm} is a forum then a row from the
2232
     * For instance if {@link moodle_page::$_cm} is a forum then a row from the
2134
     * forum table will be loaded.
2233
     * forum table will be loaded.
2135
     */
2234
     */
2136
    protected function load_activity_record() {
2235
    protected function load_activity_record()
-
 
2236
    {
2137
        global $DB;
2237
        global $DB;
2138
        if (is_null($this->_cm)) {
2238
        if (is_null($this->_cm)) {
2139
            return;
2239
            return;
2140
        }
2240
        }
2141
        $this->_module = $DB->get_record($this->_cm->modname, array('id' => $this->_cm->instance));
2241
        $this->_module = $DB->get_record($this->_cm->modname, array('id' => $this->_cm->instance));
Línea 2146... Línea 2246...
2146
     * loaded, and if not, the function loads it now.
2246
     * loaded, and if not, the function loads it now.
2147
     *
2247
     *
2148
     * @return void
2248
     * @return void
2149
     * @throws coding_exception
2249
     * @throws coding_exception
2150
     */
2250
     */
2151
    protected function ensure_category_loaded() {
2251
    protected function ensure_category_loaded()
-
 
2252
    {
2152
        if (is_array($this->_categories)) {
2253
        if (is_array($this->_categories)) {
2153
            return; // Already done.
2254
            return; // Already done.
2154
        }
2255
        }
2155
        if (is_null($this->_course)) {
2256
        if (is_null($this->_course)) {
2156
            throw new coding_exception('Attempt to get the course category for this page before the course was set.');
2257
            throw new coding_exception('Attempt to get the course category for this page before the course was set.');
Línea 2166... Línea 2267...
2166
     * Loads the requested category into the pages categories array.
2267
     * Loads the requested category into the pages categories array.
2167
     *
2268
     *
2168
     * @param int $categoryid
2269
     * @param int $categoryid
2169
     * @throws moodle_exception
2270
     * @throws moodle_exception
2170
     */
2271
     */
2171
    protected function load_category($categoryid) {
2272
    protected function load_category($categoryid)
-
 
2273
    {
2172
        global $DB;
2274
        global $DB;
2173
        $category = $DB->get_record('course_categories', array('id' => $categoryid));
2275
        $category = $DB->get_record('course_categories', array('id' => $categoryid));
2174
        if (!$category) {
2276
        if (!$category) {
2175
            throw new moodle_exception('unknowncategory', a: $categoryid);
2277
            throw new moodle_exception('unknowncategory', a: $categoryid);
2176
        }
2278
        }
Línea 2186... Línea 2288...
2186
     * Ensures that the category the current course is within, as well as all of
2288
     * Ensures that the category the current course is within, as well as all of
2187
     * its parent categories, have been loaded.
2289
     * its parent categories, have been loaded.
2188
     *
2290
     *
2189
     * @return void
2291
     * @return void
2190
     */
2292
     */
2191
    protected function ensure_categories_loaded() {
2293
    protected function ensure_categories_loaded()
-
 
2294
    {
2192
        global $DB;
2295
        global $DB;
2193
        $this->ensure_category_loaded();
2296
        $this->ensure_category_loaded();
2194
        if (!is_null(end($this->_categories))) {
2297
        if (!is_null(end($this->_categories))) {
2195
            return; // Already done.
2298
            return; // Already done.
2196
        }
2299
        }
Línea 2205... Línea 2308...
2205
    /**
2308
    /**
2206
     * Ensure the theme has not been loaded yet. If it has an exception is thrown.
2309
     * Ensure the theme has not been loaded yet. If it has an exception is thrown.
2207
     *
2310
     *
2208
     * @throws coding_exception
2311
     * @throws coding_exception
2209
     */
2312
     */
2210
    protected function ensure_theme_not_set() {
2313
    protected function ensure_theme_not_set()
-
 
2314
    {
2211
        // This is explicitly allowed for webservices though which may process many course contexts in a single request.
2315
        // This is explicitly allowed for webservices though which may process many course contexts in a single request.
2212
        if (WS_SERVER) {
2316
        if (WS_SERVER) {
2213
            return;
2317
            return;
2214
        }
2318
        }
Línea 2215... Línea 2319...
2215
 
2319
 
-
 
2320
        if (!is_null($this->_theme)) {
2216
        if (!is_null($this->_theme)) {
2321
            throw new coding_exception(
2217
            throw new coding_exception('The theme has already been set up for this page ready for output. ' .
2322
                'The theme has already been set up for this page ready for output. ' .
2218
                    'Therefore, you can no longer change the theme, or anything that might affect what ' .
2323
                    'Therefore, you can no longer change the theme, or anything that might affect what ' .
2219
                    'the current theme is, for example, the course.',
2324
                    'the current theme is, for example, the course.',
-
 
2325
                'Stack trace when the theme was set up: ' . format_backtrace($this->_wherethemewasinitialised)
2220
                    'Stack trace when the theme was set up: ' . format_backtrace($this->_wherethemewasinitialised));
2326
            );
2221
        }
2327
        }
Línea 2222... Línea 2328...
2222
    }
2328
    }
2223
 
2329
 
2224
    /**
2330
    /**
2225
     * Converts the provided URL into a CSS class that be used within the page.
2331
     * Converts the provided URL into a CSS class that be used within the page.
2226
     * This is primarily used to add the wwwroot to the body tag as a CSS class.
2332
     * This is primarily used to add the wwwroot to the body tag as a CSS class.
2227
     *
2333
     *
2228
     * @param string $url
2334
     * @param string $url
2229
     * @return string
2335
     * @return string
-
 
2336
     */
2230
     */
2337
    protected function url_to_class_name($url)
2231
    protected function url_to_class_name($url) {
2338
    {
2232
        $bits = parse_url($url);
2339
        $bits = parse_url($url);
2233
        $class = str_replace('.', '-', $bits['host']);
2340
        $class = str_replace('.', '-', $bits['host']);
2234
        if (!empty($bits['port'])) {
2341
        if (!empty($bits['port'])) {
Línea 2247... Línea 2354...
2247
     * Combines all of the required editing caps for the page and returns them
2354
     * Combines all of the required editing caps for the page and returns them
2248
     * as an array.
2355
     * as an array.
2249
     *
2356
     *
2250
     * @return array
2357
     * @return array
2251
     */
2358
     */
2252
    protected function all_editing_caps() {
2359
    protected function all_editing_caps()
-
 
2360
    {
2253
        $caps = $this->_othereditingcaps;
2361
        $caps = $this->_othereditingcaps;
2254
        $caps[] = $this->_blockseditingcap;
2362
        $caps[] = $this->_blockseditingcap;
2255
        return $caps;
2363
        return $caps;
2256
    }
2364
    }
Línea 2257... Línea 2365...
2257
 
2365
 
2258
    /**
2366
    /**
2259
     * Returns true if the page URL has beem set.
2367
     * Returns true if the page URL has beem set.
2260
     *
2368
     *
2261
     * @return bool
2369
     * @return bool
2262
     */
2370
     */
-
 
2371
    public function has_set_url()
2263
    public function has_set_url() {
2372
    {
2264
        return ($this->_url!==null);
2373
        return ($this->_url !== null);
Línea 2265... Línea 2374...
2265
    }
2374
    }
2266
 
2375
 
2267
    /**
2376
    /**
2268
     * Gets set when the block actions for the page have been processed.
2377
     * Gets set when the block actions for the page have been processed.
2269
     *
2378
     *
2270
     * @param bool $setting
2379
     * @param bool $setting
-
 
2380
     */
2271
     */
2381
    public function set_block_actions_done($setting = true)
2272
    public function set_block_actions_done($setting = true) {
2382
    {
Línea 2273... Línea 2383...
2273
        $this->_block_actions_done = $setting;
2383
        $this->_block_actions_done = $setting;
2274
    }
2384
    }
2275
 
2385
 
2276
    /**
2386
    /**
2277
     * Are popup notifications allowed on this page?
2387
     * Are popup notifications allowed on this page?
2278
     * Popup notifications may be disallowed in situations such as while upgrading or completing a quiz
2388
     * Popup notifications may be disallowed in situations such as while upgrading or completing a quiz
2279
     *
2389
     *
-
 
2390
     * @return bool true if popup notifications may be displayed
2280
     * @return bool true if popup notifications may be displayed
2391
     */
2281
     */
2392
    public function get_popup_notification_allowed()
Línea 2282... Línea 2393...
2282
    public function get_popup_notification_allowed() {
2393
    {
2283
        return $this->_popup_notification_allowed;
2394
        return $this->_popup_notification_allowed;
2284
    }
2395
    }
2285
 
2396
 
2286
    /**
2397
    /**
2287
     * Allow or disallow popup notifications on this page. Popups are allowed by default.
2398
     * Allow or disallow popup notifications on this page. Popups are allowed by default.
-
 
2399
     *
2288
     *
2400
     * @param bool $allowed true if notifications are allowed. False if not allowed. They are allowed by default.
2289
     * @param bool $allowed true if notifications are allowed. False if not allowed. They are allowed by default.
2401
     */
Línea 2290... Línea 2402...
2290
     */
2402
    public function set_popup_notification_allowed($allowed)
2291
    public function set_popup_notification_allowed($allowed) {
2403
    {
2292
        $this->_popup_notification_allowed = $allowed;
2404
        $this->_popup_notification_allowed = $allowed;
2293
    }
2405
    }
2294
 
2406
 
2295
    /**
2407
    /**
2296
     * Returns the block region having made any required theme manipulations.
2408
     * Returns the block region having made any required theme manipulations.
2297
     *
2409
     *
-
 
2410
     * @since Moodle 2.5.1 2.6
2298
     * @since Moodle 2.5.1 2.6
2411
     * @param string $region
2299
     * @param string $region
2412
     * @return string
2300
     * @return string
2413
     */
2301
     */
2414
    public function apply_theme_region_manipulations($region)
2302
    public function apply_theme_region_manipulations($region) {
2415
    {
Línea 2317... Línea 2430...
2317
     * Add a report node and a specific report to the navigation.
2430
     * Add a report node and a specific report to the navigation.
2318
     *
2431
     *
2319
     * @param int $userid The user ID that we are looking to add this report node to.
2432
     * @param int $userid The user ID that we are looking to add this report node to.
2320
     * @param array $nodeinfo Name and url of the final node that we are creating.
2433
     * @param array $nodeinfo Name and url of the final node that we are creating.
2321
     */
2434
     */
2322
    public function add_report_nodes($userid, $nodeinfo) {
2435
    public function add_report_nodes($userid, $nodeinfo)
-
 
2436
    {
2323
        global $USER;
2437
        global $USER;
2324
        // Try to find the specific user node.
2438
        // Try to find the specific user node.
2325
        $newusernode = $this->navigation->find('user' . $userid, null);
2439
        $newusernode = $this->navigation->find('user' . $userid, null);
2326
        $reportnode = null;
2440
        $reportnode = null;
2327
        $navigationnodeerror =
2441
        $navigationnodeerror =
2328
                'Could not find the navigation node requested. Please check that the node you are looking for exists.';
2442
            'Could not find the navigation node requested. Please check that the node you are looking for exists.';
2329
        if ($userid != $USER->id  || $this->context->contextlevel == CONTEXT_COURSE) {
2443
        if ($userid != $USER->id  || $this->context->contextlevel == CONTEXT_COURSE) {
2330
            // Within a course context we need to properly indicate how we have come to the page,
2444
            // Within a course context we need to properly indicate how we have come to the page,
2331
            // regardless of whether it's currently logged in user or not.
2445
            // regardless of whether it's currently logged in user or not.
2332
            // Check that we have a valid node.
2446
            // Check that we have a valid node.
2333
            if (empty($newusernode)) {
2447
            if (empty($newusernode)) {
Línea 2346... Línea 2460...
2346
            }
2460
            }
2347
            // Add 'Reports' to our node.
2461
            // Add 'Reports' to our node.
2348
            $reportnode = $myprofilenode->add(get_string('reports'));
2462
            $reportnode = $myprofilenode->add(get_string('reports'));
2349
        }
2463
        }
2350
        // Finally add the report to the navigation tree.
2464
        // Finally add the report to the navigation tree.
-
 
2465
        $reportnode->add(
-
 
2466
            $nodeinfo['name'],
-
 
2467
            $nodeinfo['url'],
2351
        $reportnode->add($nodeinfo['name'], $nodeinfo['url'], navigation_node::TYPE_CUSTOM, null, null,
2468
            navigation_node::TYPE_CUSTOM,
-
 
2469
            null,
-
 
2470
            null,
2352
            new pix_icon('i/report', $nodeinfo['name']));
2471
            new pix_icon('i/report', $nodeinfo['name'])
-
 
2472
        );
2353
    }
2473
    }
Línea 2354... Línea 2474...
2354
 
2474
 
2355
    /**
2475
    /**
2356
     * Add some HTML to the list of actions to render in the header actions menu.
2476
     * Add some HTML to the list of actions to render in the header actions menu.
2357
     *
2477
     *
2358
     * @param string $html The HTML to add.
2478
     * @param string $html The HTML to add.
2359
     */
2479
     */
-
 
2480
    public function add_header_action(string $html): void
2360
    public function add_header_action(string $html): void {
2481
    {
2361
        $this->_headeractions[] = $html;
2482
        $this->_headeractions[] = $html;
Línea 2362... Línea 2483...
2362
    }
2483
    }
2363
 
2484
 
2364
    /**
2485
    /**
2365
     * Get the list of HTML for actions to render in the header actions menu.
2486
     * Get the list of HTML for actions to render in the header actions menu.
2366
     *
2487
     *
2367
     * @return string[]
2488
     * @return string[]
-
 
2489
     */
2368
     */
2490
    public function get_header_actions(): array
2369
    public function get_header_actions(): array {
2491
    {
Línea 2370... Línea 2492...
2370
        return $this->_headeractions;
2492
        return $this->_headeractions;
2371
    }
2493
    }
2372
 
2494
 
2373
    /**
2495
    /**
2374
     * Set the flag to indicate if the region main settings should be rendered as an action
2496
     * Set the flag to indicate if the region main settings should be rendered as an action
2375
     * in the header actions menu rather than at the top of the content.
2497
     * in the header actions menu rather than at the top of the content.
2376
     *
2498
     *
-
 
2499
     * @param bool $value If the settings should be in the header.
2377
     * @param bool $value If the settings should be in the header.
2500
     */
2378
     */
2501
    public function set_include_region_main_settings_in_header_actions(bool $value): void
Línea 2379... Línea 2502...
2379
    public function set_include_region_main_settings_in_header_actions(bool $value): void {
2502
    {
2380
        $this->_regionmainsettingsinheader = $value;
2503
        $this->_regionmainsettingsinheader = $value;
2381
    }
2504
    }
2382
 
2505
 
2383
    /**
2506
    /**
2384
     * Check if the  region main settings should be rendered as an action in the header actions
2507
     * Check if the  region main settings should be rendered as an action in the header actions
2385
     * menu rather than at the top of the content.
2508
     * menu rather than at the top of the content.
-
 
2509
     *
2386
     *
2510
     * @return bool
2387
     * @return bool
2511
     */
Línea 2388... Línea 2512...
2388
     */
2512
    public function include_region_main_settings_in_header_actions(): bool
2389
    public function include_region_main_settings_in_header_actions(): bool {
2513
    {
2390
        return $this->_regionmainsettingsinheader;
2514
        return $this->_regionmainsettingsinheader;
2391
    }
2515
    }
2392
 
2516
 
2393
    /**
2517
    /**
2394
     * Set the flag to indicate if the secondary navigation should be rendered.
2518
     * Set the flag to indicate if the secondary navigation should be rendered.
2395
     *
2519
     *
-
 
2520
     * @param bool $hassecondarynavigation If the secondary navigation should be rendered.
2396
     * @param bool $hassecondarynavigation If the secondary navigation should be rendered.
2521
     * @param bool $istablist When true, the navigation bar should be rendered and behave with a tablist ARIA role.
2397
     * @param bool $istablist When true, the navigation bar should be rendered and behave with a tablist ARIA role.
2522
     *                        If false, it's rendered with a menubar ARIA role. Defaults to false.
2398
     *                        If false, it's rendered with a menubar ARIA role. Defaults to false.
2523
     */
Línea 2399... Línea 2524...
2399
     */
2524
    public function set_secondary_navigation(bool $hassecondarynavigation, bool $istablist = false): void
2400
    public function set_secondary_navigation(bool $hassecondarynavigation, bool $istablist = false): void {
2525
    {
2401
        $this->_hassecondarynavigation = $hassecondarynavigation;
2526
        $this->_hassecondarynavigation = $hassecondarynavigation;
2402
        $this->_hastablistsecondarynavigation = $istablist;
2527
        $this->_hastablistsecondarynavigation = $istablist;
2403
    }
2528
    }
2404
 
2529
 
-
 
2530
    /**
2405
    /**
2531
     * Check if the secondary navigation should be rendered.
2406
     * Check if the secondary navigation should be rendered.
2532
     *
Línea 2407... Línea 2533...
2407
     *
2533
     * @return bool
2408
     * @return bool
2534
     */
2409
     */
2535
    public function has_secondary_navigation(): bool
2410
    public function has_secondary_navigation(): bool {
2536
    {
2411
        return $this->_hassecondarynavigation;
2537
        return $this->_hassecondarynavigation;
2412
    }
2538
    }
-
 
2539
 
2413
 
2540
    /**
2414
    /**
2541
     * Check if the secondary navigation should be rendered with a tablist as opposed to a menubar.
Línea 2415... Línea 2542...
2415
     * Check if the secondary navigation should be rendered with a tablist as opposed to a menubar.
2542
     *
2416
     *
2543
     * @return bool
2417
     * @return bool
2544
     */
2418
     */
2545
    public function has_tablist_secondary_navigation(): bool
2419
    public function has_tablist_secondary_navigation(): bool {
2546
    {
2420
        return $this->_hastablistsecondarynavigation;
2547
        return $this->_hastablistsecondarynavigation;
-
 
2548
    }
2421
    }
2549
 
2422
 
2550
    /**
Línea 2423... Línea 2551...
2423
    /**
2551
     * Set the key of the secondary nav node to be activated.
2424
     * Set the key of the secondary nav node to be activated.
2552
     *
2425
     *
2553
     * @param string $navkey the key of the secondary nav node to be activated.
2426
     * @param string $navkey the key of the secondary nav node to be activated.
2554
     */
2427
     */
2555
    public function set_secondary_active_tab(string $navkey): void
2428
    public function set_secondary_active_tab(string $navkey): void {
2556
    {
-
 
2557
        $this->_activekeysecondary = $navkey;
2429
        $this->_activekeysecondary = $navkey;
2558
    }
2430
    }
2559
 
Línea 2431... Línea 2560...
2431
 
2560
    /**
2432
    /**
2561
     * The key of secondary nav node to activate.
2433
     * The key of secondary nav node to activate.
2562
     *
2434
     *
2563
     * @return string|null get the key of the secondary node to activate.
2435
     * @return string|null get the key of the secondary node to activate.
2564
     */
2436
     */
2565
    public function get_secondary_active_tab(): ?string
-
 
2566
    {
2437
    public function get_secondary_active_tab(): ?string {
2567
        return $this->_activekeysecondary;
2438
        return $this->_activekeysecondary;
2568
    }
Línea 2439... Línea 2569...
2439
    }
2569
 
2440
 
2570
    /**
2441
    /**
2571
     * Set the key of the primary nav node to be activated.
2442
     * Set the key of the primary nav node to be activated.
2572
     *
2443
     *
2573
     * @param string $navkey
2444
     * @param string $navkey
2574
     */
-
 
2575
    public function set_primary_active_tab(string $navkey): void
2445
     */
2576
    {
2446
    public function set_primary_active_tab(string $navkey): void {
2577
        $this->_activenodeprimary = $navkey;
Línea 2447... Línea 2578...
2447
        $this->_activenodeprimary = $navkey;
2578
    }
2448
    }
2579
 
2449
 
2580
    /**
2450
    /**
2581
     * The key of the primary nav node to activate.
2451
     * The key of the primary nav node to activate.
2582
     *
2452
     *
2583
     * @return string|null get the key of the primary nav node to activate.
2453
     * @return string|null get the key of the primary nav node to activate.
2584
     */
-
 
2585
    public function get_primary_activate_tab(): ?string
2454
     */
2586
    {
2455
    public function get_primary_activate_tab(): ?string {
2587
        return $this->_activenodeprimary;
Línea 2456... Línea 2588...
2456
        return $this->_activenodeprimary;
2588
    }
2457
    }
2589
 
2458
 
2590
    /**
2459
    /**
2591
     * Sets the navigation overflow state. This allows developers to turn off the overflow menu if they perhaps are using
2460
     * Sets the navigation overflow state. This allows developers to turn off the overflow menu if they perhaps are using
2592
     * some other navigation to show settings.
2461
     * some other navigation to show settings.
2593
     *
-
 
2594
     * @param bool  $state  The state of whether to show the navigation overflow.
2462
     *
2595
     */
2463
     * @param bool  $state  The state of whether to show the navigation overflow.
2596
    public function set_navigation_overflow_state(bool $state): void
Línea 2464... Línea 2597...
2464
     */
2597
    {
2465
    public function set_navigation_overflow_state(bool $state): void {
2598
        $this->_navigationoverflow = $state;
2466
        $this->_navigationoverflow = $state;
2599
    }
2467
    }
2600
 
2468
 
2601
    /**
2469
    /**
2602
     * Gets the navigation overflow state.
2470
     * Gets the navigation overflow state.
2603
     *
2471
     *
2604
     * @return bool The navigation overflow state.
-
 
2605
     */
2472
     * @return bool The navigation overflow state.
2606
    public function get_navigation_overflow_state(): bool
2473
     */
2607
    {
Línea 2474... Línea 2608...
2474
    public function get_navigation_overflow_state(): bool {
2608
        return $this->_navigationoverflow;
2475
        return $this->_navigationoverflow;
2609
    }
2476
    }
2610
 
2477
 
2611
    /**
2478
    /**
2612
     * Set the status for displaying the course index.
2479
     * Set the status for displaying the course index.
2613
     *
-
 
2614
     * @param bool $state
2480
     *
2615
     *     - `true` (default) if the course index should be shown.
2481
     * @param bool $state
2616
     *     - `false` if the course index should be hidden.
2482
     *     - `true` (default) if the course index should be shown.
2617
     */