From 0a5b9e79e38059ecb5a280a339fd680ae99418e8 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Mon, 18 Jun 2012 16:10:15 +0800 Subject: [PATCH] MDL-33121 Book Module: removing prev/next value from book_preload_chapters and more code cleaning --- mod/book/edit_form.php | 16 +++++++++++----- mod/book/lib.php | 5 +++-- mod/book/locallib.php | 10 ---------- mod/book/tool/exportimscp/lib.php | 1 - mod/book/tool/importhtml/lib.php | 1 - mod/book/tool/print/lib.php | 4 +--- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/mod/book/edit_form.php b/mod/book/edit_form.php index c62d66744117e..afd04909ebddd 100644 --- a/mod/book/edit_form.php +++ b/mod/book/edit_form.php @@ -29,17 +29,15 @@ class book_chapter_edit_form extends moodleform { function definition() { + global $CFG; $chapter = $this->_customdata['chapter']; $options = $this->_customdata['options']; //Disabled subchapter option when editing first node $disabledmsg = null; - $disabledarr = null; - - if (!$chapter->id && $chapter->pagenum == 1 || $chapter->pagenum == 1) { + if ($chapter->pagenum == 1) { $disabledmsg = get_string('subchapternotice', 'book'); - $disabledarr = array('group' => 1, 'disabled' => 'disabled'); } $mform = $this->_form; @@ -50,7 +48,7 @@ function definition() { $mform->setType('title', PARAM_RAW); $mform->addRule('title', null, 'required', null, 'client'); - $mform->addElement('advcheckbox', 'subchapter', get_string('subchapter', 'mod_book'), $disabledmsg, $disabledarr); + $mform->addElement('advcheckbox', 'subchapter', get_string('subchapter', 'mod_book'), $disabledmsg); $mform->addElement('editor', 'content_editor', get_string('content', 'mod_book'), null, $options); $mform->setType('content_editor', PARAM_RAW); @@ -70,4 +68,12 @@ function definition() { // set the defaults $this->set_data($chapter); } + + function definition_after_data(){ + $mform = $this->_form; + $pagenum = $mform->getElement('pagenum'); + if ($pagenum->getValue() == 1) { + $mform->hardFreeze('subchapter'); + } + } } diff --git a/mod/book/lib.php b/mod/book/lib.php index 7ba75b61138f3..4c3cde3eb2dc1 100644 --- a/mod/book/lib.php +++ b/mod/book/lib.php @@ -29,6 +29,7 @@ * @return array */ function book_get_numbering_types() { + global $CFG; // required for the include require_once(dirname(__FILE__).'/locallib.php'); @@ -215,6 +216,7 @@ function book_scale_used_anywhere($scaleid) { * @return array */ function book_get_view_actions() { + global $CFG; // necessary for includes $return = array('view', 'view all'); @@ -239,6 +241,7 @@ function book_get_view_actions() { * @return array */ function book_get_post_actions() { + global $CFG; // necessary for includes $return = array('update'); @@ -289,11 +292,9 @@ function book_supports($feature) { * @return void */ function book_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $booknode) { - global $USER, $PAGE; $plugins = get_plugin_list('booktool'); - foreach ($plugins as $plugin => $dir) { if (file_exists("$dir/lib.php")) { require_once("$dir/lib.php"); diff --git a/mod/book/locallib.php b/mod/book/locallib.php index d089abf7339f3..a4c04877f1873 100644 --- a/mod/book/locallib.php +++ b/mod/book/locallib.php @@ -24,8 +24,6 @@ defined('MOODLE_INTERNAL') || die; -global $CFG; - require_once(dirname(__FILE__).'/lib.php'); require_once($CFG->libdir.'/filelib.php'); @@ -113,19 +111,11 @@ function book_preload_chapters($book) { } } - // assigning previous and next page id - $ch->prev = $prev; - $ch->next = null; - if ($prev) { - $chapters[$prev]->next = $ch->id; - } - if ($oldch->subchapter != $ch->subchapter or $oldch->pagenum != $ch->pagenum or $oldch->hidden != $ch->hidden) { // update only if something changed $DB->update_record('book_chapters', $ch); } $chapters[$id] = $ch; - $prev = $ch->id; } return $chapters; diff --git a/mod/book/tool/exportimscp/lib.php b/mod/book/tool/exportimscp/lib.php index 620b524c6110a..732275f7f43b2 100644 --- a/mod/book/tool/exportimscp/lib.php +++ b/mod/book/tool/exportimscp/lib.php @@ -31,7 +31,6 @@ * @param navigation_node $node The node to add module settings to */ function booktool_exportimscp_extend_settings_navigation(settings_navigation $settings, navigation_node $node) { - global $PAGE; if (has_capability('booktool/exportimscp:export', $PAGE->cm->context)) { diff --git a/mod/book/tool/importhtml/lib.php b/mod/book/tool/importhtml/lib.php index 09d032f3e0cd5..53ad230222cd4 100644 --- a/mod/book/tool/importhtml/lib.php +++ b/mod/book/tool/importhtml/lib.php @@ -31,7 +31,6 @@ * @param navigation_node $node The node to add module settings to */ function booktool_importhtml_extend_settings_navigation(settings_navigation $settings, navigation_node $node) { - global $PAGE; if (has_capability('booktool/importhtml:import', $PAGE->cm->context)) { diff --git a/mod/book/tool/print/lib.php b/mod/book/tool/print/lib.php index f3b2f8cce8ded..ffa60de10d851 100644 --- a/mod/book/tool/print/lib.php +++ b/mod/book/tool/print/lib.php @@ -31,11 +31,9 @@ * @param navigation_node $node The node to add module settings to */ function booktool_print_extend_settings_navigation(settings_navigation $settings, navigation_node $node) { - - global $PAGE; + global $USER, $PAGE, $CFG, $DB, $OUTPUT; $params = $PAGE->url->params(); - if (empty($params['id']) or empty($params['chapterid'])) { return; }