2009-05-26 03:23:32 +00:00
< ? php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
2004-11-08 19:36:07 +00:00
2004-11-10 16:43:57 +00:00
/**
2009-05-06 08:27:12 +00:00
* This file contains the moodle_page class . There is normally a single instance
* of this class in the $PAGE global variable . This class is a central reporitory
* of information about the page we are building up to send back to the user .
2004-11-10 16:43:57 +00:00
*
2009-05-26 03:23:32 +00:00
* @ package moodlecore
* @ copyright 1999 onwards Martin Dougiamas { @ link http :// moodle . com }
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
2004-11-10 16:43:57 +00:00
*/
2009-06-15 03:54:00 +00:00
2009-05-06 08:29:22 +00:00
/**
* $PAGE is a central store of information about the current page we are
2009-06-15 04:03:59 +00:00
* generating in response to the user ' s request .
*
* It does not do very much itself
2009-05-06 08:29:22 +00:00
* except keep track of information , however , it serves as the access point to
* some more significant components like $PAGE -> theme , $PAGE -> requires ,
* $PAGE -> blocks , etc .
2009-05-26 03:23:32 +00:00
*
2009-06-15 04:03:59 +00:00
* @ copyright 2009 Tim Hunt
2009-05-26 03:23:32 +00:00
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
2009-06-15 04:03:59 +00:00
* @ since Moodle 2.0
2009-06-15 03:54:00 +00:00
*
2010-01-28 03:19:21 +00:00
* @ property - read string $activityname The type of activity we are in , for example 'forum' or 'quiz' .
* Will be null if this page is not within a module .
* @ property - read object $activityrecord The row from the activities own database table ( for example
* the forum or quiz table ) that this page belongs to . Will be null
* if this page is not within a module .
* @ property - read array $alternativeversions Mime type => object with -> url and -> title .
* @ property - read blocks_manager $blocks The blocks manager object for this page .
* @ property - read string $bodyclasses Returns a string to use within the class attribute on the body tag .
* @ property - read string $button The HTML to go where the Turn editing on button normaly goes .
* @ property - read bool $cacheable Defaults to true . Set to false to stop the page being cached at all .
* @ property - read array $categories An array of all the categories the page course belongs to ,
* starting with the immediately containing category , and working out to
* the top - level category . This may be the empty array if we are in the
* front page course .
* @ property - read mixed $category The category that the page course belongs to . If there isn ' t one returns null .
* @ property - read object $cm The course_module that this page belongs to . Will be null
* if this page is not within a module . This is a full cm object , as loaded
* by get_coursemodule_from_id or get_coursemodule_from_instance ,
* so the extra modname and name fields are present .
* @ property - read object $context The main context to which this page belongs .
* @ property - read object $course The current course that we are inside - a row from the
* course table . ( Also available as $COURSE global . ) If we are not inside
* an actual course , this will be the site course .
* @ property - read string $docspath The path to the Moodle docs for this page .
* @ property - read string $focuscontrol The id of the HTML element to be focussed when the page has loaded .
* @ property - read bool $headerprinted
* @ property - read string $heading The main heading that should be displayed at the top of the < body >.
* @ property - read string $headingmenu The menu ( or actions ) to display in the heading
* @ property - read array $layout_options Returns arrays with options for layout file .
* @ property - read navbar $navbar Returns the navbar object used to display the navbar
* @ property - read global_navigation $navigation Returns the global navigation structure
* @ property - read xml_container_stack $opencontainers Tracks XHTML tags on this page that have been opened but not closed .
* mainly for internal use by the rendering code .
* @ property - read string $pagelayout The general type of page this is . For example 'normal' , 'popup' , 'home' .
2009-06-26 09:06:16 +00:00
* Allows the theme to display things differently , if it wishes to .
2010-01-28 03:19:21 +00:00
* @ property - read string $pagetype Returns the page type string , should be used as the id for the body tag in the theme .
* @ property - read int $periodicrefreshdelay The periodic refresh delay to use with meta refresh
* @ property - read page_requirements_manager $requires Tracks the JavaScript , CSS files , etc . required by this page .
* @ property - read settings_navigation $settignsnav
* @ property - read int $state One of the STATE_ ... constants
* @ property - read string $subpage The subpage identifier , if any .
* @ property - read theme_config $theme Returns the initialised theme for this page .
* @ property - read string $title The title that should go in the < head > section of the HTML of this page .
* @ property - read moodle_url $url The moodle url object for this page .
2009-05-06 08:29:22 +00:00
*/
class moodle_page {
/**#@+ Tracks the where we are in the generation of the page. */
const STATE_BEFORE_HEADER = 0 ;
const STATE_PRINTING_HEADER = 1 ;
const STATE_IN_BODY = 2 ;
2009-06-26 09:06:16 +00:00
const STATE_DONE = 3 ;
2009-05-06 08:29:22 +00:00
/**#@-*/
2009-05-06 08:42:13 +00:00
/// Field declarations =========================================================
2009-05-06 08:29:22 +00:00
protected $_state = self :: STATE_BEFORE_HEADER ;
protected $_course = null ;
2009-05-06 09:03:33 +00:00
/**
* If this page belongs to a module , this is the row from the course_modules
* table , as fetched by get_coursemodule_from_id or get_coursemodule_from_instance ,
* so the extra modname and name fields are present .
*/
protected $_cm = null ;
/**
* If $_cm is not null , then this will hold the corresponding row from the
* modname table . For example , if $_cm -> modname is 'quiz' , this will be a
* row from the quiz table .
*/
protected $_module = null ;
/**
* The context that this page belongs to .
*/
2009-05-06 08:30:25 +00:00
protected $_context = null ;
2009-05-06 08:46:05 +00:00
/**
* This holds any categories that $_course belongs to , starting with the
* particular category it belongs to , and working out through any parent
* categories to the top level . These are loaded progressively , if neaded .
* There are three states . $_categories = null initially when nothing is
* loaded ; $_categories = array ( $id => $cat , $parentid => null ) when we have
* loaded $_course -> category , but not any parents ; and a complete array once
* everything is loaded .
*/
protected $_categories = null ;
2009-05-06 08:42:13 +00:00
protected $_bodyclasses = array ();
2009-06-26 09:06:16 +00:00
protected $_title = '' ;
protected $_heading = '' ;
2009-05-06 08:34:32 +00:00
protected $_pagetype = null ;
2009-12-27 12:02:04 +00:00
protected $_pagelayout = 'base' ;
2009-12-16 18:00:58 +00:00
/**
* List of theme layeout options , these are ignored by core .
* To be used in individual theme layout files only .
* @ var array
*/
protected $_layout_options = array ();
2009-06-26 09:06:16 +00:00
2009-05-06 09:14:42 +00:00
protected $_subpage = '' ;
2009-05-06 09:03:49 +00:00
2009-05-06 08:48:13 +00:00
protected $_docspath = null ;
2010-03-25 06:38:21 +00:00
/** @var string|null A legacy class that will be added to the body tag */
2009-05-06 08:38:55 +00:00
protected $_legacyclass = null ;
2009-05-06 08:50:32 +00:00
protected $_url = null ;
2009-06-26 09:06:16 +00:00
protected $_alternateversions = array ();
2009-05-06 08:55:53 +00:00
protected $_blocks = null ;
2009-06-12 03:13:29 +00:00
protected $_requires = null ;
2009-05-06 09:01:42 +00:00
protected $_blockseditingcap = 'moodle/site:manageblocks' ;
protected $_othereditingcaps = array ();
2009-06-26 09:06:16 +00:00
protected $_cacheable = true ;
protected $_focuscontrol = '' ;
protected $_button = '' ;
themes: MDL-19077 implement the renderer_factory instrastructure.
This is part of http://docs.moodle.org/en/Development:Theme_engines_for_Moodle%3F
The concept is that all the print_... functions in weblib get replaced by methods
on a moodle_core_renderer class. Then, the theme can choose whether to
use the standard moodle_core_renderer class, or another implemenatation of
its own choosing, to generate different HTML.
Also, becuase Moodle is modular, we may need a moodle_mod_forum_renderer
and so on.
In order for the theme to be able to choose which renderers get created, we
introduce the concept of a renderer factory, as in the factory design pattern.
The theme will choose which factory should be used, and that then creates
the renderer objects based on the module name.
This commit includes 4 types of factory:
* standard_renderer_factory
* custom_corners_renderer_factory
* theme_overridden_renderer_factory
* template_renderer_factory
All this with unit tests and PHP doc comments.
Note, this new code is not actually used yet. Still todo:
1. actually define the moodle_core_renderer class, and deprecate a lot of weblib functions.
2. make theme_setup initialise everything, so it is used.
2009-06-18 10:43:13 +00:00
2009-07-01 05:54:26 +00:00
protected $_theme = null ;
2009-08-28 08:47:31 +00:00
/** @var null|global_navigation Contains the global navigation structure*/
protected $_navigation = null ;
/** @var null|settings_navigation Contains the settings navigation structure*/
protected $_settingsnav = null ;
/** @var null|navbar Contains the navbar structure*/
protected $_navbar = null ;
2009-09-01 03:47:07 +00:00
/** @var string */
protected $_headingmenu = null ;
2009-07-01 05:54:26 +00:00
/**
* Then the theme is initialsed , we save the stack trace , for use in error messages .
* @ var array stack trace .
*/
protected $_wherethemewasinitialised = null ;
2009-07-02 07:06:25 +00:00
/** @var xhtml_container_stack tracks XHTML tags on this page that have been opened but not closed. */
protected $_opencontainers ;
2009-06-30 07:57:41 +00:00
/**
* Sets the page to refresh after a given delay ( in seconds ) using meta refresh
* in { @ link standard_head_html ()} in outputlib . php
* If set to null ( default ) the page is not refreshed
* @ var int | null
*/
protected $_periodicrefreshdelay = null ;
2009-05-06 09:03:03 +00:00
/**
* This is simply to improve backwards compatability . If old code relies on
* a page class that implements print_header , or complex logic in
* user_allowed_editing then we stash an instance of that other class here ,
2009-12-16 18:00:58 +00:00
* and delegate to it in certain situations .
2009-05-06 09:03:03 +00:00
*/
protected $_legacypageobject = null ;
2009-12-17 14:06:22 +00:00
/// Magic getter methods =============================================================
2009-12-17 14:04:15 +00:00
/// Due to the __get magic below, you normally do not call these as $PAGE->magic_get_x
2009-05-06 08:43:51 +00:00
/// methods, but instead use the $PAGE->x syntax.
2009-05-06 08:42:13 +00:00
2009-05-06 08:29:22 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> state syntax . { @ link __get ()} .
2009-05-06 08:29:22 +00:00
* @ return integer one of the STATE_ ... constants . You should not normally need
* to use this in your code . It is indended for internal use by this class
* and its friends like print_header , to check that everything is working as
* expected . Also accessible as $PAGE -> state .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_state () {
2009-05-06 08:29:22 +00:00
return $this -> _state ;
}
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> headerprinted syntax . { @ link __get ()} .
2009-05-06 09:29:05 +00:00
* @ return boolean has the header already been printed ?
2009-05-06 08:29:22 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_headerprinted () {
2009-05-06 08:29:22 +00:00
return $this -> _state >= self :: STATE_IN_BODY ;
}
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> course syntax . { @ link __get ()} .
2009-05-26 03:23:32 +00:00
*
* @ global object
2009-05-06 08:29:22 +00:00
* @ return object the current course that we are inside - a row from the
* course table . ( Also available as $COURSE global . ) If we are not inside
2009-05-06 09:29:05 +00:00
* an actual course , this will be the site course .
2009-05-06 08:29:22 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_course () {
2009-05-06 08:29:22 +00:00
global $SITE ;
if ( is_null ( $this -> _course )) {
return $SITE ;
}
return $this -> _course ;
}
2009-05-06 09:03:33 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> cm syntax . { @ link __get ()} .
2009-05-06 09:03:33 +00:00
* @ return object the course_module that this page belongs to . Will be null
* if this page is not within a module . This is a full cm object , as loaded
* by get_coursemodule_from_id or get_coursemodule_from_instance ,
* so the extra modname and name fields are present .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_cm () {
2009-05-06 09:03:33 +00:00
return $this -> _cm ;
}
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> activityrecord syntax . { @ link __get ()} .
2009-05-06 09:29:05 +00:00
* @ return object the row from the activities own database table ( for example
* the forum or quiz table ) that this page belongs to . Will be null
* if this page is not within a module .
2009-05-06 09:03:33 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_activityrecord () {
2009-05-06 09:03:33 +00:00
if ( is_null ( $this -> _module ) && ! is_null ( $this -> _cm )) {
$this -> load_activity_record ();
}
return $this -> _module ;
}
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> activityname syntax . { @ link __get ()} .
2009-05-06 09:29:05 +00:00
* @ return string | null the The type of activity we are in , for example 'forum' or 'quiz' .
* Will be null if this page is not within a module .
2009-05-06 09:03:33 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_activityname () {
2009-05-06 09:03:33 +00:00
if ( is_null ( $this -> _cm )) {
return null ;
}
return $this -> _cm -> modname ;
}
2009-05-06 08:46:05 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> category syntax . { @ link __get ()} .
2009-05-06 08:46:05 +00:00
* @ return mixed the category that the page course belongs to . If there isn ' t one
* ( that is , if this is the front page course ) returns null .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_category () {
2009-05-06 08:46:05 +00:00
$this -> ensure_category_loaded ();
if ( ! empty ( $this -> _categories )) {
return reset ( $this -> _categories );
} else {
return null ;
}
}
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> categories syntax . { @ link __get ()} .
2009-05-06 08:46:05 +00:00
* @ return array an array of all the categories the page course belongs to ,
* starting with the immediately containing category , and working out to
* the top - level category . This may be the empty array if we are in the
* front page course .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_categories () {
2009-05-06 08:46:05 +00:00
$this -> ensure_categories_loaded ();
return $this -> _categories ;
}
2009-05-06 08:30:25 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> context syntax . { @ link __get ()} .
2009-05-06 08:30:25 +00:00
* @ return object the main context to which this page belongs .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_context () {
2009-05-06 08:30:25 +00:00
if ( is_null ( $this -> _context )) {
throw new coding_exception ( '$PAGE->context accessed before it was known.' );
}
return $this -> _context ;
}
2009-05-06 08:34:32 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> pagetype syntax . { @ link __get ()} .
2010-03-25 06:38:21 +00:00
* @ return string e . g . 'my-index' or 'mod-quiz-attempt' .
2009-05-06 08:34:32 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_pagetype () {
2009-05-06 08:38:55 +00:00
if ( is_null ( $this -> _pagetype ) || isset ( $CFG -> pagepath )) {
$this -> initialise_default_pagetype ();
2009-05-06 08:34:32 +00:00
}
return $this -> _pagetype ;
}
2010-03-25 06:38:21 +00:00
/**
* Please do not call this method directly , use the -> pagetype syntax . { @ link __get ()} .
* @ return string The id to use on the body tag , uses { @ link magic_get_pagetype ()} .
*/
protected function magic_get_bodyid () {
return 'page-' . $this -> pagetype ;
}
2009-05-06 09:03:49 +00:00
/**
2009-12-16 18:00:58 +00:00
* Please do not call this method directly , use the -> pagelayout syntax . { @ link __get ()} .
2009-12-27 12:02:04 +00:00
* @ return string the general type of page this is . For example 'standard' , 'popup' , 'home' .
2009-06-26 09:06:16 +00:00
* Allows the theme to display things differently , if it wishes to .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_pagelayout () {
2009-12-16 18:00:58 +00:00
return $this -> _pagelayout ;
}
/**
* Please do not call this method directly , use the -> layout_tions syntax . { @ link __get ()} .
2010-01-28 03:19:21 +00:00
* @ return array returns arrys with options for layout file
2009-12-16 18:00:58 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_layout_options () {
2009-12-16 18:00:58 +00:00
return $this -> _layout_options ;
2009-06-26 09:06:16 +00:00
}
/**
* Please do not call this method directly , use the -> subpage syntax . { @ link __get ()} .
2009-05-06 09:03:49 +00:00
* @ return string | null The subpage identifier , if any .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_subpage () {
2009-05-06 09:03:49 +00:00
return $this -> _subpage ;
}
2009-05-06 08:42:13 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> bodyclasses syntax . { @ link __get ()} .
2009-05-06 08:42:13 +00:00
* @ return string the class names to put on the body element in the HTML .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_bodyclasses () {
2009-05-06 08:42:13 +00:00
return implode ( ' ' , array_keys ( $this -> _bodyclasses ));
}
2009-05-06 08:48:13 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> title syntax . { @ link __get ()} .
* @ return string the title that should go in the < head > section of the HTML of this page .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_title () {
2009-06-26 09:06:16 +00:00
return $this -> _title ;
}
/**
* Please do not call this method directly , use the -> heading syntax . { @ link __get ()} .
* @ return string the main heading that should be displayed at the top of the < body >.
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_heading () {
2009-06-26 09:06:16 +00:00
return $this -> _heading ;
}
2009-09-01 03:47:07 +00:00
/**
* Please do not call this method directly , use the -> heading syntax . { @ link __get ()} .
* @ return string The menu ( or actions ) to display in the heading
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_headingmenu () {
2009-09-01 03:47:07 +00:00
return $this -> _headingmenu ;
}
2009-06-26 09:06:16 +00:00
/**
* Please do not call this method directly , use the -> docspath syntax . { @ link __get ()} .
2009-05-06 09:29:05 +00:00
* @ return string the path to the Moodle docs for this page .
2009-05-06 08:48:13 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_docspath () {
2009-05-06 08:48:13 +00:00
if ( is_string ( $this -> _docspath )) {
return $this -> _docspath ;
} else {
return str_replace ( '-' , '/' , $this -> pagetype );
}
}
2009-05-06 08:50:32 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> url syntax . { @ link __get ()} .
2009-05-06 08:50:32 +00:00
* @ return moodle_url the clean URL required to load the current page . ( You
* should normally use this in preference to $ME or $FULLME . )
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_url () {
2009-09-03 07:47:43 +00:00
global $FULLME ;
2009-05-06 08:50:32 +00:00
if ( is_null ( $this -> _url )) {
2009-09-03 07:47:43 +00:00
debugging ( 'This page did not call $PAGE->set_url(...). Using ' . s ( $FULLME ), DEBUG_DEVELOPER );
2009-07-14 10:41:59 +00:00
$this -> _url = new moodle_url ( $FULLME );
// Make sure the guessed URL cannot lead to dangerous redirects.
$this -> _url -> remove_params ( 'sesskey' );
2009-05-06 08:50:32 +00:00
}
2009-05-06 08:55:53 +00:00
return new moodle_url ( $this -> _url ); // Return a clone for safety.
}
/**
2009-06-26 09:06:16 +00:00
* The list of alternate versions of this page .
* @ return array mime type => object with -> url and -> title .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_alternateversions () {
2009-06-26 09:06:16 +00:00
return $this -> _alternateversions ;
}
/**
* Please do not call this method directly , use the -> blocks syntax . { @ link __get ()} .
2009-05-06 08:55:53 +00:00
* @ return blocks_manager the blocks manager object for this page .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_blocks () {
2009-12-16 18:00:58 +00:00
global $CFG ;
2009-05-06 08:55:53 +00:00
if ( is_null ( $this -> _blocks )) {
2009-05-06 09:14:01 +00:00
if ( ! empty ( $CFG -> blockmanagerclass )) {
$classname = $CFG -> blockmanagerclass ;
} else {
$classname = 'block_manager' ;
}
$this -> _blocks = new $classname ( $this );
2009-05-06 08:55:53 +00:00
}
return $this -> _blocks ;
2009-05-06 08:50:32 +00:00
}
2009-06-12 03:13:29 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> requires syntax . { @ link __get ()} .
themes: MDL-19077 implement the renderer_factory instrastructure.
This is part of http://docs.moodle.org/en/Development:Theme_engines_for_Moodle%3F
The concept is that all the print_... functions in weblib get replaced by methods
on a moodle_core_renderer class. Then, the theme can choose whether to
use the standard moodle_core_renderer class, or another implemenatation of
its own choosing, to generate different HTML.
Also, becuase Moodle is modular, we may need a moodle_mod_forum_renderer
and so on.
In order for the theme to be able to choose which renderers get created, we
introduce the concept of a renderer factory, as in the factory design pattern.
The theme will choose which factory should be used, and that then creates
the renderer objects based on the module name.
This commit includes 4 types of factory:
* standard_renderer_factory
* custom_corners_renderer_factory
* theme_overridden_renderer_factory
* template_renderer_factory
All this with unit tests and PHP doc comments.
Note, this new code is not actually used yet. Still todo:
1. actually define the moodle_core_renderer class, and deprecate a lot of weblib functions.
2. make theme_setup initialise everything, so it is used.
2009-06-18 10:43:13 +00:00
* @ return page_requirements_manager tracks the JavaScript , CSS files , etc . required by this page .
2009-06-12 03:13:29 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_requires () {
2009-06-12 03:13:29 +00:00
global $CFG ;
if ( is_null ( $this -> _requires )) {
$this -> _requires = new page_requirements_manager ();
}
return $this -> _requires ;
}
themes: MDL-19077 implement the renderer_factory instrastructure.
This is part of http://docs.moodle.org/en/Development:Theme_engines_for_Moodle%3F
The concept is that all the print_... functions in weblib get replaced by methods
on a moodle_core_renderer class. Then, the theme can choose whether to
use the standard moodle_core_renderer class, or another implemenatation of
its own choosing, to generate different HTML.
Also, becuase Moodle is modular, we may need a moodle_mod_forum_renderer
and so on.
In order for the theme to be able to choose which renderers get created, we
introduce the concept of a renderer factory, as in the factory design pattern.
The theme will choose which factory should be used, and that then creates
the renderer objects based on the module name.
This commit includes 4 types of factory:
* standard_renderer_factory
* custom_corners_renderer_factory
* theme_overridden_renderer_factory
* template_renderer_factory
All this with unit tests and PHP doc comments.
Note, this new code is not actually used yet. Still todo:
1. actually define the moodle_core_renderer class, and deprecate a lot of weblib functions.
2. make theme_setup initialise everything, so it is used.
2009-06-18 10:43:13 +00:00
/**
2009-06-26 09:06:16 +00:00
* Please do not call this method directly , use the -> cacheable syntax . { @ link __get ()} .
* @ return boolean can this page be cached by the user ' s browser .
themes: MDL-19077 implement the renderer_factory instrastructure.
This is part of http://docs.moodle.org/en/Development:Theme_engines_for_Moodle%3F
The concept is that all the print_... functions in weblib get replaced by methods
on a moodle_core_renderer class. Then, the theme can choose whether to
use the standard moodle_core_renderer class, or another implemenatation of
its own choosing, to generate different HTML.
Also, becuase Moodle is modular, we may need a moodle_mod_forum_renderer
and so on.
In order for the theme to be able to choose which renderers get created, we
introduce the concept of a renderer factory, as in the factory design pattern.
The theme will choose which factory should be used, and that then creates
the renderer objects based on the module name.
This commit includes 4 types of factory:
* standard_renderer_factory
* custom_corners_renderer_factory
* theme_overridden_renderer_factory
* template_renderer_factory
All this with unit tests and PHP doc comments.
Note, this new code is not actually used yet. Still todo:
1. actually define the moodle_core_renderer class, and deprecate a lot of weblib functions.
2. make theme_setup initialise everything, so it is used.
2009-06-18 10:43:13 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_cacheable () {
2009-06-26 09:06:16 +00:00
return $this -> _cacheable ;
}
/**
* Please do not call this method directly , use the -> focuscontrol syntax . { @ link __get ()} .
* @ return string the id of the HTML element to be focussed when the page has loaded .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_focuscontrol () {
2009-06-26 09:06:16 +00:00
return $this -> _focuscontrol ;
}
/**
* Please do not call this method directly , use the -> button syntax . { @ link __get ()} .
* @ return string the HTML to go where the Turn editing on button normaly goes .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_button () {
2009-06-26 09:06:16 +00:00
return $this -> _button ;
themes: MDL-19077 implement the renderer_factory instrastructure.
This is part of http://docs.moodle.org/en/Development:Theme_engines_for_Moodle%3F
The concept is that all the print_... functions in weblib get replaced by methods
on a moodle_core_renderer class. Then, the theme can choose whether to
use the standard moodle_core_renderer class, or another implemenatation of
its own choosing, to generate different HTML.
Also, becuase Moodle is modular, we may need a moodle_mod_forum_renderer
and so on.
In order for the theme to be able to choose which renderers get created, we
introduce the concept of a renderer factory, as in the factory design pattern.
The theme will choose which factory should be used, and that then creates
the renderer objects based on the module name.
This commit includes 4 types of factory:
* standard_renderer_factory
* custom_corners_renderer_factory
* theme_overridden_renderer_factory
* template_renderer_factory
All this with unit tests and PHP doc comments.
Note, this new code is not actually used yet. Still todo:
1. actually define the moodle_core_renderer class, and deprecate a lot of weblib functions.
2. make theme_setup initialise everything, so it is used.
2009-06-18 10:43:13 +00:00
}
2009-07-01 05:54:26 +00:00
/**
* Please do not call this method directly , use the -> theme syntax . { @ link __get ()} .
2010-01-28 03:19:21 +00:00
* @ return theme_config the initialised theme for this page .
2009-07-01 05:54:26 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_theme () {
2009-07-01 05:54:26 +00:00
if ( is_null ( $this -> _theme )) {
$this -> initialise_theme_and_output ();
}
return $this -> _theme ;
}
2009-06-30 07:57:41 +00:00
/**
2009-07-01 03:47:52 +00:00
* Please do not call this method directly use the -> periodicrefreshdelay syntax
* { @ link __get ()}
* @ return int The periodic refresh delay to use with meta refresh
2009-06-30 07:57:41 +00:00
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_periodicrefreshdelay () {
2009-06-30 07:57:41 +00:00
return $this -> _periodicrefreshdelay ;
}
2009-07-02 07:06:25 +00:00
/**
* Please do not call this method directly use the -> opencontainers syntax . { @ link __get ()}
* @ return xhtml_container_stack tracks XHTML tags on this page that have been opened but not closed .
* mainly for internal use by the rendering code .
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_opencontainers () {
2009-07-02 07:06:25 +00:00
if ( is_null ( $this -> _opencontainers )) {
$this -> _opencontainers = new xhtml_container_stack ();
}
return $this -> _opencontainers ;
}
2009-08-28 08:47:31 +00:00
/**
* Return the navigation object
* @ return global_navigation
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_navigation () {
2009-08-28 08:47:31 +00:00
if ( $this -> _navigation === null ) {
$this -> _navigation = new global_navigation ();
}
return $this -> _navigation ;
}
/**
* Return a navbar object
* @ return navbar
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_navbar () {
2009-08-28 08:47:31 +00:00
if ( $this -> _navbar === null ) {
$this -> _navbar = new navbar ( $this );
}
return $this -> _navbar ;
}
/**
* Returns the settings navigation object
* @ return settings_navigation
*/
2009-12-17 14:04:15 +00:00
protected function magic_get_settingsnav () {
2009-08-28 08:47:31 +00:00
if ( $this -> _settingsnav === null ) {
$this -> _settingsnav = new settings_navigation ( $this );
$this -> _settingsnav -> initialise ();
}
return $this -> _settingsnav ;
}
2009-05-06 08:44:58 +00:00
/**
2009-05-06 09:29:05 +00:00
* PHP overloading magic to make the $PAGE -> course syntax work by redirecting
2009-12-17 14:04:15 +00:00
* it to the corresponding $PAGE -> magic_get_course () method if there is one , and
2009-05-06 09:29:05 +00:00
* throwing an exception if not .
2009-12-17 14:04:15 +00:00
* @ var string field name
* @ return mixed
2009-05-06 08:44:58 +00:00
*/
public function __get ( $field ) {
2009-12-17 14:04:15 +00:00
$getmethod = 'magic_get_' . $field ;
2009-05-06 08:44:58 +00:00
if ( method_exists ( $this , $getmethod )) {
return $this -> $getmethod ();
} else {
throw new coding_exception ( 'Unknown field ' . $field . ' of $PAGE.' );
}
}
2009-05-06 08:59:29 +00:00
/// Other information getting methods ==========================================
2009-12-17 14:06:22 +00:00
/**
* Returns instance of page renderer
* @ param string $component name such as 'core' , 'mod_forum' or 'qtype_multichoice' .
* @ param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
2009-12-17 22:43:27 +00:00
* @ param string $target one of rendering target constants
2009-12-17 14:06:22 +00:00
* @ return renderer_base
*/
2009-12-17 22:43:27 +00:00
public function get_renderer ( $component , $subtype = null , $target = null ) {
return $this -> magic_get_theme () -> get_renderer ( $this , $component , $subtype , $target );
2009-12-17 14:06:22 +00:00
}
2009-12-17 14:04:15 +00:00
/**
* Checks to see if there are any items on the navbar object
* @ return bool true if there are , false if not
*/
public function has_navbar () {
if ( $this -> _navbar === null ) {
$this -> _navbar = new navbar ( $this );
}
return $this -> _navbar -> has_items ();
}
2009-05-06 08:59:29 +00:00
/**
* @ return boolean should the current user see this page in editing mode .
* That is , are they allowed to edit this page , and are they currently in
* editing mode .
*/
public function user_is_editing () {
global $USER ;
return ! empty ( $USER -> editing ) && $this -> user_allowed_editing ();
}
2009-05-06 09:15:05 +00:00
/**
* @ return boolean does the user have permission to edit blocks on this page .
*/
public function user_can_edit_blocks () {
return has_capability ( $this -> _blockseditingcap , $this -> _context );
}
2009-05-06 08:59:29 +00:00
/**
* @ return boolean does the user have permission to see this page in editing mode .
*/
public function user_allowed_editing () {
2009-05-06 09:03:03 +00:00
if ( $this -> _legacypageobject ) {
return $this -> _legacypageobject -> user_allowed_editing ();
}
2009-05-07 08:55:10 +00:00
return has_any_capability ( $this -> all_editing_caps (), $this -> context );
2009-05-06 08:59:29 +00:00
}
2009-07-20 06:18:16 +00:00
/**
2009-07-21 13:58:47 +00:00
* @ return string a description of this page . Normally displayed in the footer in
* developer debug mode .
2009-07-20 06:18:16 +00:00
*/
public function debug_summary () {
2009-07-21 13:58:47 +00:00
$summary = '' ;
2009-12-16 18:00:58 +00:00
$summary .= 'General type: ' . $this -> pagelayout . '. ' ;
2009-07-21 13:58:47 +00:00
if ( ! during_initial_install ()) {
$summary .= 'Context ' . print_context_name ( $this -> context ) . ' (context id ' . $this -> context -> id . '). ' ;
}
2009-07-20 06:18:16 +00:00
$summary .= 'Page type ' . $this -> pagetype . '. ' ;
if ( $this -> subpage ) {
'Sub-page ' . $this -> subpage . '. ' ;
}
return $summary ;
}
2009-05-06 08:42:13 +00:00
/// Setter methods =============================================================
2009-05-06 08:29:22 +00:00
/**
* Set the state . The state must be one of that STATE_ ... constants , and
* the state is only allowed to advance one step at a time .
* @ param integer $state the new state .
*/
public function set_state ( $state ) {
if ( $state != $this -> _state + 1 || $state > self :: STATE_DONE ) {
throw new coding_exception ( 'Invalid state passed to moodle_page::set_state. We are in state ' .
$this -> _state . ' and state ' . $state . ' was requestsed.' );
}
2009-05-06 08:42:13 +00:00
if ( $state == self :: STATE_PRINTING_HEADER ) {
2009-05-06 09:14:42 +00:00
$this -> starting_output ();
2009-05-06 08:29:22 +00:00
}
$this -> _state = $state ;
}
/**
* Set the current course . This sets both $PAGE -> course and $COURSE . It also
* sets the right theme and locale .
*
* Normally you don ' t need to call this function yourself , require_login will
* call it for you if you pass a $course to it . You can use this function
* on pages that do need to call require_login () .
*
2009-05-06 08:30:25 +00:00
* Sets $PAGE -> context to the course context , if it is not already set .
*
2009-05-06 08:29:22 +00:00
* @ param object the course to set as the global course .
*/
public function set_course ( $course ) {
2009-07-01 05:54:26 +00:00
global $COURSE , $PAGE ;
2009-05-06 08:29:22 +00:00
if ( empty ( $course -> id )) {
throw new coding_exception ( '$course passed to moodle_page::set_course does not look like a proper course object.' );
}
2009-07-01 05:54:26 +00:00
$this -> ensure_theme_not_set ();
2009-05-06 08:29:22 +00:00
2009-05-06 08:46:48 +00:00
if ( ! empty ( $this -> _course -> id ) && $this -> _course -> id != $course -> id ) {
$this -> _categories = null ;
}
2009-05-06 08:29:22 +00:00
$this -> _course = clone ( $course );
2009-07-01 05:54:26 +00:00
if ( $this === $PAGE ) {
$COURSE = $this -> _course ;
moodle_setlocale ();
}
2009-05-06 08:29:22 +00:00
2009-05-06 08:30:25 +00:00
if ( ! $this -> _context ) {
$this -> set_context ( get_context_instance ( CONTEXT_COURSE , $this -> _course -> id ));
}
2009-05-06 08:29:22 +00:00
}
2009-05-06 08:30:25 +00:00
/**
* Set the main context to which this page belongs .
* @ param object $context a context object , normally obtained with get_context_instance .
*/
public function set_context ( $context ) {
$this -> _context = $context ;
}
2009-05-06 09:03:33 +00:00
/**
* The course module that this page belongs to ( if it does belong to one ) .
*
* @ param objcet $cm a full cm objcet obtained from get_coursemodule_from_id or get_coursemodule_from_instance .
*/
public function set_cm ( $cm , $course = null , $module = null ) {
2010-03-31 07:41:31 +00:00
if ( ! isset ( $cm -> name ) || ! isset ( $cm -> modname ) || ! isset ( $cm -> id )) {
2009-05-06 09:03:33 +00:00
throw new coding_exception ( 'The $cm you set on $PAGE must have been obtained with get_coursemodule_from_id or get_coursemodule_from_instance. That is, the ->name and -> modname fields must be present and correct.' );
}
$this -> _cm = $cm ;
2010-03-31 07:41:31 +00:00
$this -> _cm -> context = get_context_instance ( CONTEXT_MODULE , $cm -> id ); // hacky shortcut
2009-05-06 09:03:33 +00:00
if ( ! $this -> _context ) {
2010-03-31 07:41:31 +00:00
$this -> set_context ( $this -> _cm -> context );
2009-05-06 09:03:33 +00:00
}
if ( ! $this -> _course || $this -> _course -> id != $cm -> course ) {
if ( ! $course ) {
global $DB ;
$course = $DB -> get_record ( 'course' , array ( 'id' => $cm -> course ));
}
if ( $course -> id != $cm -> course ) {
throw new coding_exception ( 'The course you passed to $PAGE->set_cm does not seem to correspond to the $cm.' );
}
$this -> set_course ( $course );
}
if ( $module ) {
$this -> set_activity_record ( $module );
}
}
/**
* @ param $module a row from the main database table for the module that this
* page belongs to . For example , if -> cm is a forum , then you can pass the
* corresponding row from the forum table here if you have it ( saves a database
* query sometimes ) .
*/
public function set_activity_record ( $module ) {
if ( is_null ( $this -> _cm )) {
throw new coding_exception ( 'You cannot call $PAGE->set_activity_record until after $PAGE->cm has been set.' );
}
if ( $module -> id != $this -> _cm -> instance || $module -> course != $this -> _course -> id ) {
throw new coding_exception ( 'The activity record your are trying to set does not seem to correspond to the cm that has been set.' );
}
$this -> _module = $module ;
}
2009-05-06 08:34:32 +00:00
/**
* @ param string $pagetype e . g . 'my-index' or 'mod-quiz-attempt' . Normally
* you do not need to set this manually , it is automatically created from the
* script name . However , on some pages this is overridden . For example , the
* page type for coures / view . php includes the course format , for example
* 'coures-view-weeks' . This gets used as the id attribute on < body > and
* also for determining which blocks are displayed .
*/
public function set_pagetype ( $pagetype ) {
$this -> _pagetype = $pagetype ;
}
2009-06-26 09:06:16 +00:00
/**
2009-12-16 18:00:58 +00:00
* @ param string $pagelayout the page layout this is . For example 'popup' , 'home' .
2009-12-27 12:02:04 +00:00
* This properly defaults to 'base' , so you only need to call this function if
2009-12-16 18:00:58 +00:00
* you want something different . The exact range of supported layouts is specified
* in the standard theme .
2009-06-26 09:06:16 +00:00
*/
2009-12-16 18:00:58 +00:00
public function set_pagelayout ( $pagelayout ) {
$this -> _pagelayout = $pagelayout ;
2009-06-26 09:06:16 +00:00
}
2009-05-06 09:03:49 +00:00
/**
* If context -> id and pagetype are not enough to uniquely identify this page ,
* then you can set a subpage id as well . For example , the tags page sets
* @ param string $subpage an arbitrary identifier that , along with context -> id
* and pagetype , uniquely identifies this page .
*/
public function set_subpage ( $subpage ) {
2009-05-06 09:14:42 +00:00
if ( empty ( $subpage )) {
$this -> _subpage = '' ;
} else {
$this -> _subpage = $subpage ;
}
2009-05-06 09:03:49 +00:00
}
2009-05-06 08:42:13 +00:00
/**
* @ param string $class add this class name ot the class attribute on the body tag .
*/
public function add_body_class ( $class ) {
if ( $this -> _state > self :: STATE_BEFORE_HEADER ) {
throw new coding_exception ( 'Cannot call moodle_page::add_body_class after output has been started.' );
}
$this -> _bodyclasses [ $class ] = 1 ;
}
2009-05-06 08:29:22 +00:00
/**
2009-05-06 08:44:58 +00:00
* @ param array $classes this utility method calls add_body_class for each array element .
2009-05-06 08:29:22 +00:00
*/
2009-05-06 08:44:58 +00:00
public function add_body_classes ( $classes ) {
foreach ( $classes as $class ) {
$this -> add_body_class ( $class );
2009-05-06 08:29:22 +00:00
}
}
2009-05-06 08:34:32 +00:00
2009-06-26 09:06:16 +00:00
/**
2009-09-01 03:47:07 +00:00
* @ param string $title the title that should go in the < head > section of the HTML of this page .
2009-06-26 09:06:16 +00:00
*/
public function set_title ( $title ) {
$title = format_string ( $title );
$title = str_replace ( '"' , '"' , $title );
$this -> _title = $title ;
}
/**
2009-09-01 03:47:07 +00:00
* @ param string $heading the main heading that should be displayed at the top of the < body >.
2009-06-26 09:06:16 +00:00
*/
public function set_heading ( $heading ) {
$this -> _heading = format_string ( $heading );
}
2009-09-01 03:47:07 +00:00
/**
* @ param string $menu The menu / content to show in the heading
*/
public function set_headingmenu ( $menu ) {
$this -> _headingmenu = $menu ;
}
2009-05-06 08:46:05 +00:00
/**
* Set the course category this page belongs to manually . This automatically
* sets $PAGE -> course to be the site coures . You cannot use this method if
* you have already set $PAGE -> course - in that case , the category must be
* the one that the course belongs to . This also automatically sets the
* page context to the category context .
* @ param integer $categoryid The id of the category to set .
*/
public function set_category_by_id ( $categoryid ) {
global $SITE , $DB ;
if ( ! is_null ( $this -> _course )) {
throw new coding_exception ( 'Attempt to manually set the course category when the course has been set. This is not allowed.' );
}
if ( is_array ( $this -> _categories )) {
throw new coding_exception ( 'Course category has already been set. You are not allowed to change it.' );
}
2009-07-01 05:54:26 +00:00
$this -> ensure_theme_not_set ();
2009-05-06 08:46:05 +00:00
$this -> set_course ( $SITE );
$this -> load_category ( $categoryid );
$this -> set_context ( get_context_instance ( CONTEXT_COURSECAT , $categoryid ));
}
2009-05-06 08:48:13 +00:00
/**
* Set a different path to use for the 'Moodle docs for this page' link .
* By default , it uses the pagetype , which is normally the same as the
* script name . So , for example , for mod / quiz / attempt . php , pagetype is
* mod - quiz - attempt , and so docspath is mod / quiz / attempt .
* @ param string $path the path to use at the end of the moodle docs URL .
*/
public function set_docs_path ( $path ) {
$this -> _docspath = $path ;
}
2009-05-06 08:50:32 +00:00
/**
* You should call this method from every page to set the cleaned - up URL
* that should be used to return to this page . Used , for example , by the
* blocks editing UI to know where to return the user after an action .
* For example , course / view . php does :
* $id = optional_param ( 'id' , 0 , PARAM_INT );
2010-01-16 15:39:56 +00:00
* $PAGE -> set_url ( '/course/view.php' , array ( 'id' => $id ));
2010-01-07 20:17:38 +00:00
* @ param moodle_url | string $url URL relative to $CFG -> wwwroot or { @ link moodle_url } instance
2010-01-16 15:39:56 +00:00
* @ param array $params paramters to add to the URL
2009-05-06 08:50:32 +00:00
*/
2010-01-16 15:39:56 +00:00
public function set_url ( $url , array $params = null ) {
2009-05-06 08:50:32 +00:00
global $CFG ;
2009-12-29 14:30:15 +00:00
2010-01-16 15:39:56 +00:00
if ( is_string ( $url )) {
2009-12-29 14:30:15 +00:00
if ( strpos ( $url , 'http' ) === 0 ) {
2010-01-16 15:39:56 +00:00
// ok
} else if ( strpos ( $url , '/' ) === 0 ) {
2009-12-29 14:30:15 +00:00
// we have to use httpswwwroot here, because of loginhttps pages
2010-01-16 15:39:56 +00:00
$url = $CFG -> httpswwwroot . $url ;
} else {
throw new coding_exception ( 'Invalid parameter $url, has to be full url or in shortened form starting with /.' );
2009-12-29 14:30:15 +00:00
}
2009-07-29 16:05:36 +00:00
}
2009-12-29 14:30:15 +00:00
2010-01-16 15:39:56 +00:00
$this -> _url = new moodle_url ( $url , $params );
2010-01-17 09:37:30 +00:00
$fullurl = $this -> _url -> out_omit_querystring ();
2009-12-29 14:30:15 +00:00
if ( strpos ( $fullurl , " $CFG->httpswwwroot / " ) !== 0 ) {
debugging ( 'Most probably incorrect set_page() url argument, it does not match the httpswwwroot!' );
}
$shorturl = str_replace ( " $CFG->httpswwwroot / " , '' , $fullurl );
2009-05-06 08:50:32 +00:00
if ( is_null ( $this -> _pagetype )) {
2009-07-29 16:05:36 +00:00
$this -> initialise_default_pagetype ( $shorturl );
2009-05-06 08:50:32 +00:00
}
2009-05-06 09:03:33 +00:00
if ( ! is_null ( $this -> _legacypageobject )) {
2009-07-29 16:38:40 +00:00
$this -> _legacypageobject -> set_url ( $url , $params );
2009-05-06 09:03:33 +00:00
}
2009-05-06 08:50:32 +00:00
}
2009-07-14 10:41:59 +00:00
/**
* Make sure page URL does not contain the given URL parameter .
*
* This should not be necessary if the script has called set_url properly .
* However , in some situations like the block editing actions ; when the URL
* has been guessed , it will contain dangerous block - related actions .
* Therefore , the blocks code calls this function to clean up such parameters
* before doing any redirect .
2009-11-01 11:31:16 +00:00
*
2009-07-14 10:41:59 +00:00
* @ param string $param the name of the parameter to make sure is not in the
* page URL .
*/
public function ensure_param_not_in_url ( $param ) {
$discard = $this -> url ; // Make sure $this->url is lazy-loaded;
$this -> _url -> remove_params ( $param );
}
2009-06-26 09:06:16 +00:00
/**
* There can be alternate versions of some pages ( for example an RSS feed version ) .
* If such other version exist , call this method , and a link to the alternate
* version will be included in the < head > of the page .
*
* @ param $title The title to give the alternate version .
* @ param $url The URL of the alternate version .
* @ param $mimetype The mime - type of the alternate version .
*/
public function add_alternate_version ( $title , $url , $mimetype ) {
if ( $this -> _state > self :: STATE_BEFORE_HEADER ) {
throw new coding_exception ( 'Cannot call moodle_page::add_alternate_version after output has been started.' );
}
$alt = new stdClass ;
$alt -> title = $title ;
$alt -> url = url ;
$this -> _alternateversions [ $mimetype ] = $alt ;
}
/**
* Specify a form control should be focussed when the page has loaded .
*
* @ param string $controlid the id of the HTML element to be focussed .
*/
public function set_focuscontrol ( $controlid ) {
$this -> _focuscontrol = $controlid ;
}
/**
* Specify a fragment of HTML that goes where the 'Turn editing on' button normally goes .
*
* @ param string $html the HTML to display there .
*/
public function set_button ( $html ) {
$this -> _button = $html ;
}
2009-05-06 09:01:42 +00:00
/**
* Set the capability that allows users to edit blocks on this page . Normally
* the default of 'moodle/site:manageblocks' is used , but a few pages like
* the My Moodle page need to use a different capability like 'moodle/my:manageblocks' .
* @ param string $capability a capability .
*/
public function set_blocks_editing_capability ( $capability ) {
$this -> _blockseditingcap = $capability ;
}
/**
* Some pages let you turn editing on for reasons other than editing blocks .
* If that is the case , you can pass other capabilitise that let the user
* edit this page here .
* @ param string | array $capability either a capability , or an array of capabilities .
*/
public function set_other_editing_capability ( $capability ) {
if ( is_array ( $capability )) {
$this -> _othereditingcaps = array_unique ( $this -> _othereditingcaps + $capability );
} else {
$this -> _othereditingcaps [] = $capability ;
}
}
2009-06-26 09:06:16 +00:00
/**
* @ return boolean $cacheable can this page be cached by the user ' s browser .
*/
public function set_cacheable ( $cacheable ) {
$this -> _cacheable = $cacheable ;
}
2009-06-30 07:57:41 +00:00
/**
* Sets the page to periodically refresh
*
* This function must be called before $OUTPUT -> header has been called or
* a coding exception will be thrown .
*
* @ param int $delay Sets the delay before refreshing the page , if set to null
* refresh is cancelled
*/
public function set_periodic_refresh_delay ( $delay = null ) {
if ( $this -> _state > self :: STATE_BEFORE_HEADER ) {
throw new coding_exception ( 'You cannot set a periodic refresh delay after the header has been printed' );
}
if ( $delay === null ) {
$this -> _periodicrefreshdelay = null ;
} else if ( is_int ( $delay )) {
$this -> _periodicrefreshdelay = $delay ;
}
}
2009-07-01 05:54:26 +00:00
/**
* Force this page to use a particular theme .
*
2009-12-23 18:23:21 +00:00
* Please use this cautiously . It is only intended to be used by the themes selector admin page .
2009-07-01 05:54:26 +00:00
*
* @ param $themename the name of the theme to use .
*/
public function force_theme ( $themename ) {
$this -> ensure_theme_not_set ();
$this -> _theme = theme_config :: load ( $themename );
}
/**
* This function sets the $HTTPSPAGEREQUIRED global
* ( used in some parts of moodle to change some links )
* and calculate the proper wwwroot to be used
*
* By using this function properly , we can ensure 100 % https - ized pages
* at our entire discretion ( login , forgot_password , change_password )
*/
public function https_required () {
global $CFG , $HTTPSPAGEREQUIRED ;
$this -> ensure_theme_not_set ();
if ( ! empty ( $CFG -> loginhttps )) {
$HTTPSPAGEREQUIRED = true ;
$CFG -> httpswwwroot = str_replace ( 'http:' , 'https:' , $CFG -> wwwroot );
} else {
$CFG -> httpswwwroot = $CFG -> wwwroot ;
}
}
2009-05-06 08:42:13 +00:00
/// Initialisation methods =====================================================
/// These set various things up in a default way.
2009-05-06 09:14:42 +00:00
/**
* This method is called when the page first moves out of the STATE_BEFORE_HEADER
* state . This is our last change to initialise things .
*/
protected function starting_output () {
2009-07-14 05:14:45 +00:00
global $CFG ;
2009-05-07 07:05:22 +00:00
2009-07-03 09:03:50 +00:00
if ( ! during_initial_install ()) {
$this -> blocks -> load_blocks ();
2009-07-28 09:59:21 +00:00
if ( empty ( $this -> _block_actions_done )) {
2009-07-14 09:28:10 +00:00
$this -> _block_actions_done = true ;
2009-07-28 09:59:21 +00:00
if ( $this -> blocks -> process_url_actions ( $this )) {
2010-01-17 09:50:55 +00:00
redirect ( $this -> url -> out ( false ));
2009-07-28 09:59:21 +00:00
}
2009-07-14 07:18:57 +00:00
}
2009-07-20 03:04:08 +00:00
$this -> blocks -> create_all_block_instances ();
2009-05-06 09:14:42 +00:00
}
2009-07-14 05:14:45 +00:00
// If maintenance mode is on, change the page header.
if ( ! empty ( $CFG -> maintenance_enabled )) {
$this -> set_button ( '<a href="' . $CFG -> wwwroot . '/' . $CFG -> admin .
'/settings.php?section=maintenancemode">' . get_string ( 'maintenancemode' , 'admin' ) .
'</a> ' . $this -> button );
2009-07-14 07:18:57 +00:00
2009-07-14 05:14:45 +00:00
$title = $this -> title ;
if ( $title ) {
$title .= ' - ' ;
}
$this -> set_title ( $title . get_string ( 'maintenancemode' , 'admin' ));
}
2009-07-14 07:18:57 +00:00
2009-07-14 05:14:45 +00:00
// Show the messaging popup, if there are messages.
message_popup_window ();
2009-07-14 07:18:57 +00:00
$this -> initialise_standard_body_classes ();
2009-07-01 05:54:26 +00:00
}
/**
* Method for use by Moodle core to set up the theme . Do not
* use this in your own code .
*
* Make sure the right theme for this page is loaded . Tell our
* blocks_manager about the theme block regions , and then , if
2009-12-23 18:23:21 +00:00
* we are $PAGE , set up the global $OUTPUT .
2009-07-01 05:54:26 +00:00
*/
public function initialise_theme_and_output () {
2009-12-23 18:23:21 +00:00
global $OUTPUT , $PAGE , $SITE ;
2009-07-01 05:54:26 +00:00
2009-07-09 07:35:03 +00:00
if ( ! empty ( $this -> _wherethemewasinitialised )) {
return ;
}
2009-07-03 09:03:50 +00:00
if ( ! $this -> _course && ! during_initial_install ()) {
2009-07-01 05:54:26 +00:00
$this -> set_course ( $SITE );
}
if ( is_null ( $this -> _theme )) {
$themename = $this -> resolve_theme ();
$this -> _theme = theme_config :: load ( $themename );
2009-12-16 18:00:58 +00:00
$this -> _layout_options = $this -> _theme -> pagelayout_options ( $this -> pagelayout );
2009-07-01 05:54:26 +00:00
}
2009-12-16 18:00:58 +00:00
$this -> _theme -> setup_blocks ( $this -> pagelayout , $this -> blocks );
2009-07-01 05:54:26 +00:00
if ( $this === $PAGE ) {
2009-12-17 14:06:22 +00:00
$OUTPUT = $this -> get_renderer ( 'core' );
2009-07-01 05:54:26 +00:00
}
$this -> _wherethemewasinitialised = debug_backtrace ();
}
/**
* Work out the theme this page should use .
*
* This depends on numerous $CFG settings , and the properties of this page .
*
* @ return string the name of the theme that should be used on this page .
*/
protected function resolve_theme () {
global $CFG , $USER , $SESSION ;
if ( empty ( $CFG -> themeorder )) {
$themeorder = array ( 'course' , 'category' , 'session' , 'user' , 'site' );
} else {
$themeorder = $CFG -> themeorder ;
// Just in case, make sure we always use the site theme if nothing else matched.
$themeorder [] = 'site' ;
}
$mnetpeertheme = '' ;
if ( isloggedin () and isset ( $CFG -> mnet_localhost_id ) and $USER -> mnethostid != $CFG -> mnet_localhost_id ) {
require_once ( $CFG -> dirroot . '/mnet/peer.php' );
$mnetpeer = new mnet_peer ();
$mnetpeer -> set_id ( $USER -> mnethostid );
if ( $mnetpeer -> force_theme == 1 && $mnetpeer -> theme != '' ) {
$mnetpeertheme = $mnetpeer -> theme ;
}
}
$theme = '' ;
foreach ( $themeorder as $themetype ) {
switch ( $themetype ) {
case 'course' :
if ( ! empty ( $CFG -> allowcoursethemes ) and ! empty ( $this -> course -> theme )) {
return $this -> course -> theme ;
}
case 'category' :
if ( ! empty ( $CFG -> allowcategorythemes )) {
$categories = $this -> categories ;
foreach ( $categories as $category ) {
if ( ! empty ( $category -> theme )) {
return $category -> theme ;
}
}
}
case 'session' :
if ( ! empty ( $SESSION -> theme )) {
return $SESSION -> theme ;
}
case 'user' :
if ( ! empty ( $CFG -> allowuserthemes ) and ! empty ( $USER -> theme )) {
if ( $mnetpeertheme ) {
return $mnetpeertheme ;
} else {
return $USER -> theme ;
}
}
case 'site' :
if ( $mnetpeertheme ) {
return $mnetpeertheme ;
} else {
return $CFG -> theme ;
}
}
}
2009-05-06 09:14:42 +00:00
}
2009-05-06 08:38:55 +00:00
/**
* Sets -> pagetype from the script name . For example , if the script that was
* run is mod / quiz / view . php , -> pagetype will be set to 'mod-quiz-view' .
* @ param string $script the path to the script that should be used to
* initialise -> pagetype . If not passed the $SCRIPT global will be used .
* If legacy code has set $CFG -> pagepath that will be used instead , and a
* developer warning issued .
*/
2009-05-06 08:55:53 +00:00
protected function initialise_default_pagetype ( $script = null ) {
2009-05-06 08:38:55 +00:00
global $CFG , $SCRIPT ;
if ( isset ( $CFG -> pagepath )) {
debugging ( 'Some code appears to have set $CFG->pagepath. That was a horrible deprecated thing. ' .
'Don\'t do it! Try calling $PAGE->set_pagetype() instead.' );
$script = $CFG -> pagepath ;
unset ( $CFG -> pagepath );
}
2009-05-06 08:55:53 +00:00
if ( is_null ( $script )) {
2009-05-06 08:38:55 +00:00
$script = ltrim ( $SCRIPT , '/' );
$len = strlen ( $CFG -> admin );
if ( substr ( $script , 0 , $len ) == $CFG -> admin ) {
$script = 'admin' . substr ( $script , $len );
}
}
$path = str_replace ( '.php' , '' , $script );
if ( substr ( $path , - 1 ) == '/' ) {
$path .= 'index' ;
}
if ( empty ( $path ) || $path == 'index' ) {
$this -> _pagetype = 'site-index' ;
} else {
$this -> _pagetype = str_replace ( '/' , '-' , $path );
}
}
2009-05-06 08:42:13 +00:00
protected function initialise_standard_body_classes () {
2009-07-01 05:54:26 +00:00
global $CFG , $USER ;
2009-05-06 08:44:58 +00:00
2009-05-06 08:42:13 +00:00
$pagetype = $this -> pagetype ;
if ( $pagetype == 'site-index' ) {
$this -> _legacyclass = 'course' ;
} else if ( substr ( $pagetype , 0 , 6 ) == 'admin-' ) {
$this -> _legacyclass = 'admin' ;
}
$this -> add_body_class ( $this -> _legacyclass );
2010-03-25 06:38:21 +00:00
$pathbits = explode ( '-' , trim ( $pagetype ));
for ( $i = 1 ; $i < count ( $pathbits ); $i ++ ) {
$this -> add_body_class ( 'path-' . join ( '-' , array_slice ( $pathbits , 0 , $i )));
}
2009-05-06 08:44:58 +00:00
$this -> add_body_classes ( get_browser_version_classes ());
2009-05-06 08:42:13 +00:00
$this -> add_body_class ( 'dir-' . get_string ( 'thisdirection' ));
$this -> add_body_class ( 'lang-' . current_language ());
ajaxlib/require_js: MDL-16693 $PAGE->requires->... deprecates require_js etc.
There is a new implementation of require_js in lib/deprecatedlib.php,
based on $PAGE->requires.
There were a few other recently introduced functions in lib/weblib.php,
namely print_js_call, print_delayed_js_call, print_js_config and
standard_js_config. These have been removed, since they were never in
a stable branch, and all the places that used them have been changed
to use the newer $PAGE->requires->... methods.
get_require_js_code is also gone, and the evil places that were calling
it, even though it is an internal function, have been fixed.
Also, I made some minor improvements to the code I committed yesterday
for MDL-16695.
All that remains is to update all the places in core code that are
still using require_js.
(This commit also fixes the problem where the admin tree would not
start with the right categories expanded.)
2009-06-12 12:13:07 +00:00
$this -> add_body_class ( 'yui-skin-sam' ); // Make YUI happy, if it is used.
2009-05-06 08:44:58 +00:00
$this -> add_body_class ( $this -> url_to_class_name ( $CFG -> wwwroot ));
2009-12-27 12:02:04 +00:00
$this -> add_body_class ( 'pagelayout-' . $this -> _pagelayout ); // extra class describing current page layout
2009-07-03 09:03:50 +00:00
if ( ! during_initial_install ()) {
$this -> add_body_class ( 'course-' . $this -> _course -> id );
$this -> add_body_class ( 'context-' . $this -> context -> id );
2009-05-06 09:27:16 +00:00
}
2009-05-06 09:28:06 +00:00
if ( ! empty ( $this -> _cm )) {
$this -> add_body_class ( 'cmid-' . $this -> _cm -> id );
}
2009-07-03 09:03:50 +00:00
if ( ! empty ( $CFG -> allowcategorythemes )) {
2009-05-06 08:46:48 +00:00
$this -> ensure_category_loaded ();
foreach ( $this -> _categories as $catid => $notused ) {
$this -> add_body_class ( 'category-' . $catid );
}
} else {
$catid = 0 ;
if ( is_array ( $this -> _categories )) {
$catids = array_keys ( $this -> _categories );
$catid = reset ( $catids );
} else if ( ! empty ( $this -> _course -> category )) {
$catid = $this -> _course -> category ;
}
if ( $catid ) {
$this -> add_body_class ( 'category-' . $catid );
}
}
2009-05-06 08:42:13 +00:00
if ( ! isloggedin ()) {
$this -> add_body_class ( 'notloggedin' );
}
if ( ! empty ( $USER -> editing )) {
$this -> add_body_class ( 'editing' );
}
if ( ! empty ( $CFG -> blocksdrag )) {
$this -> add_body_class ( 'drag' );
}
}
2009-05-06 09:03:33 +00:00
protected function load_activity_record () {
global $DB ;
if ( is_null ( $this -> _cm )) {
return ;
}
$this -> _module = $DB -> get_record ( $this -> _cm -> modname , array ( 'id' => $this -> _cm -> instance ));
}
2009-05-06 08:46:05 +00:00
protected function ensure_category_loaded () {
if ( is_array ( $this -> _categories )) {
return ; // Already done.
}
if ( is_null ( $this -> _course )) {
throw new coding_exception ( 'Attempt to get the course category for this page before the course was set.' );
}
if ( $this -> _course -> category == 0 ) {
$this -> _categories = array ();
} else {
$this -> load_category ( $this -> _course -> category );
}
}
protected function load_category ( $categoryid ) {
global $DB ;
$category = $DB -> get_record ( 'course_categories' , array ( 'id' => $categoryid ));
if ( ! $category ) {
throw new moodle_exception ( 'unknowncategory' );
}
$this -> _categories [ $category -> id ] = $category ;
$parentcategoryids = explode ( '/' , trim ( $category -> path , '/' ));
array_pop ( $parentcategoryids );
foreach ( array_reverse ( $parentcategoryids ) as $catid ) {
$this -> _categories [ $catid ] = null ;
}
}
protected function ensure_categories_loaded () {
global $DB ;
$this -> ensure_category_loaded ();
if ( ! is_null ( end ( $this -> _categories ))) {
return ; // Already done.
}
$idstoload = array_keys ( $this -> _categories );
array_shift ( $idstoload );
$categories = $DB -> get_records_list ( 'course_categories' , 'id' , $idstoload );
foreach ( $idstoload as $catid ) {
$this -> _categories [ $catid ] = $categories [ $catid ];
}
}
2009-07-01 05:54:26 +00:00
protected function ensure_theme_not_set () {
if ( ! is_null ( $this -> _theme )) {
throw new coding_exception ( 'The theme has already been set up for this page ready for output. ' .
'Therefore, you can no longer change the theme, or anything that might affect what ' .
'the current theme is, for example, the course.' ,
'Stack trace when the theme was set up: ' . format_backtrace ( $this -> _wherethemewasinitialised ));
}
}
2009-05-06 08:44:58 +00:00
protected function url_to_class_name ( $url ) {
$bits = parse_url ( $url );
$class = str_replace ( '.' , '-' , $bits [ 'host' ]);
if ( ! empty ( $bits [ 'port' ])) {
$class .= '--' . $bits [ 'port' ];
}
if ( ! empty ( $bits [ 'path' ])) {
$path = trim ( $bits [ 'path' ], '/' );
if ( $path ) {
$class .= '--' . str_replace ( '/' , '-' , $path );
}
}
return $class ;
}
2009-05-06 09:01:42 +00:00
protected function all_editing_caps () {
$caps = $this -> _othereditingcaps ;
$caps [] = $this -> _blockseditingcap ;
return $caps ;
}
2009-05-06 08:42:13 +00:00
/// Deprecated fields and methods for backwards compatibility ==================
2009-05-06 08:38:55 +00:00
2009-05-06 08:34:32 +00:00
/**
2009-05-06 08:35:39 +00:00
* @ deprecated since Moodle 2.0 - use $PAGE -> pagetype instead .
2009-05-06 08:34:32 +00:00
* @ return string page type .
*/
public function get_type () {
debugging ( 'Call to deprecated method moodle_page::get_type. Please use $PAGE->pagetype instead.' );
return $this -> get_pagetype ();
}
2009-05-06 08:38:55 +00:00
/**
* @ deprecated since Moodle 2.0 - use $PAGE -> pagetype instead .
* @ return string this is what page_id_and_class used to return via the $getclass parameter .
*/
function get_format_name () {
return $this -> get_pagetype ();
}
2009-05-06 08:35:39 +00:00
/**
* @ deprecated since Moodle 2.0 - use $PAGE -> course instead .
* @ return object course .
*/
public function get_courserecord () {
debugging ( 'Call to deprecated method moodle_page::get_courserecord. Please use $PAGE->course instead.' );
return $this -> get_course ();
}
2009-05-06 08:38:55 +00:00
/**
* @ deprecated since Moodle 2.0
* @ return string this is what page_id_and_class used to return via the $getclass parameter .
*/
public function get_legacyclass () {
if ( is_null ( $this -> _legacyclass )) {
2009-05-06 08:42:13 +00:00
$this -> initialise_standard_body_classes ();
2009-05-06 08:38:55 +00:00
}
debugging ( 'Call to deprecated method moodle_page::get_legacyclass.' );
return $this -> _legacyclass ;
}
2009-05-06 08:53:14 +00:00
/**
2009-05-06 09:14:01 +00:00
* @ deprecated since Moodle 2.0 - use $PAGE -> blocks -> get_regions () instead
2009-05-06 08:53:14 +00:00
* @ return string the places on this page where blocks can go .
*/
function blocks_get_positions () {
2009-05-06 09:14:01 +00:00
debugging ( 'Call to deprecated method moodle_page::blocks_get_positions. Use $PAGE->blocks->get_regions() instead.' );
return $this -> blocks -> get_regions ();
2009-05-06 08:53:14 +00:00
}
/**
2009-05-06 09:14:01 +00:00
* @ deprecated since Moodle 2.0 - use $PAGE -> blocks -> get_default_region () instead
2009-05-06 08:53:14 +00:00
* @ return string the default place for blocks on this page .
*/
function blocks_default_position () {
2009-05-06 09:14:01 +00:00
debugging ( 'Call to deprecated method moodle_page::blocks_default_position. Use $PAGE->blocks->get_default_region() instead.' );
return $this -> blocks -> get_default_region ();
2009-05-06 08:53:14 +00:00
}
/**
* @ deprecated since Moodle 2.0 - no longer used .
*/
function blocks_get_default () {
debugging ( 'Call to deprecated method moodle_page::blocks_get_default. This method has no function any more.' );
}
/**
* @ deprecated since Moodle 2.0 - no longer used .
*/
function blocks_move_position ( & $instance , $move ) {
debugging ( 'Call to deprecated method moodle_page::blocks_move_position. This method has no function any more.' );
}
2009-05-06 08:55:53 +00:00
/**
* @ deprecated since Moodle 2.0 - use $this -> url -> params () instead .
* @ return array URL parameters for this page .
*/
function url_get_parameters () {
debugging ( 'Call to deprecated method moodle_page::url_get_parameters. Use $this->url->params() instead.' );
return $this -> url -> params ();
}
/**
* @ deprecated since Moodle 2.0 - use $this -> url -> params () instead .
* @ return string URL for this page without parameters .
*/
function url_get_path () {
2009-12-16 21:33:01 +00:00
debugging ( 'Call to deprecated method moodle_page::url_get_path. Use $this->url->out() instead.' );
return $this -> url -> out ();
2009-05-06 08:55:53 +00:00
}
/**
* @ deprecated since Moodle 2.0 - use $this -> url -> out () instead .
* @ return string full URL for this page .
*/
function url_get_full ( $extraparams = array ()) {
debugging ( 'Call to deprecated method moodle_page::url_get_full. Use $this->url->out() instead.' );
2010-01-17 09:50:55 +00:00
return $this -> url -> out ( true , $extraparams );
2009-05-06 08:55:53 +00:00
}
2009-05-06 09:03:03 +00:00
/**
* @ deprecated since Moodle 2.0 - just a backwards compatibility hook .
*/
function set_legacy_page_object ( $pageobject ) {
return $this -> _legacypageobject = $pageobject ;
}
/**
* @ deprecated since Moodle 2.0 - page objects should no longer be doing print_header .
* @ param $_ , ...
*/
function print_header ( $_ ) {
if ( is_null ( $this -> _legacypageobject )) {
throw new coding_exception ( 'You have called print_header on $PAGE when there is not a legacy page class present.' );
}
debugging ( 'You should not longer be doing print_header via a page class.' , DEBUG_DEVELOPER );
$args = func_get_args ();
call_user_func_array ( array ( $this -> _legacypageobject , 'print_header' ), $args );
}
/**
* @ deprecated since Moodle 2.0
* @ return the 'page id' . This concept no longer exists .
*/
function get_id () {
debugging ( 'Call to deprecated method moodle_page::get_id(). It should not be necessary any more.' , DEBUG_DEVELOPER );
if ( ! is_null ( $this -> _legacypageobject )) {
return $this -> _legacypageobject -> get_id ();
}
return 0 ;
}
2009-05-06 09:03:33 +00:00
2009-05-06 09:11:07 +00:00
/**
* @ deprecated since Moodle 2.0
* @ return the 'page id' . This concept no longer exists .
*/
function get_pageid () {
debugging ( 'Call to deprecated method moodle_page::get_pageid(). It should not be necessary any more.' , DEBUG_DEVELOPER );
if ( ! is_null ( $this -> _legacypageobject )) {
return $this -> _legacypageobject -> get_id ();
}
return 0 ;
}
2009-05-06 09:03:33 +00:00
/**
* @ deprecated since Moodle 2.0 - user $PAGE -> cm instead .
* @ return $this -> cm ;
*/
function get_modulerecord () {
return $this -> cm ;
}
2009-09-23 06:05:36 +00:00
public function has_set_url () {
return ( $this -> _url !== null );
}
2009-05-06 08:55:53 +00:00
}
2009-05-06 08:27:12 +00:00
/**
* @ deprecated since Moodle 2.0
2009-05-06 09:03:03 +00:00
* Not needed any more .
2009-05-06 08:27:12 +00:00
* @ param $path the folder path
* @ return array an array of page types .
*/
2005-02-28 04:01:30 +00:00
function page_import_types ( $path ) {
global $CFG ;
2009-05-06 08:27:12 +00:00
debugging ( 'Call to deprecated function page_import_types.' , DEBUG_DEVELOPER );
2005-02-28 04:01:30 +00:00
}
2005-02-02 02:32:40 +00:00
/**
2009-05-06 08:38:55 +00:00
* @ deprecated since Moodle 2.0
2009-05-06 09:03:03 +00:00
* Do not use this any more . The global $PAGE is automatically created for you .
* If you need custom behaviour , you should just set properties of that object .
2009-05-06 08:38:55 +00:00
* @ param integer $instance legacy page instance id .
* @ return the global $PAGE object .
2005-02-02 02:32:40 +00:00
*/
function page_create_instance ( $instance ) {
2009-05-06 09:25:54 +00:00
global $PAGE ;
2009-05-06 08:38:55 +00:00
return page_create_object ( $PAGE -> pagetype , $instance );
2005-02-02 02:32:40 +00:00
}
2004-11-29 04:19:05 +00:00
/**
2009-05-06 09:03:03 +00:00
* @ deprecated since Moodle 2.0
* Do not use this any more . The global $PAGE is automatically created for you .
* If you need custom behaviour , you should just set properties of that object .
2004-11-29 04:19:05 +00:00
*/
function page_create_object ( $type , $id = NULL ) {
2009-05-06 09:03:33 +00:00
global $CFG , $PAGE , $SITE , $ME ;
2009-05-06 09:03:03 +00:00
debugging ( 'Call to deprecated function page_create_object.' , DEBUG_DEVELOPER );
2005-01-28 17:03:57 +00:00
2004-11-29 04:19:05 +00:00
$data = new stdClass ;
$data -> pagetype = $type ;
2009-05-06 09:03:33 +00:00
$data -> pageid = $id ;
2004-11-29 04:19:05 +00:00
$classname = page_map_class ( $type );
2009-05-06 09:11:07 +00:00
if ( ! $classname ) {
return $PAGE ;
}
2009-05-06 08:55:53 +00:00
$legacypage = new $classname ;
$legacypage -> init_quick ( $data );
2009-05-06 08:46:48 +00:00
$course = $PAGE -> course ;
if ( $course -> id != $SITE -> id ) {
2009-05-06 08:55:53 +00:00
$legacypage -> set_course ( $course );
2009-05-06 08:46:48 +00:00
} else {
try {
$category = $PAGE -> category ;
} catch ( coding_exception $e ) {
// Was not set before, so no need to try to set it again.
$category = false ;
}
if ( $category ) {
2009-05-06 08:55:53 +00:00
$legacypage -> set_category_by_id ( $category -> id );
2009-05-06 08:46:48 +00:00
} else {
2009-05-06 08:55:53 +00:00
$legacypage -> set_course ( $SITE );
2009-05-06 08:46:48 +00:00
}
}
2009-05-07 08:55:10 +00:00
2009-05-06 09:03:03 +00:00
$legacypage -> set_pagetype ( $type );
2009-05-06 09:03:33 +00:00
$legacypage -> set_url ( $ME );
$PAGE -> set_url ( str_replace ( $CFG -> wwwroot . '/' , '' , $legacypage -> url_get_full ()));
2009-05-06 09:03:03 +00:00
$PAGE -> set_pagetype ( $type );
$PAGE -> set_legacy_page_object ( $legacypage );
return $PAGE ;
2004-11-29 04:19:05 +00:00
}
/**
2009-05-06 09:03:03 +00:00
* @ deprecated since Moodle 2.0
* You should not be writing page subclasses any more . Just set properties on the
* global $PAGE object to control its behaviour .
2004-11-29 04:19:05 +00:00
*/
function page_map_class ( $type , $classname = NULL ) {
2005-01-28 17:03:57 +00:00
global $CFG ;
2009-05-06 09:03:03 +00:00
static $mappings = array (
PAGE_COURSE_VIEW => 'page_course' ,
);
2004-11-29 04:19:05 +00:00
2005-01-28 17:03:57 +00:00
if ( ! empty ( $type ) && ! empty ( $classname )) {
2004-11-29 04:19:05 +00:00
$mappings [ $type ] = $classname ;
}
2005-01-28 17:03:57 +00:00
if ( ! isset ( $mappings [ $type ])) {
2006-09-13 09:45:07 +00:00
debugging ( 'Page class mapping requested for unknown type: ' . $type );
2009-05-06 09:11:07 +00:00
return null ;
} else if ( empty ( $classname ) && ! class_exists ( $mappings [ $type ])) {
2006-09-13 09:45:07 +00:00
debugging ( 'Page class mapping for id "' . $type . '" exists but class "' . $mappings [ $type ] . '" is not defined' );
2009-05-06 09:11:07 +00:00
return null ;
2004-11-29 04:19:05 +00:00
}
return $mappings [ $type ];
}
2004-11-08 19:36:07 +00:00
/**
2009-05-06 09:03:03 +00:00
* @ deprecated since Moodle 2.0
2004-11-08 19:36:07 +00:00
* Parent class from which all Moodle page classes derive
*
2009-05-26 03:23:32 +00:00
* @ package moodlecore
* @ subpackage pages
* @ copyright 1999 onwards Martin Dougiamas { @ link http :// moodle . com }
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
2004-11-08 19:36:07 +00:00
*/
2009-05-06 08:29:22 +00:00
class page_base extends moodle_page {
2004-11-10 16:43:57 +00:00
/**
* The numeric identifier of the page being described .
* @ var int $id
*/
2004-11-08 19:36:07 +00:00
var $id = NULL ;
2004-11-10 16:43:57 +00:00
/// Class Functions
2004-11-12 18:39:25 +00:00
// HTML OUTPUT SECTION
// SELF-REPORTING SECTION
// Simple stuff, do not override this.
2004-11-08 19:36:07 +00:00
function get_id () {
return $this -> id ;
}
2004-11-12 18:39:25 +00:00
// Initialize the data members of the parent class
2004-11-08 19:36:07 +00:00
function init_quick ( $data ) {
$this -> id = $data -> pageid ;
}
2004-11-12 18:39:25 +00:00
function init_full () {
}
2004-11-08 19:36:07 +00:00
}
/**
2009-05-06 09:03:03 +00:00
* @ deprecated since Moodle 2.0
2009-05-07 07:05:22 +00:00
* Class that models the behavior of a moodle course .
* Although this does nothing , this class declaration should be left for now
* since there may be legacy class doing class page_ ... extends page_course
2004-11-08 19:36:07 +00:00
*
2009-05-26 03:23:32 +00:00
* @ package moodlecore
* @ subpackage pages
* @ copyright 1999 onwards Martin Dougiamas { @ link http :// moodle . com }
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
2004-11-08 19:36:07 +00:00
*/
2004-11-25 17:23:57 +00:00
class page_course extends page_base {
2004-11-08 19:36:07 +00:00
}
2005-02-01 07:12:39 +00:00
/**
2009-05-06 09:03:03 +00:00
* @ deprecated since Moodle 2.0
2005-02-09 15:22:16 +00:00
* Class that models the common parts of all activity modules
2005-02-01 07:12:39 +00:00
*
2009-05-26 03:23:32 +00:00
* @ package moodlecore
* @ subpackage pages
* @ copyright 1999 onwards Martin Dougiamas { @ link http :// moodle . com }
* @ license http :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
2005-02-01 07:12:39 +00:00
*/
2005-02-09 15:22:16 +00:00
class page_generic_activity extends page_base {
2009-05-07 07:05:22 +00:00
// Although this function is deprecated, it should be left here because
// people upgrading legacy code need to copy it. See
2009-05-06 09:26:46 +00:00
// http://docs.moodle.org/en/Development:Migrating_your_code_code_to_the_2.0_rendering_API
2007-07-05 04:40:48 +00:00
function print_header ( $title , $morenavlinks = NULL , $bodytags = '' , $meta = '' ) {
2009-09-03 06:59:25 +00:00
global $USER , $CFG , $PAGE , $OUTPUT ;
2009-05-06 08:27:12 +00:00
2007-04-16 20:48:48 +00:00
$this -> init_full ();
$replacements = array (
'%fullname%' => format_string ( $this -> activityrecord -> name )
);
foreach ( $replacements as $search => $replace ) {
$title = str_replace ( $search , $replace , $title );
}
2009-05-06 08:27:12 +00:00
2009-12-23 02:45:22 +00:00
$buttons = '<table><tr><td>' . $OUTPUT -> update_module_button ( $this -> modulerecord -> id , $this -> activityname ) . '</td>' ;
2009-05-06 09:02:48 +00:00
if ( $this -> user_allowed_editing () && ! empty ( $CFG -> showblocksonmodpages )) {
2010-02-11 13:27:02 +00:00
$buttons .= '<td><form method="get" action="view.php"><div>' .
2009-05-06 09:02:48 +00:00
'<input type="hidden" name="id" value="' . $this -> modulerecord -> id . '" />' .
'<input type="hidden" name="edit" value="' . ( $this -> user_is_editing () ? 'off' : 'on' ) . '" />' .
'<input type="submit" value="' . get_string ( $this -> user_is_editing () ? 'blockseditoff' : 'blocksediton' ) . '" /></div></form></td>' ;
2007-04-16 20:48:48 +00:00
}
2009-05-06 09:02:48 +00:00
$buttons .= '</tr></table>' ;
2009-05-06 08:27:12 +00:00
2009-09-03 06:59:25 +00:00
if ( ! empty ( $morenavlinks ) && is_array ( $morenavlinks )) {
foreach ( $morenavlinks as $navitem ) {
if ( is_array ( $navitem ) && array_key_exists ( 'name' , $navitem )) {
$link = null ;
if ( array_key_exists ( 'link' , $navitem )) {
$link = $navitem [ 'link' ];
}
2009-09-04 03:12:01 +00:00
$PAGE -> navbar -> add ( $navitem [ 'name' ], $link );
2009-09-03 06:59:25 +00:00
}
}
2007-10-12 15:55:49 +00:00
}
2009-09-03 06:59:25 +00:00
$PAGE -> set_title ( $title );
$PAGE -> set_heading ( $this -> course -> fullname );
$PAGE -> set_button ( $buttons );
2009-09-04 03:12:01 +00:00
echo $OUTPUT -> header ();
2007-04-16 20:48:48 +00:00
}
2005-02-09 15:22:16 +00:00
}