~ubuntu-branches/ubuntu/natty/moodle/natty

« back to all changes in this revision

Viewing changes to mod/lesson/lib.php

  • Committer: Bazaar Package Importer
  • Author(s): Tomasz Muras
  • Date: 2010-10-30 12:19:28 UTC
  • mfrom: (1.1.12 upstream) (3.1.10 squeeze)
  • Revision ID: james.westby@ubuntu.com-20101030121928-qzobi6mctpnk4dif
Tags: 1.9.9.dfsg2-2
* Added Romanian translation
* Updated Japanese translation (closes: #596820)
* Backporting security fixes from Moodle 1.9.10 (closes: #601384)
   - Updated embedded CAS to 1.1.3
   - Added patch for MDL-24523:
     clean_text() not filtering text in markdown format
   - Added patch for MDL-24810 and upgraded customized HTML Purifier to 4.2.0 
   - Added patch for MDL-24258:
     students can delete their forum posts later than $CFG->maxeditingtime 
     under certain conditions
   - Added patch for MDL-23377:
     Can't delete quiz attempts in course without enrolled students

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php  // $Id: lib.php,v 1.41.2.7 2009/01/09 06:16:52 tjhunt Exp $
 
1
<?php  // $Id: lib.php,v 1.41.2.11 2009/10/27 11:24:56 nicolasconnault Exp $
2
2
/**
3
3
 * Standard library of functions and constants for lesson
4
4
 *
5
 
 * @version $Id: lib.php,v 1.41.2.7 2009/01/09 06:16:52 tjhunt Exp $
 
5
 * @version $Id: lib.php,v 1.41.2.11 2009/10/27 11:24:56 nicolasconnault Exp $
6
6
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7
7
 * @package lesson
8
8
 **/
147
147
/// Used for user activity reports.
148
148
/// $return->time = the time they did it
149
149
/// $return->info = a short text description
150
 
 
151
 
    if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $user->id",
152
 
                "grade DESC")) {
153
 
        foreach ($grades as $grade) {
154
 
            $max_grade = number_format($grade->grade * $lesson->grade / 100.0, 1);
155
 
            break;
156
 
        }
157
 
        $return->time = $grade->completed;
158
 
        if ($lesson->retake) {
159
 
            $return->info = get_string("gradeis", "lesson", $max_grade)." (".
160
 
                get_string("attempt", "lesson", count($grades)).")";
161
 
        } else {
162
 
            $return->info = get_string("gradeis", "lesson", $max_grade);
163
 
        }
164
 
    } else {
 
150
    global $CFG;
 
151
    require_once("$CFG->libdir/gradelib.php");
 
152
    $grades = grade_get_grades($course->id, 'mod', 'lesson', $lesson->id, $user->id);
 
153
    if (empty($grades->items[0]->grades)) {
165
154
        $return->info = get_string("no")." ".get_string("attempts", "lesson");
 
155
    } else {
 
156
        $grade = reset($grades->items[0]->grades);
 
157
        $return->info = get_string("grade") . ': ' . $grade->str_long_grade;
 
158
        $return->time = $grade->dategraded;
166
159
    }
167
160
    return $return;
168
161
}
171
164
function lesson_user_complete($course, $user, $mod, $lesson) {
172
165
/// Print a detailed representation of what a  user has done with
173
166
/// a given particular instance of this module, for user activity reports.
 
167
    global $CFG;
 
168
    require_once("$CFG->libdir/gradelib.php");
 
169
 
 
170
    $grades = grade_get_grades($course->id, 'mod', 'lesson', $lesson->id, $user->id);
 
171
    if (!empty($grades->items[0]->grades)) {
 
172
        $grade = reset($grades->items[0]->grades);
 
173
        echo '<p>'.get_string('grade').': '.$grade->str_long_grade.'</p>';
 
174
        if ($grade->str_feedback) {
 
175
            echo '<p>'.get_string('feedback').': '.$grade->str_feedback.'</p>';
 
176
        }
 
177
    }
174
178
 
175
179
    if ($attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $user->id",
176
180
                "retry, timeseen")) {
210
214
        }
211
215
        print_table($table);
212
216
        print_simple_box_end();
213
 
        // also print grade summary
214
 
        if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $user->id",
215
 
                    "grade DESC")) {
216
 
            foreach ($grades as $grade) {
217
 
                $max_grade = number_format($grade->grade * $lesson->grade / 100.0, 1);
218
 
                break;
219
 
            }
220
 
            if ($lesson->retake) {
221
 
                echo "<p>".get_string("gradeis", "lesson", $max_grade)." (".
222
 
                    get_string("attempts", "lesson").": ".count($grades).")</p>";
223
 
            } else {
224
 
                echo "<p>".get_string("gradeis", "lesson", $max_grade)."</p>";
225
 
            }
226
 
        }
227
 
    } else {
228
 
        echo get_string("no")." ".get_string("attempts", "lesson");
229
217
    }
230
218
 
231
 
 
232
219
    return true;
233
220
}
234
221
 
427
414
    if ($grades  === 'reset') {
428
415
        $params['reset'] = true;
429
416
        $grades = NULL;
 
417
    } else if (!empty($grades)) {
 
418
        // Need to calculate raw grade (Note: $grades has many forms)
 
419
        if (is_object($grades)) {
 
420
            $grades = array($grades->userid => $grades);
 
421
        } else if (array_key_exists('userid', $grades)) {
 
422
            $grades = array($grades['userid'] => $grades);
 
423
        }
 
424
        foreach ($grades as $key => $grade) {
 
425
            if (!is_array($grade)) {
 
426
                $grades[$key] = $grade = (array) $grade;
 
427
            }
 
428
            $grades[$key]['rawgrade'] = ($grade['rawgrade'] * $lesson->grade / 100);
 
429
        }
430
430
    }
431
431
 
432
432
    return grade_update('mod/lesson', $lesson->course, 'mod', 'lesson', $lesson->id, 0, $grades, $params);
659
659
    return array('moodle/site:accessallgroups');
660
660
}
661
661
 
 
662
/**
 
663
 * Tells if files in moddata are trusted and can be served without XSS protection.
 
664
 * @return bool true if file can be submitted by teacher only (trusted), false otherwise
 
665
 */
 
666
function lesson_is_moddata_trusted() {
 
667
    return true;
 
668
}
 
669
 
662
670
?>