Commit 29656fe2 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

MDL-32709 book: coding style, deprecated and minor fixes

parent 1fc9e895
......@@ -55,7 +55,7 @@ if ($confirm) { // the operation was confirmed.
if (!$chapter->subchapter) { // Delete all its sub-chapters if any
$chapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum', 'id, subchapter');
$found = false;
foreach($chapters as $ch) {
foreach ($chapters as $ch) {
if ($ch->id == $chapter->id) {
$found = true;
} else if ($found and $ch->subchapter) {
......@@ -91,4 +91,4 @@ $continue = new moodle_url('/mod/book/delete.php', array('id'=>$cm->id, 'chapter
$cancel = new moodle_url('/mod/book/view.php', array('id'=>$cm->id, 'chapterid'=>$chapter->id));
echo $OUTPUT->confirm("<strong>$chapter->title</strong><p>$strconfirm</p>", $continue, $cancel);
echo $OUTPUT->footer();
echo $OUTPUT->footer();
\ No newline at end of file
......@@ -122,4 +122,3 @@ if (debugging()) {
$mform->display();
echo $OUTPUT->footer();
......@@ -93,10 +93,7 @@ function book_update_instance($data, $mform) {
}
/**
*
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
* Delete book instance by activity id
*
* @param int $id
* @return bool success
......@@ -138,7 +135,7 @@ function book_user_outline($course, $user, $mod, $book) {
return $result;
}
return NULL;
return null;
}
/**
......@@ -187,22 +184,6 @@ function book_grades($bookid) {
return null;
}
/**
* Returns the users with data in one book
*
* @todo deprecated - to be deleted in 2.2
* @param int $bookid
* @return array
*/
function book_get_participants($bookid) {
// Must return an array of user records (all data) who are participants
// for a given instance of book. Must include every user involved
// in the instance, independent of his role (student, teacher, admin...)
// See other modules as example.
return false;
}
/**
* This function returns if a scale is being used by one book
* it it has support for grading and scales. Commented code should be
......@@ -213,7 +194,7 @@ function book_get_participants($bookid) {
* @param int $scaleid
* @return boolean True if the scale is used by any journal
*/
function book_scale_used($bookid,$scaleid) {
function book_scale_used($bookid, $scaleid) {
return false;
}
......@@ -239,7 +220,7 @@ function book_get_view_actions() {
$return = array('view', 'view all');
$plugins = get_plugin_list('booktool');
foreach($plugins as $plugin=>$dir) {
foreach ($plugins as $plugin => $dir) {
if (file_exists("$dir/lib.php")) {
require_once("$dir/lib.php");
}
......@@ -264,7 +245,7 @@ function book_get_post_actions() {
$return = array('update');
$plugins = get_plugin_list('booktool');
foreach($plugins as $plugin=>$dir) {
foreach ($plugins as $plugin => $dir) {
if (file_exists("$dir/lib.php")) {
require_once("$dir/lib.php");
}
......@@ -296,6 +277,7 @@ function book_supports($feature) {
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
......@@ -320,7 +302,7 @@ function book_extend_settings_navigation(settings_navigation $settingsnav, navig
}
$plugins = get_plugin_list('booktool');
foreach($plugins as $plugin=>$dir) {
foreach ($plugins as $plugin => $dir) {
if (file_exists("$dir/lib.php")) {
require_once("$dir/lib.php");
}
......@@ -360,7 +342,7 @@ function book_get_file_areas($course, $cm, $context) {
}
/**
* File browsing support for book module ontent area.
* File browsing support for book module chapter area.
* @param object $browser
* @param object $areas
* @param object $course
......@@ -385,7 +367,7 @@ function book_get_file_info($browser, $areas, $course, $cm, $context, $filearea,
return null;
}
require_once("$CFG->dirroot/mod/book/locallib.php");
require_once(dirname(__FILE__).'/locallib.php');
if (is_null($itemid)) {
return new book_file_info($browser, $course, $cm, $context, $areas, $filearea);
......@@ -411,15 +393,16 @@ function book_get_file_info($browser, $areas, $course, $cm, $context, $filearea,
/**
* Serves the book attachments. Implements needed access control ;-)
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @param stdClass $course course object
* @param cm_info $cm course module object
* @param context $context context object
* @param string $filearea file area
* @param array $args extra arguments
* @param bool $forcedownload whether or not force download
* @param array $options additional options affecting the file serving
* @return bool false if file not found, does not return if found - just send the file
*/
function book_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
function book_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) {
global $DB;
if ($context->contextlevel != CONTEXT_MODULE) {
......@@ -458,7 +441,7 @@ function book_pluginfile($course, $cm, $context, $filearea, $args, $forcedownloa
}
// finally send the file
send_stored_file($file, 360, 0, false);
send_stored_file($file, 360, 0, $forcedownload, $options);
}
/**
......
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/mod/book/lib.php');
require_once(dirname(__FILE__).'/lib.php');
require_once($CFG->libdir.'/filelib.php');
define('BOOK_NUM_NONE', '0');
......@@ -58,7 +58,7 @@ function book_preload_chapters($book) {
$pagenum = 0; // chapter sort
$i = 0; // main chapter num
$j = 0; // subchapter num
foreach($chapters as $id=>$ch) {
foreach ($chapters as $id => $ch) {
$oldch = clone($ch);
$pagenum++;
$ch->pagenum = $pagenum;
......@@ -224,25 +224,24 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
$context = context_module::instance($cm->id);
switch ($book->numbering) {
case BOOK_NUM_NONE:
$toc .= '<div class="book_toc_none">';
break;
case BOOK_NUM_NUMBERS:
$toc .= '<div class="book_toc_numbered">';
break;
case BOOK_NUM_BULLETS:
$toc .= '<div class="book_toc_bullets">';
break;
case BOOK_NUM_INDENTED:
$toc .= '<div class="book_toc_indented">';
break;
case BOOK_NUM_NONE:
$toc .= '<div class="book_toc_none">';
break;
case BOOK_NUM_NUMBERS:
$toc .= '<div class="book_toc_numbered">';
break;
case BOOK_NUM_BULLETS:
$toc .= '<div class="book_toc_bullets">';
break;
case BOOK_NUM_INDENTED:
$toc .= '<div class="book_toc_indented">';
break;
}
if ($edit) { // Teacher's TOC
$toc .= '<ul>';
$i = 0;
foreach($chapters as $ch) {
foreach ($chapters as $ch) {
$i++;
$title = trim(format_string($ch->title, true, array('context'=>$context)));
if (!$ch->subchapter) {
......@@ -281,19 +280,27 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
}
$toc .= '&nbsp;&nbsp;';
if ($i != 1) {
$toc .= ' <a title="'.get_string('up').'" href="move.php?id='.$cm->id.'&amp;chapterid='.$ch->id.'&amp;up=1&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/up').'" class="iconsmall" alt="'.get_string('up').'" /></a>';
$toc .= ' <a title="'.get_string('up').'" href="move.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;up=1&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/up').'" class="iconsmall" alt="'.get_string('up').'" /></a>';
}
if ($i != count($chapters)) {
$toc .= ' <a title="'.get_string('down').'" href="move.php?id='.$cm->id.'&amp;chapterid='.$ch->id.'&amp;up=0&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/down').'" class="iconsmall" alt="'.get_string('down').'" /></a>';
$toc .= ' <a title="'.get_string('down').'" href="move.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;up=0&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/down').'" class="iconsmall" alt="'.get_string('down').'" /></a>';
}
$toc .= ' <a title="'.get_string('edit').'" href="edit.php?cmid='.$cm->id.'&amp;id='.$ch->id.'"><img src="'.$OUTPUT->pix_url('t/edit').'" class="iconsmall" alt="'.get_string('edit').'" /></a>';
$toc .= ' <a title="'.get_string('delete').'" href="delete.php?id='.$cm->id.'&amp;chapterid='.$ch->id.'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/delete').'" class="iconsmall" alt="'.get_string('delete').'" /></a>';
$toc .= ' <a title="'.get_string('edit').'" href="edit.php?cmid='.$cm->id.'&amp;id='.$ch->id.'"><img src="'.
$OUTPUT->pix_url('t/edit').'" class="iconsmall" alt="'.get_string('edit').'" /></a>';
$toc .= ' <a title="'.get_string('delete').'" href="delete.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/delete').'" class="iconsmall" alt="'.get_string('delete').'" /></a>';
if ($ch->hidden) {
$toc .= ' <a title="'.get_string('show').'" href="show.php?id='.$cm->id.'&amp;chapterid='.$ch->id.'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/show').'" class="iconsmall" alt="'.get_string('show').'" /></a>';
$toc .= ' <a title="'.get_string('show').'" href="show.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/show').'" class="iconsmall" alt="'.get_string('show').'" /></a>';
} else {
$toc .= ' <a title="'.get_string('hide').'" href="show.php?id='.$cm->id.'&amp;chapterid='.$ch->id.'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/hide').'" class="iconsmall" alt="'.get_string('hide').'" /></a>';
$toc .= ' <a title="'.get_string('hide').'" href="show.php?id='.$cm->id.'&amp;chapterid='.$ch->id.
'&amp;sesskey='.$USER->sesskey.'"><img src="'.$OUTPUT->pix_url('t/hide').'" class="iconsmall" alt="'.get_string('hide').'" /></a>';
}
$toc .= ' <a title="'.get_string('addafter', 'mod_book').'" href="edit.php?cmid='.$cm->id.'&amp;pagenum='.$ch->pagenum.'&amp;subchapter='.$ch->subchapter.'"><img src="'.$OUTPUT->pix_url('add', 'mod_book').'" class="iconsmall" alt="'.get_string('addafter', 'mod_book').'" /></a>';
$toc .= ' <a title="'.get_string('addafter', 'mod_book').'" href="edit.php?cmid='.$cm->id.
'&amp;pagenum='.$ch->pagenum.'&amp;subchapter='.$ch->subchapter.'"><img src="'.
$OUTPUT->pix_url('add', 'mod_book').'" class="iconsmall" alt="'.get_string('addafter', 'mod_book').'" /></a>';
$toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
$first = 0;
......@@ -301,7 +308,7 @@ function book_get_toc($chapters, $chapter, $book, $cm, $edit) {
$toc .= '</ul></li></ul>';
} else { // Normal students view
$toc .= '<ul>';
foreach($chapters as $ch) {
foreach ($chapters as $ch) {
$title = trim(format_string($ch->title, true, array('context'=>$context)));
if (!$ch->hidden) {
if (!$ch->subchapter) {
......@@ -420,7 +427,7 @@ class book_file_info extends file_info {
$children = array();
$chapters = $DB->get_records('book_chapters', array('bookid'=>$this->cm->instance), 'pagenum', 'id, pagenum');
foreach ($chapters as $itemid=>$unused) {
foreach ($chapters as $itemid => $unused) {
if ($child = $this->browser->get_file_info($this->context, 'mod_book', $this->filearea, $itemid)) {
$children[] = $child;
}
......
......@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/mod/book/locallib.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once($CFG->dirroot.'/course/moodleform_mod.php');
class mod_book_mod_form extends moodleform_mod {
......@@ -74,6 +74,4 @@ class mod_book_mod_form extends moodleform_mod {
$this->add_action_buttons();
}
}
......@@ -22,7 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php');
......@@ -98,7 +97,7 @@ if ($chapters[$chs]->subchapter) { // Moving single subchapter up or down.
$nothing = 1; // Already first.
} else {
$te = $chs - 1;
for($i = $chs-1; $i >= 1; $i--) {
for ($i = $chs-1; $i >= 1; $i--) {
if ($chapters[$i]->subchapter) {
$ts = $i;
} else {
......@@ -113,7 +112,7 @@ if ($chapters[$chs]->subchapter) { // Moving single subchapter up or down.
} else {
$ts = $che + 1;
$found = 0;
for($i = $che+1; $i <= count($chapters); $i++) {
for ($i = $che+1; $i <= count($chapters); $i++) {
if ($chapters[$i]->subchapter) {
$te = $i;
} else {
......
......@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
require_once("$CFG->dirroot/mod/book/lib.php");
require_once(dirname(__FILE__).'/lib.php');
// General settings
......
......@@ -52,7 +52,7 @@ $DB->update_record('book_chapters', $chapter);
if (!$chapter->subchapter) {
$chapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum', 'id, subchapter, hidden');
$found = 0;
foreach($chapters as $ch) {
foreach ($chapters as $ch) {
if ($ch->id == $chapter->id) {
$found = 1;
} else if ($found and $ch->subchapter) {
......
......@@ -24,10 +24,7 @@
defined('MOODLE_INTERNAL') || die;
$module->version = 2012042100; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2011070100; // Requires this Moodle version
$module->cron = 0; // Period for cron to check this module (secs)
$module->component = 'mod_book'; // Full name of the plugin (used for diagnostics)
$module->maturity = MATURITY_STABLE;
$module->release = "2.1 (20111105)"; // User-friendly version number
$module->version = 2012051500; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2012051100; // Requires this Moodle version
$module->cron = 0; // Period for cron to check this module (secs)
......@@ -75,7 +75,7 @@ if ($allowedit and !$chapters) {
}
// Check chapterid and read chapter data
if ($chapterid == '0') { // Go to first chapter if no given.
foreach($chapters as $ch) {
foreach ($chapters as $ch) {
if ($edit) {
$chapterid = $ch->id;
break;
......@@ -140,12 +140,14 @@ foreach ($chapters as $ch) {
$chnavigation = '';
if ($previd) {
$chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id.'&amp;chapterid='.$previd.'"><img src="'.$OUTPUT->pix_url('nav_prev', 'mod_book').'" class="bigicon" alt="'.get_string('navprev', 'book').'"/></a>';
$chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id.
'&amp;chapterid='.$previd.'"><img src="'.$OUTPUT->pix_url('nav_prev', 'mod_book').'" class="bigicon" alt="'.get_string('navprev', 'book').'"/></a>';
} else {
$chnavigation .= '<img src="'.$OUTPUT->pix_url('nav_prev_dis', 'mod_book').'" class="bigicon" alt="" />';
}
if ($nextid) {
$chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id.'&amp;chapterid='.$nextid.'"><img src="'.$OUTPUT->pix_url('nav_next', 'mod_book').'" class="bigicon" alt="'.get_string('navnext', 'book').'" /></a>';
$chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id.
'&amp;chapterid='.$nextid.'"><img src="'.$OUTPUT->pix_url('nav_next', 'mod_book').'" class="bigicon" alt="'.get_string('navnext', 'book').'" /></a>';
} else {
$sec = '';
if ($section = $DB->get_record('course_sections', array('id'=>$cm->section))) {
......@@ -156,7 +158,8 @@ if ($nextid) {
} else {
$returnurl = "$CFG->wwwroot/course/view.php?id=$course->id#section-$sec";
}
$chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="'.$returnurl.'"><img src="'.$OUTPUT->pix_url('nav_exit', 'mod_book').'" class="bigicon" alt="'.get_string('navexit', 'book').'" /></a>';
$chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="'.$returnurl.'"><img src="'.$OUTPUT->pix_url('nav_exit', 'mod_book').
'" class="bigicon" alt="'.get_string('navexit', 'book').'" /></a>';
// we are cheating a bit here, viewing the last page means user has viewed the whole book
$completion = new completion_info($course);
......@@ -194,4 +197,3 @@ echo $OUTPUT->box_end();
echo '<div class="navbottom">'.$chnavigation.'</div>';
echo $OUTPUT->footer();
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment