468
468
} else if ($lesson->grade < 0) {
469
469
$params['gradetype'] = GRADE_TYPE_SCALE;
470
470
$params['scaleid'] = -$lesson->grade;
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);
478
$currentgrade = $grades;
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;
472
488
$params['gradetype'] = GRADE_TYPE_NONE;
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);
493
509
//setting rawgrade to null just in case user is deleting a grade
494
510
$grades[$key]['rawgrade'] = null;
891
907
* @package mod_lesson
892
908
* @category files
893
* @todo MDL-31048 localize
894
909
* @return array a list of available file areas
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!!!!
913
$areas['page_contents'] = get_string('pagecontents', 'mod_lesson');
914
$areas['mediafile'] = get_string('mediafile', 'mod_lesson');
919
933
* @return file_info_stored
921
935
function lesson_get_file_info($browser, $areas, $course, $cm, $context, $filearea, $itemid, $filepath, $filename) {
923
if (has_capability('moodle/course:managefiles', $context)) {
924
// no peaking here for students!!
938
if (!has_capability('moodle/course:managefiles', $context)) {
939
// No peaking here for students!
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)) {
949
if (is_null($itemid)) {
950
require_once(__DIR__ . '/locallib.php');
951
return new mod_lesson_file_info($browser, $course, $cm, $context, $areas, $filearea);
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)) {
935
return new file_info_stored($browser, $context, $storedfile, $urlbase, $filearea, $itemid, true, true, false);
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));
966
$areas = lesson_get_file_areas();
967
if (isset($areas[$filearea])) {
968
$itemname = $areas[$filearea];
972
$urlbase = $CFG->wwwroot . '/pluginfile.php';
973
return new file_info_stored($browser, $context, $storedfile, $urlbase, $itemname, $itemid, true, true, false);