Skip to content

Commit

Permalink
MDL-33121 Book Module: removing prev/next value from book_preload_cha…
Browse files Browse the repository at this point in the history
…pters and more code cleaning
  • Loading branch information
Rossiani Wijaya committed Jun 18, 2012
1 parent fb90975 commit 0a5b9e7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 22 deletions.
16 changes: 11 additions & 5 deletions mod/book/edit_form.php
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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');
}
}
}
5 changes: 3 additions & 2 deletions mod/book/lib.php
Expand Up @@ -29,6 +29,7 @@
* @return array
*/
function book_get_numbering_types() {
global $CFG; // required for the include

require_once(dirname(__FILE__).'/locallib.php');

Expand Down Expand Up @@ -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');

Expand 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');

Expand Down Expand Up @@ -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");
Expand Down
10 changes: 0 additions & 10 deletions mod/book/locallib.php
Expand Up @@ -24,8 +24,6 @@

defined('MOODLE_INTERNAL') || die;

global $CFG;

require_once(dirname(__FILE__).'/lib.php');
require_once($CFG->libdir.'/filelib.php');

Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion mod/book/tool/exportimscp/lib.php
Expand Up @@ -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)) {
Expand Down
1 change: 0 additions & 1 deletion mod/book/tool/importhtml/lib.php
Expand Up @@ -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)) {
Expand Down
4 changes: 1 addition & 3 deletions mod/book/tool/print/lib.php
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0a5b9e7

Please sign in to comment.