From 55815b288dd54a879d760a5523a0955c39a5dfbf Mon Sep 17 00:00:00 2001 From: defacer Date: Wed, 9 Feb 2005 15:05:14 +0000 Subject: [PATCH] Streamlining class page_quiz, fixing things, removing needless comments. --- lib/pagelib.php | 76 +++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 60 deletions(-) diff --git a/lib/pagelib.php b/lib/pagelib.php index df1fb73fcd0..7ca12b5a469 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -495,7 +495,7 @@ class page_course extends page_base { } /** - * Class that models the behavior of a moodle mod + * Class that models the behavior of a moodle quiz * * @author Jon Papaioannou * @package pages @@ -503,15 +503,10 @@ class page_course extends page_base { class page_quiz extends page_base { - // Any data we might need to store specifically about ourself should be declared here. - // After init_full() is called for the first time, ALL of these variables should be - // initialized correctly and ready for use. var $courserecord = NULL; var $modulerecord = NULL; var $quizrecord = NULL; - // Do any validation of the officially recognized bits of the data and forward to parent. - // Do NOT load up "expensive" resouces (e.g. SQL data) here! function init_quick($data) { if(empty($data->pageid)) { error('Cannot quickly initialize page: empty course id'); @@ -519,10 +514,6 @@ class page_quiz extends page_base { parent::init_quick($data); } - // Here you should load up all heavy-duty data for your page. Basically everything that - // does not NEED to be loaded for the class to make basic decisions should NOT be loaded - // in init_quick() and instead deferred here. Of course this function had better recognize - // $this->full_init_done to prevent wasteful multiple-time data retrieval. function init_full() { if($this->full_init_done) { return; @@ -543,26 +534,16 @@ class page_quiz extends page_base { $this->full_init_done = true; } - // USER-RELATED THINGS - - // When is a user said to have "editing rights" in this page? This would have something - // to do with roles, in the future. function user_allowed_editing() { $this->init_full(); return isteacheredit($this->modulerecord->course); } - // Is the user actually editing this page right now? This would have something - // to do with roles, in the future. function user_is_editing() { $this->init_full(); return isediting($this->modulerecord->course); } - // HTML OUTPUT SECTION - - // This function prints out the common part of the page's header. - // You should NEVER print the header "by hand" in other code. function print_header($title, $morebreadcrumbs = NULL) { global $USER, $CFG; @@ -596,70 +577,45 @@ class page_quiz extends page_base { } } - // The "Editing On" button will be appearing only in the "main" course screen - // (i.e., no breadcrumbs other than the default one added inside this function) - $button = empty($morebreadcrumbs) ? update_course_icon($this->courserecord->id) : ' '; + if(empty($morebreadcrumbs) && $this->user_allowed_editing()) { + $buttons = ''. + '
'. + ''. + '
'. + update_module_button($this->modulerecord->id, $this->courserecord->id, get_string('modulename', 'quiz')). + '
'. + ''. + ''. + '
'; + } + else { + $buttons = ' '; + } + print_header($title, $this->courserecord->fullname, $crumbtext, '', '', true, $buttons, navmenu($this->courserecord, $this->modulerecord)); - $loggedinas = '

'. user_login_string($this->courserecord, $USER) .'

'; - print_header($title, $this->courserecord->fullname, $crumbtext, - '', '', true, $button, $loggedinas); } - // SELF-REPORTING SECTION - - // This is hardwired here so the factory function page_create_object() can be sure there was no mistake. - // Also, it doubles as a way to let others inquire about our type. function get_type() { return PAGE_QUIZ_VIEW; } - // This should return a fully qualified path to the URL which is responsible for displaying us. function url_get_path() { global $CFG; return $CFG->wwwroot .'/mod/quiz/view.php'; } - // This should return an associative array of any GET/POST parameters that are needed by the URL - // which displays us to make it work. If none are needed, return an empty array. function url_get_parameters() { $this->init_full(); return array('id' => $this->modulerecord->id); } - // BLOCKS RELATED SECTION - - // Which are the positions in this page which support blocks? Return an array containing their identifiers. - // BE CAREFUL, ORDER DOES MATTER! In textual representations, lists of blocks in a page use the ':' character - // to delimit different positions in the page. The part before the first ':' in such a representation will map - // directly to the first item of the array you return here, the second to the next one and so on. This way, - // you can add more positions in the future without interfering with legacy textual representations. function blocks_get_positions() { return array(BLOCK_POS_LEFT); } - // When a new block is created in this page, which position should it go to? function blocks_default_position() { return BLOCK_POS_LEFT; } - - // When we are creating a new page, use the data at your disposal to provide a textual representation of the - // blocks that are going to get added to this new page. Delimit block names with commas (,) and use double - // colons (:) to delimit between block positions in the page. See blocks_get_positions() for additional info. - function blocks_get_default() { - global $CFG; - return ''; - } - - // Given an instance of a block in this page and the direction in which we want to move it, where is - // it going to go? Return the identifier of the instance's new position. This allows us to tell blocklib - // how we want the blocks to move around in this page in an arbitrarily complex way. If the move as given - // does not make sense, make sure to return the instance's original position. - // - // Since this is going to get called a LOT, pass the instance by reference purely for speed. Do **NOT** - // modify its data in any way, this will actually confuse blocklib!!! - function blocks_move_position(&$instance, $move) { - return $instance->position; - } } ?>