lib.php 5.58 KB
Newer Older
1
<?php
Petr Skoda's avatar
Petr Skoda committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 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/>.
Petr Skoda's avatar
Petr Skoda committed
16

Petr Skoda's avatar
Petr Skoda committed
17
18
19
20
21
22
23
24
/**
 * 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
 */
Petr Skoda's avatar
Petr Skoda committed
25

Petr Skoda's avatar
Petr Skoda committed
26
defined('MOODLE_INTERNAL') || die;
Petr Skoda's avatar
Petr Skoda committed
27

Petr Skoda's avatar
Petr Skoda committed
28
29
30
31
32
33
34
/**
 * Add book instance.
 *
 * @param stdClass $data
 * @param stdClass $mform
 * @return int new book instance id
 */
Petr Skoda's avatar
Petr Skoda committed
35
function book_add_instance($book) {
Petr Skoda's avatar
Petr Skoda committed
36
    global $DB;
Petr Skoda's avatar
Petr Skoda committed
37
38
39

    $book->timecreated = time();
    $book->timemodified = $book->timecreated;
40
41
42
43
44
45
    if (!isset($book->customtitles)) {
        $book->customtitles = 0;
    }
    if (!isset($book->disableprinting)) {
        $book->disableprinting = 0;
    }
Petr Skoda's avatar
Petr Skoda committed
46

Petr Skoda's avatar
Petr Skoda committed
47
    return $DB->insert_record('book', $book);
Petr Skoda's avatar
Petr Skoda committed
48
49
}

Petr Skoda's avatar
Petr Skoda committed
50
51
52
53
54
55
56
/**
 * Update book instance.
 *
 * @param stdClass $data
 * @param stdClass $mform
 * @return bool true
 */
Petr Skoda's avatar
Petr Skoda committed
57
function book_update_instance($book) {
Petr Skoda's avatar
Petr Skoda committed
58
    global $DB;
Petr Skoda's avatar
Petr Skoda committed
59
60
61

    $book->timemodified = time();
    $book->id = $book->instance;
62
63
64
65
66
67
    if (!isset($book->customtitles)) {
        $book->customtitles = 0;
    }
    if (!isset($book->disableprinting)) {
        $book->disableprinting = 0;
    }
Petr Skoda's avatar
Petr Skoda committed
68

Petr Skoda's avatar
Petr Skoda committed
69
    $DB->update_record('book', $book);
Petr Skoda's avatar
Petr Skoda committed
70

Petr Skoda's avatar
Petr Skoda committed
71
    return true;
Petr Skoda's avatar
Petr Skoda committed
72
73
}

Petr Skoda's avatar
Petr Skoda committed
74
75
76
77
78
79
80
81
82
/**
 *
 * 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
 */
Petr Skoda's avatar
Petr Skoda committed
83
function book_delete_instance($id) {
Petr Skoda's avatar
Petr Skoda committed
84
    global $DB;
Petr Skoda's avatar
Petr Skoda committed
85

Petr Skoda's avatar
Petr Skoda committed
86
    if (!$book = $DB->get_record('book', array('id'=>$id))) {
Petr Skoda's avatar
Petr Skoda committed
87
88
89
        return false;
    }

Petr Skoda's avatar
Petr Skoda committed
90
91
    $DB->delete_records('book_chapters', array('bookid'=>$book->id));
    $DB->delete_records('book', array('id'=>$book->id));
Petr Skoda's avatar
Petr Skoda committed
92

Petr Skoda's avatar
Petr Skoda committed
93
    return true;
Petr Skoda's avatar
Petr Skoda committed
94
95
}

96
function book_get_types() {
Petr Skoda's avatar
Petr Skoda committed
97
    $type = new stdClass();
98
    $type->modclass = MOD_CLASS_RESOURCE;
Petr Skoda's avatar
Petr Skoda committed
99
100
    $type->type     = 'book';
    $type->typestr  = get_string('modulename', 'book');
101

Petr Skoda's avatar
Petr Skoda committed
102
    return array($type);
103
}
Petr Skoda's avatar
Petr Skoda committed
104

Petr Skoda's avatar
Petr Skoda committed
105
function book_user_outline($course, $user, $mod, $book) {
Petr Skoda's avatar
Petr Skoda committed
106
107
108
109
110
111
112
    // 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;
Petr Skoda's avatar
Petr Skoda committed
113
114
115
}

function book_user_complete($course, $user, $mod, $book) {
Petr Skoda's avatar
Petr Skoda committed
116
117
    // Print a detailed representation of what a  user has done with
    // a given particular instance of this module, for user activity reports.
Petr Skoda's avatar
Petr Skoda committed
118
119
120
121
122

    return true;
}

function book_print_recent_activity($course, $isteacher, $timestart) {
Petr Skoda's avatar
Petr Skoda committed
123
124
125
    // 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.
Petr Skoda's avatar
Petr Skoda committed
126
127
128
129
    return false;  //  True if anything was printed, otherwise false
}

function book_cron () {
Petr Skoda's avatar
Petr Skoda committed
130
131
132
    // 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 ...
Petr Skoda's avatar
Petr Skoda committed
133
134
135
136
    return true;
}

function book_grades($bookid) {
Petr Skoda's avatar
Petr Skoda committed
137
138
    // Must return an array of grades for a given instance of this module,
    // indexed by user.  It also returns a maximum allowed grade.
Petr Skoda's avatar
Petr Skoda committed
139

Petr Skoda's avatar
Petr Skoda committed
140
    return null;
Petr Skoda's avatar
Petr Skoda committed
141
142
143
}

function book_get_participants($bookid) {
Petr Skoda's avatar
Petr Skoda committed
144
145
146
147
    //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.
Petr Skoda's avatar
Petr Skoda committed
148
149
150
151

    return false;
}

152
153
154
155
156
/**
 * This function returns if a scale is being used by one book
 * it it has support for grading and scales. Commented code should be
 * modified if necessary. See forum, glossary or journal modules
 * as reference.
Petr Skoda's avatar
Petr Skoda committed
157
 *
158
159
160
161
 * @param $bookid int
 * @param $scaleid int
 * @return boolean True if the scale is used by any journal
 */
Petr Skoda's avatar
Petr Skoda committed
162
function book_scale_used($bookid,$scaleid) {
163
    return false;
Petr Skoda's avatar
Petr Skoda committed
164
165
}

166
/**
Petr Skoda's avatar
Petr Skoda committed
167
 * Checks if scale is being used by any instance of book
168
169
 *
 * This is used to find out if scale used anywhere
Petr Skoda's avatar
Petr Skoda committed
170
 *
171
172
173
 * @param $scaleid int
 * @return boolean True if the scale is used by any journal
 */
Petr Skoda's avatar
Petr Skoda committed
174
function book_scale_used_anywhere($scaleid) {
175
176
    return false;
}
177
178
179
180
181
182
183
184

function book_get_view_actions() {
    return array('view', 'view all', 'print');
}

function book_get_post_actions() {
    return array('update');
}
Petr Skoda's avatar
Petr Skoda committed
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

/**
 * 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;
    }
}