~ubuntu-branches/ubuntu/trusty/moodle/trusty

« back to all changes in this revision

Viewing changes to mod/lesson/lib.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-01-21 13:40:52 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20140121134052-ym2qvsp2cd9vq0p6
Tags: 2.5.4-1
* New upstream release, fixing security issues:
  - MSA-14-0001 Config passwords visibility issue [CVE-2014-0008]
  - MSA-14-0002 Group constraints lacking in "login as" [CVE-2014-0009]
  - MSA-14-0003 CSRF vulnerability in profile fields [CVE-2014-0010]
* Move /var/lib/moodle directory into package.
* Revert back to bundled yui3. Unfortunately, version in Debian and
  of upstream are not compatible (closes: #735312).

Show diffs side-by-side

added added

removed removed

Lines of Context:
468
468
    } else if ($lesson->grade < 0) {
469
469
        $params['gradetype']  = GRADE_TYPE_SCALE;
470
470
        $params['scaleid']   = -$lesson->grade;
 
471
 
 
472
        // Make sure current grade fetched correctly from $grades
 
473
        $currentgrade = null;
 
474
        if (!empty($grades)) {
 
475
            if (is_array($grades)) {
 
476
                $currentgrade = reset($grades);
 
477
            } else {
 
478
                $currentgrade = $grades;
 
479
            }
 
480
        }
 
481
 
 
482
        // When converting a score to a scale, use scale's grade maximum to calculate it.
 
483
        if (!empty($currentgrade) && $currentgrade->rawgrade !== null) {
 
484
            $grade = grade_get_grades($lesson->course, 'mod', 'lesson', $lesson->id, $currentgrade->userid);
 
485
            $params['grademax']   = reset($grade->items)->grademax;
 
486
        }
471
487
    } else {
472
488
        $params['gradetype']  = GRADE_TYPE_NONE;
473
489
    }
488
504
            }
489
505
            //check raw grade isnt null otherwise we erroneously insert a grade of 0
490
506
            if ($grade['rawgrade'] !== null) {
491
 
                $grades[$key]['rawgrade'] = ($grade['rawgrade'] * $lesson->grade / 100);
 
507
                $grades[$key]['rawgrade'] = ($grade['rawgrade'] * $params['grademax'] / 100);
492
508
            } else {
493
509
                //setting rawgrade to null just in case user is deleting a grade
494
510
                $grades[$key]['rawgrade'] = null;
890
906
 *
891
907
 * @package  mod_lesson
892
908
 * @category files
893
 
 * @todo MDL-31048 localize
894
909
 * @return array a list of available file areas
895
910
 */
896
911
function lesson_get_file_areas() {
897
912
    $areas = array();
898
 
    $areas['page_contents'] = 'Page contents'; //TODO: localize!!!!
899
 
    $areas['mediafile'] = 'Media file'; //TODO: localize!!!!
900
 
 
 
913
    $areas['page_contents'] = get_string('pagecontents', 'mod_lesson');
 
914
    $areas['mediafile'] = get_string('mediafile', 'mod_lesson');
901
915
    return $areas;
902
916
}
903
917
 
919
933
 * @return file_info_stored
920
934
 */
921
935
function lesson_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
922
 
    global $CFG;
923
 
    if (has_capability('moodle/course:managefiles', $context)) {
924
 
        // no peaking here for students!!
 
936
    global $CFG, $DB;
 
937
 
 
938
    if (!has_capability('moodle/course:managefiles', $context)) {
 
939
        // No peaking here for students!
925
940
        return null;
926
941
    }
927
942
 
 
943
    // Mediafile area does not have sub directories, so let's select the default itemid to prevent
 
944
    // the user from selecting a directory to access the mediafile content.
 
945
    if ($filearea == 'mediafile' && is_null($itemid)) {
 
946
        $itemid = 0;
 
947
    }
 
948
 
 
949
    if (is_null($itemid)) {
 
950
        require_once(__DIR__ . '/locallib.php');
 
951
        return new mod_lesson_file_info($browser, $course, $cm, $context, $areas, $filearea);
 
952
    }
 
953
 
928
954
    $fs = get_file_storage();
929
955
    $filepath = is_null($filepath) ? '/' : $filepath;
930
956
    $filename = is_null($filename) ? '.' : $filename;
931
 
    $urlbase = $CFG->wwwroot.'/pluginfile.php';
932
957
    if (!$storedfile = $fs->get_file($context->id, 'mod_lesson', $filearea, $itemid, $filepath, $filename)) {
933
958
        return null;
934
959
    }
935
 
    return new file_info_stored($browser, $context, $storedfile, $urlbase, $filearea, $itemid, true, true, false);
 
960
 
 
961
    $itemname = $filearea;
 
962
    if ($filearea == 'page_contents') {
 
963
        $itemname = $DB->get_field('lesson_pages', 'title', array('lessonid' => $cm->instance, 'id' => $itemid));
 
964
        $itemname = format_string($itemname, true, array('context' => $context));
 
965
    } else {
 
966
        $areas = lesson_get_file_areas();
 
967
        if (isset($areas[$filearea])) {
 
968
            $itemname = $areas[$filearea];
 
969
        }
 
970
    }
 
971
 
 
972
    $urlbase = $CFG->wwwroot . '/pluginfile.php';
 
973
    return new file_info_stored($browser, $context, $storedfile, $urlbase, $itemname, $itemid, true, true, false);
936
974
}
937
975
 
938
976