Commit 3c5e59cb authored by Petr Skoda's avatar Petr Skoda
Browse files

conversion to 2.0

parent e355240d
<?php
// This file is part of Book module for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
defined('MOODLE_INTERNAL') || die;
/**
* Book module core interaction API
*
* @package mod
* @subpackage book
* @copyright 2004-2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/// Library of functions and constants for module 'book'
defined('MOODLE_INTERNAL') || die;
/**
* Add book instance.
*
* @param stdClass $data
* @param stdClass $mform
* @return int new book instance id
*/
function book_add_instance($book) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
/// will create a new instance and return the id number
/// of the new instance.
global $DB;
$book->timecreated = time();
$book->timemodified = $book->timecreated;
......@@ -20,14 +44,18 @@ function book_add_instance($book) {
$book->disableprinting = 0;
}
return insert_record('book', $book);
return $DB->insert_record('book', $book);
}
/**
* Update book instance.
*
* @param stdClass $data
* @param stdClass $mform
* @return bool true
*/
function book_update_instance($book) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
/// will update an existing instance with new data.
global $DB;
$book->timemodified = time();
$book->id = $book->instance;
......@@ -38,96 +66,85 @@ function book_update_instance($book) {
$book->disableprinting = 0;
}
# May have to add extra stuff in here #
$DB->update_record('book', $book);
return update_record('book', $book);
return true;
}
/**
*
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*
* @param int $id
* @return bool success
*/
function book_delete_instance($id) {
/// Given an ID of an instance of this module,
/// this function will permanently delete the instance
/// and any data that depends on it.
global $DB;
if (! $book = get_record('book', 'id', $id)) {
if (!$book = $DB->get_record('book', array('id'=>$id))) {
return false;
}
$result = true;
delete_records('book_chapters', 'bookid', $book->id);
$DB->delete_records('book_chapters', array('bookid'=>$book->id));
$DB->delete_records('book', array('id'=>$book->id));
if (! delete_records('book', 'id', $book->id)) {
$result = false;
}
return $result;
return true;
}
function book_get_types() {
global $CFG;
$types = array();
$type = new object();
$type = new stdClass();
$type->modclass = MOD_CLASS_RESOURCE;
$type->type = 'book';
$type->typestr = get_string('modulename', 'book');
$types[] = $type;
$type->type = 'book';
$type->typestr = get_string('modulename', 'book');
return $types;
return array($type);
}
function book_user_outline($course, $user, $mod, $book) {
/// Return a small object with summary information about what a
/// user has done with a given particular instance of this module
/// Used for user activity reports.
/// $return->time = the time they did it
/// $return->info = a short text description
$return = null;
return $return;
// Return a small object with summary information about what a
// user has done with a given particular instance of this module
// Used for user activity reports.
// $return->time = the time they did it
// $return->info = a short text description
return null;
}
function book_user_complete($course, $user, $mod, $book) {
/// Print a detailed representation of what a user has done with
/// a given particular instance of this module, for user activity reports.
// Print a detailed representation of what a user has done with
// a given particular instance of this module, for user activity reports.
return true;
}
function book_print_recent_activity($course, $isteacher, $timestart) {
/// Given a course and a time, this module should find recent activity
/// that has occurred in book activities and print it out.
/// Return true if there was output, or false is there was none.
global $CFG;
// Given a course and a time, this module should find recent activity
// that has occurred in book activities and print it out.
// Return true if there was output, or false is there was none.
return false; // True if anything was printed, otherwise false
}
function book_cron () {
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
global $CFG;
// Function to be run periodically according to the moodle cron
// This function searches for things that need to be done, such
// as sending out mail, toggling flags etc ...
return true;
}
function book_grades($bookid) {
/// Must return an array of grades for a given instance of this module,
/// indexed by user. It also returns a maximum allowed grade.
// Must return an array of grades for a given instance of this module,
// indexed by user. It also returns a maximum allowed grade.
return NULL;
return null;
}
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, independient of his role (student, teacher, admin...)
//See other modules as example.
//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;
}
......@@ -137,11 +154,12 @@ function book_get_participants($bookid) {
* it it has support for grading and scales. Commented code should be
* modified if necessary. See forum, glossary or journal modules
* as reference.
*
* @param $bookid int
* @param $scaleid int
* @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;
}
......@@ -149,6 +167,7 @@ function book_scale_used ($bookid,$scaleid) {
* Checks if scale is being used by any instance of book
*
* This is used to find out if scale used anywhere
*
* @param $scaleid int
* @return boolean True if the scale is used by any journal
*/
......@@ -163,3 +182,22 @@ function book_get_view_actions() {
function book_get_post_actions() {
return array('update');
}
/**
* Supported features
*
* @param string $feature FEATURE_xx constant for requested feature
* @return mixed True if module supports feature, false if not, null if doesn't know
*/
function book_supports($feature) {
switch($feature) {
case FEATURE_GROUPS: return false;
case FEATURE_GROUPINGS: return false;
case FEATURE_GROUPMEMBERSONLY: return true;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return false; //TODO
case FEATURE_BACKUP_MOODLE2: return false; //TODO
default: return null;
}
}
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