[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Book module core interaction API 19 * 20 * @package mod_book 21 * @copyright 2004-2011 Petr Skoda {@link http://skodak.org} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die; 26 27 /** 28 * Returns list of available numbering types 29 * @return array 30 */ 31 function book_get_numbering_types() { 32 global $CFG; // required for the include 33 34 require_once(dirname(__FILE__).'/locallib.php'); 35 36 return array ( 37 BOOK_NUM_NONE => get_string('numbering0', 'mod_book'), 38 BOOK_NUM_NUMBERS => get_string('numbering1', 'mod_book'), 39 BOOK_NUM_BULLETS => get_string('numbering2', 'mod_book'), 40 BOOK_NUM_INDENTED => get_string('numbering3', 'mod_book') 41 ); 42 } 43 44 /** 45 * Returns all other caps used in module 46 * @return array 47 */ 48 function book_get_extra_capabilities() { 49 // used for group-members-only 50 return array('moodle/site:accessallgroups'); 51 } 52 53 /** 54 * Add book instance. 55 * 56 * @param stdClass $data 57 * @param stdClass $mform 58 * @return int new book instance id 59 */ 60 function book_add_instance($data, $mform) { 61 global $DB; 62 63 $data->timecreated = time(); 64 $data->timemodified = $data->timecreated; 65 if (!isset($data->customtitles)) { 66 $data->customtitles = 0; 67 } 68 69 return $DB->insert_record('book', $data); 70 } 71 72 /** 73 * Update book instance. 74 * 75 * @param stdClass $data 76 * @param stdClass $mform 77 * @return bool true 78 */ 79 function book_update_instance($data, $mform) { 80 global $DB; 81 82 $data->timemodified = time(); 83 $data->id = $data->instance; 84 if (!isset($data->customtitles)) { 85 $data->customtitles = 0; 86 } 87 88 $DB->update_record('book', $data); 89 90 $book = $DB->get_record('book', array('id'=>$data->id)); 91 $DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id)); 92 93 return true; 94 } 95 96 /** 97 * Delete book instance by activity id 98 * 99 * @param int $id 100 * @return bool success 101 */ 102 function book_delete_instance($id) { 103 global $DB; 104 105 if (!$book = $DB->get_record('book', array('id'=>$id))) { 106 return false; 107 } 108 109 $DB->delete_records('book_chapters', array('bookid'=>$book->id)); 110 $DB->delete_records('book', array('id'=>$book->id)); 111 112 return true; 113 } 114 115 /** 116 * Given a course and a time, this module should find recent activity 117 * that has occurred in book activities and print it out. 118 * 119 * @param stdClass $course 120 * @param bool $viewfullnames 121 * @param int $timestart 122 * @return bool true if there was output, or false is there was none 123 */ 124 function book_print_recent_activity($course, $viewfullnames, $timestart) { 125 return false; // True if anything was printed, otherwise false 126 } 127 128 /** 129 * This function is used by the reset_course_userdata function in moodlelib. 130 * @param $data the data submitted from the reset course. 131 * @return array status array 132 */ 133 function book_reset_userdata($data) { 134 return array(); 135 } 136 137 /** 138 * No cron in book. 139 * 140 * @return bool 141 */ 142 function book_cron () { 143 return true; 144 } 145 146 /** 147 * No grading in book. 148 * 149 * @param int $bookid 150 * @return null 151 */ 152 function book_grades($bookid) { 153 return null; 154 } 155 156 /** 157 * This function returns if a scale is being used by one book 158 * it it has support for grading and scales. Commented code should be 159 * modified if necessary. See book, glossary or journal modules 160 * as reference. 161 * 162 * @param int $bookid 163 * @param int $scaleid 164 * @return boolean True if the scale is used by any journal 165 */ 166 function book_scale_used($bookid, $scaleid) { 167 return false; 168 } 169 170 /** 171 * Checks if scale is being used by any instance of book 172 * 173 * This is used to find out if scale used anywhere 174 * 175 * @param int $scaleid 176 * @return bool true if the scale is used by any book 177 */ 178 function book_scale_used_anywhere($scaleid) { 179 return false; 180 } 181 182 /** 183 * Return read actions. 184 * 185 * Note: This is not used by new logging system. Event with 186 * crud = 'r' and edulevel = LEVEL_PARTICIPATING will 187 * be considered as view action. 188 * 189 * @return array 190 */ 191 function book_get_view_actions() { 192 global $CFG; // necessary for includes 193 194 $return = array('view', 'view all'); 195 196 $plugins = core_component::get_plugin_list('booktool'); 197 foreach ($plugins as $plugin => $dir) { 198 if (file_exists("$dir/lib.php")) { 199 require_once("$dir/lib.php"); 200 } 201 $function = 'booktool_'.$plugin.'_get_view_actions'; 202 if (function_exists($function)) { 203 if ($actions = $function()) { 204 $return = array_merge($return, $actions); 205 } 206 } 207 } 208 209 return $return; 210 } 211 212 /** 213 * Return write actions. 214 * 215 * Note: This is not used by new logging system. Event with 216 * crud = ('c' || 'u' || 'd') and edulevel = LEVEL_PARTICIPATING 217 * will be considered as post action. 218 * 219 * @return array 220 */ 221 function book_get_post_actions() { 222 global $CFG; // necessary for includes 223 224 $return = array('update'); 225 226 $plugins = core_component::get_plugin_list('booktool'); 227 foreach ($plugins as $plugin => $dir) { 228 if (file_exists("$dir/lib.php")) { 229 require_once("$dir/lib.php"); 230 } 231 $function = 'booktool_'.$plugin.'_get_post_actions'; 232 if (function_exists($function)) { 233 if ($actions = $function()) { 234 $return = array_merge($return, $actions); 235 } 236 } 237 } 238 239 return $return; 240 } 241 242 /** 243 * Supported features 244 * 245 * @param string $feature FEATURE_xx constant for requested feature 246 * @return mixed True if module supports feature, false if not, null if doesn't know 247 */ 248 function book_supports($feature) { 249 switch($feature) { 250 case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE; 251 case FEATURE_GROUPS: return false; 252 case FEATURE_GROUPINGS: return false; 253 case FEATURE_MOD_INTRO: return true; 254 case FEATURE_COMPLETION_TRACKS_VIEWS: return true; 255 case FEATURE_GRADE_HAS_GRADE: return false; 256 case FEATURE_GRADE_OUTCOMES: return false; 257 case FEATURE_BACKUP_MOODLE2: return true; 258 case FEATURE_SHOW_DESCRIPTION: return true; 259 260 default: return null; 261 } 262 } 263 264 /** 265 * Adds module specific settings to the settings block 266 * 267 * @param settings_navigation $settingsnav The settings navigation object 268 * @param navigation_node $booknode The node to add module settings to 269 * @return void 270 */ 271 function book_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $booknode) { 272 global $USER, $PAGE; 273 274 $plugins = core_component::get_plugin_list('booktool'); 275 foreach ($plugins as $plugin => $dir) { 276 if (file_exists("$dir/lib.php")) { 277 require_once("$dir/lib.php"); 278 } 279 $function = 'booktool_'.$plugin.'_extend_settings_navigation'; 280 if (function_exists($function)) { 281 $function($settingsnav, $booknode); 282 } 283 } 284 285 $params = $PAGE->url->params(); 286 287 if (!empty($params['id']) and !empty($params['chapterid']) and has_capability('mod/book:edit', $PAGE->cm->context)) { 288 if (!empty($USER->editing)) { 289 $string = get_string("turneditingoff"); 290 $edit = '0'; 291 } else { 292 $string = get_string("turneditingon"); 293 $edit = '1'; 294 } 295 $url = new moodle_url('/mod/book/view.php', array('id'=>$params['id'], 'chapterid'=>$params['chapterid'], 'edit'=>$edit, 'sesskey'=>sesskey())); 296 $booknode->add($string, $url, navigation_node::TYPE_SETTING); 297 } 298 } 299 300 301 /** 302 * Lists all browsable file areas 303 * @param object $course 304 * @param object $cm 305 * @param object $context 306 * @return array 307 */ 308 function book_get_file_areas($course, $cm, $context) { 309 $areas = array(); 310 $areas['chapter'] = get_string('chapters', 'mod_book'); 311 return $areas; 312 } 313 314 /** 315 * File browsing support for book module chapter area. 316 * @param object $browser 317 * @param object $areas 318 * @param object $course 319 * @param object $cm 320 * @param object $context 321 * @param string $filearea 322 * @param int $itemid 323 * @param string $filepath 324 * @param string $filename 325 * @return object file_info instance or null if not found 326 */ 327 function book_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) { 328 global $CFG, $DB; 329 330 // note: 'intro' area is handled in file_browser automatically 331 332 if (!has_capability('mod/book:read', $context)) { 333 return null; 334 } 335 336 if ($filearea !== 'chapter') { 337 return null; 338 } 339 340 require_once(dirname(__FILE__).'/locallib.php'); 341 342 if (is_null($itemid)) { 343 return new book_file_info($browser, $course, $cm, $context, $areas, $filearea); 344 } 345 346 $fs = get_file_storage(); 347 $filepath = is_null($filepath) ? '/' : $filepath; 348 $filename = is_null($filename) ? '.' : $filename; 349 if (!$storedfile = $fs->get_file($context->id, 'mod_book', $filearea, $itemid, $filepath, $filename)) { 350 return null; 351 } 352 353 // modifications may be tricky - may cause caching problems 354 $canwrite = has_capability('mod/book:edit', $context); 355 356 $chaptername = $DB->get_field('book_chapters', 'title', array('bookid'=>$cm->instance, 'id'=>$itemid)); 357 $chaptername = format_string($chaptername, true, array('context'=>$context)); 358 359 $urlbase = $CFG->wwwroot.'/pluginfile.php'; 360 return new file_info_stored($browser, $context, $storedfile, $urlbase, $chaptername, true, true, $canwrite, false); 361 } 362 363 /** 364 * Serves the book attachments. Implements needed access control ;-) 365 * 366 * @param stdClass $course course object 367 * @param cm_info $cm course module object 368 * @param context $context context object 369 * @param string $filearea file area 370 * @param array $args extra arguments 371 * @param bool $forcedownload whether or not force download 372 * @param array $options additional options affecting the file serving 373 * @return bool false if file not found, does not return if found - just send the file 374 */ 375 function book_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options=array()) { 376 global $CFG, $DB; 377 378 if ($context->contextlevel != CONTEXT_MODULE) { 379 return false; 380 } 381 382 require_course_login($course, true, $cm); 383 384 if ($filearea !== 'chapter') { 385 return false; 386 } 387 388 if (!has_capability('mod/book:read', $context)) { 389 return false; 390 } 391 392 $chid = (int)array_shift($args); 393 394 if (!$book = $DB->get_record('book', array('id'=>$cm->instance))) { 395 return false; 396 } 397 398 if (!$chapter = $DB->get_record('book_chapters', array('id'=>$chid, 'bookid'=>$book->id))) { 399 return false; 400 } 401 402 if ($chapter->hidden and !has_capability('mod/book:viewhiddenchapters', $context)) { 403 return false; 404 } 405 406 $fs = get_file_storage(); 407 $relativepath = implode('/', $args); 408 $fullpath = "/$context->id/mod_book/chapter/$chid/$relativepath"; 409 if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) { 410 return false; 411 } 412 413 // Nasty hack because we do not have file revisions in book yet. 414 $lifetime = $CFG->filelifetime; 415 if ($lifetime > 60*10) { 416 $lifetime = 60*10; 417 } 418 419 // finally send the file 420 send_stored_file($file, $lifetime, 0, $forcedownload, $options); 421 } 422 423 /** 424 * Return a list of page types 425 * 426 * @param string $pagetype current page type 427 * @param stdClass $parentcontext Block's parent context 428 * @param stdClass $currentcontext Current context of block 429 * @return array 430 */ 431 function book_page_type_list($pagetype, $parentcontext, $currentcontext) { 432 $module_pagetype = array('mod-book-*'=>get_string('page-mod-book-x', 'mod_book')); 433 return $module_pagetype; 434 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |