2009-07-07 02:26:36 +00:00
|
|
|
<?php
|
|
|
|
// This file is part of 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/>.
|
2007-10-10 06:34:20 +00:00
|
|
|
|
2007-07-16 04:09:00 +00:00
|
|
|
/**
|
2012-01-06 11:52:46 +07:00
|
|
|
* Definition of the grade_user_report class is defined
|
|
|
|
*
|
|
|
|
* @package gradereport_user
|
|
|
|
* @copyright 2007 Nicolas Connault
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2007-07-16 04:09:00 +00:00
|
|
|
*/
|
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
use core_user\output\myprofile\tree;
|
|
|
|
|
2007-07-16 04:09:00 +00:00
|
|
|
require_once($CFG->dirroot . '/grade/report/lib.php');
|
|
|
|
require_once($CFG->libdir.'/tablelib.php');
|
|
|
|
|
2010-01-08 07:48:37 +00:00
|
|
|
define("GRADE_REPORT_USER_HIDE_HIDDEN", 0);
|
|
|
|
define("GRADE_REPORT_USER_HIDE_UNTIL", 1);
|
|
|
|
define("GRADE_REPORT_USER_SHOW_HIDDEN", 2);
|
|
|
|
|
2016-10-10 09:03:11 -04:00
|
|
|
define("GRADE_REPORT_USER_VIEW_SELF", 1);
|
|
|
|
define("GRADE_REPORT_USER_VIEW_USER", 2);
|
|
|
|
|
2007-10-27 15:33:43 +00:00
|
|
|
function grade_report_user_settings_definition(&$mform) {
|
|
|
|
global $CFG;
|
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
$options = [
|
|
|
|
-1 => get_string('default', 'grades'),
|
|
|
|
0 => get_string('hide'),
|
|
|
|
1 => get_string('show')
|
|
|
|
];
|
2007-10-27 15:33:43 +00:00
|
|
|
|
2007-10-27 20:37:22 +00:00
|
|
|
if (empty($CFG->grade_report_user_showrank)) {
|
2007-10-27 15:33:43 +00:00
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showrank', get_string('showrank', 'grades'), $options);
|
2010-06-25 17:19:34 +00:00
|
|
|
$mform->addHelpButton('report_user_showrank', 'showrank', 'grades');
|
2007-10-27 15:33:43 +00:00
|
|
|
|
2008-10-08 11:06:05 +00:00
|
|
|
if (empty($CFG->grade_report_user_showpercentage)) {
|
2008-10-13 08:44:10 +00:00
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
2009-02-25 07:56:11 +00:00
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
2008-10-08 11:06:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showpercentage', get_string('showpercentage', 'grades'), $options);
|
2010-06-21 08:39:27 +00:00
|
|
|
$mform->addHelpButton('report_user_showpercentage', 'showpercentage', 'grades');
|
2008-10-08 11:06:05 +00:00
|
|
|
|
2011-01-18 16:24:41 +08:00
|
|
|
if (empty($CFG->grade_report_user_showgrade)) {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showgrade', get_string('showgrade', 'grades'), $options);
|
|
|
|
|
|
|
|
if (empty($CFG->grade_report_user_showfeedback)) {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showfeedback', get_string('showfeedback', 'grades'), $options);
|
|
|
|
|
|
|
|
if (empty($CFG->grade_report_user_showweight)) {
|
2014-10-10 14:55:37 +08:00
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
2014-10-15 13:39:36 +08:00
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
2011-01-18 16:24:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showweight', get_string('showweight', 'grades'), $options);
|
|
|
|
|
|
|
|
if (empty($CFG->grade_report_user_showaverage)) {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showaverage', get_string('showaverage', 'grades'), $options);
|
|
|
|
$mform->addHelpButton('report_user_showaverage', 'showaverage', 'grades');
|
|
|
|
|
|
|
|
if (empty($CFG->grade_report_user_showlettergrade)) {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showlettergrade', get_string('showlettergrade', 'grades'), $options);
|
2014-08-13 14:23:59 +08:00
|
|
|
if (empty($CFG->grade_report_user_showcontributiontocoursetotal)) {
|
2014-10-15 13:39:36 +08:00
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
2014-08-13 14:23:59 +08:00
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[$CFG->grade_report_user_showcontributiontocoursetotal]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showcontributiontocoursetotal', get_string('showcontributiontocoursetotal', 'grades'), $options);
|
|
|
|
$mform->addHelpButton('report_user_showcontributiontocoursetotal', 'showcontributiontocoursetotal', 'grades');
|
2011-01-18 16:24:41 +08:00
|
|
|
|
|
|
|
if (empty($CFG->grade_report_user_showrange)) {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showrange', get_string('showrange', 'grades'), $options);
|
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
$options = [
|
2022-09-13 11:01:31 +02:00
|
|
|
0 => 0,
|
|
|
|
1 => 1,
|
|
|
|
2 => 2,
|
|
|
|
3 => 3,
|
|
|
|
4 => 4,
|
|
|
|
5 => 5
|
2022-09-12 06:29:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
if (!empty($CFG->grade_report_user_rangedecimals)) {
|
2011-01-18 16:24:41 +08:00
|
|
|
$options[-1] = $options[$CFG->grade_report_user_rangedecimals];
|
|
|
|
}
|
|
|
|
$mform->addElement('select', 'report_user_rangedecimals', get_string('rangedecimals', 'grades'), $options);
|
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
$options = [
|
|
|
|
-1 => get_string('default', 'grades'),
|
|
|
|
0 => get_string('shownohidden', 'grades'),
|
|
|
|
1 => get_string('showhiddenuntilonly', 'grades'),
|
|
|
|
2 => get_string('showallhidden', 'grades')
|
|
|
|
];
|
2007-10-27 15:33:43 +00:00
|
|
|
|
2007-10-27 20:37:22 +00:00
|
|
|
if (empty($CFG->grade_report_user_showhiddenitems)) {
|
2007-10-27 15:33:43 +00:00
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
|
|
|
} else {
|
2009-05-07 07:38:02 +00:00
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[$CFG->grade_report_user_showhiddenitems]);
|
2007-10-27 15:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showhiddenitems', get_string('showhiddenitems', 'grades'), $options);
|
2010-06-21 06:57:46 +00:00
|
|
|
$mform->addHelpButton('report_user_showhiddenitems', 'showhiddenitems', 'grades');
|
2010-02-08 06:27:04 +00:00
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
$options = [
|
|
|
|
-1 => get_string('default', 'grades'),
|
|
|
|
GRADE_REPORT_HIDE_TOTAL_IF_CONTAINS_HIDDEN => get_string('hide'),
|
|
|
|
GRADE_REPORT_SHOW_TOTAL_IF_CONTAINS_HIDDEN => get_string('hidetotalshowexhiddenitems', 'grades'),
|
|
|
|
GRADE_REPORT_SHOW_REAL_TOTAL_IF_CONTAINS_HIDDEN => get_string('hidetotalshowinchiddenitems', 'grades')
|
|
|
|
];
|
2010-02-08 06:27:04 +00:00
|
|
|
|
|
|
|
if (empty($CFG->grade_report_user_showtotalsifcontainhidden)) {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[0]);
|
|
|
|
} else {
|
|
|
|
$options[-1] = get_string('defaultprev', 'grades', $options[$CFG->grade_report_user_showtotalsifcontainhidden]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$mform->addElement('select', 'report_user_showtotalsifcontainhidden', get_string('hidetotalifhiddenitems', 'grades'), $options);
|
2010-06-07 09:56:33 +00:00
|
|
|
$mform->addHelpButton('report_user_showtotalsifcontainhidden', 'hidetotalifhiddenitems', 'grades');
|
2014-08-13 14:23:59 +08:00
|
|
|
|
2007-10-28 17:15:00 +00:00
|
|
|
}
|
|
|
|
|
2014-08-11 11:53:06 +08:00
|
|
|
/**
|
|
|
|
* Profile report callback.
|
|
|
|
*
|
|
|
|
* @param object $course The course.
|
|
|
|
* @param object $user The user.
|
|
|
|
* @param boolean $viewasuser True when we are viewing this as the targetted user sees it.
|
|
|
|
*/
|
2022-09-12 06:29:55 +02:00
|
|
|
function grade_report_user_profilereport(object $course, object $user, bool $viewasuser = false) {
|
2007-10-28 17:15:00 +00:00
|
|
|
if (!empty($course->showgrades)) {
|
|
|
|
|
2012-07-24 14:04:40 +08:00
|
|
|
$context = context_course::instance($course->id);
|
2007-10-28 17:15:00 +00:00
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
// Fetch the return tracking object.
|
2022-09-13 11:01:31 +02:00
|
|
|
$gpr = new grade_plugin_return(
|
|
|
|
['type' => 'report', 'plugin' => 'user', 'courseid' => $course->id, 'userid' => $user->id]
|
|
|
|
);
|
2022-09-12 06:29:55 +02:00
|
|
|
// Create a report instance.
|
2022-09-10 20:46:52 +08:00
|
|
|
$report = new gradereport_user\report\user($course->id, $gpr, $context, $user->id, $viewasuser);
|
2007-07-16 04:09:00 +00:00
|
|
|
|
2022-09-12 06:29:55 +02:00
|
|
|
// Print the page.
|
|
|
|
// A css fix to share styles with real report page.
|
|
|
|
echo '<div class="grade-report-user">';
|
2007-10-28 17:15:00 +00:00
|
|
|
if ($report->fill_table()) {
|
|
|
|
echo $report->print_table(true);
|
|
|
|
}
|
|
|
|
echo '</div>';
|
|
|
|
}
|
2007-07-16 04:09:00 +00:00
|
|
|
}
|
2007-10-28 17:15:00 +00:00
|
|
|
|
2015-04-16 15:57:01 +08:00
|
|
|
/**
|
|
|
|
* Add nodes to myprofile page.
|
|
|
|
*
|
2022-09-12 06:29:55 +02:00
|
|
|
* @param tree $tree Tree object
|
2015-04-16 15:57:01 +08:00
|
|
|
* @param stdClass $user user object
|
|
|
|
* @param bool $iscurrentuser
|
2022-09-12 06:29:55 +02:00
|
|
|
* @param null|stdClass $course Course object
|
2015-04-16 15:57:01 +08:00
|
|
|
*/
|
2022-09-12 06:29:55 +02:00
|
|
|
function gradereport_user_myprofile_navigation(tree $tree, stdClass $user, bool $iscurrentuser, ?stdClass $course) {
|
2015-04-16 15:57:01 +08:00
|
|
|
if (empty($course)) {
|
|
|
|
// We want to display these reports under the site context.
|
|
|
|
$course = get_fast_modinfo(SITEID)->get_course();
|
|
|
|
}
|
|
|
|
$usercontext = context_user::instance($user->id);
|
|
|
|
$anyreport = has_capability('moodle/user:viewuseractivitiesreport', $usercontext);
|
|
|
|
|
|
|
|
// Start capability checks.
|
2016-12-07 16:38:27 +08:00
|
|
|
if ($anyreport || $iscurrentuser) {
|
2015-04-16 15:57:01 +08:00
|
|
|
// Add grade hardcoded grade report if necessary.
|
|
|
|
$gradeaccess = false;
|
|
|
|
$coursecontext = context_course::instance($course->id);
|
|
|
|
if (has_capability('moodle/grade:viewall', $coursecontext)) {
|
|
|
|
// Can view all course grades.
|
|
|
|
$gradeaccess = true;
|
|
|
|
} else if ($course->showgrades) {
|
|
|
|
if ($iscurrentuser && has_capability('moodle/grade:view', $coursecontext)) {
|
|
|
|
// Can view own grades.
|
|
|
|
$gradeaccess = true;
|
|
|
|
} else if (has_capability('moodle/grade:viewall', $usercontext)) {
|
|
|
|
// Can view grades of this user - parent most probably.
|
|
|
|
$gradeaccess = true;
|
|
|
|
} else if ($anyreport) {
|
|
|
|
// Can view grades of this user - parent most probably.
|
|
|
|
$gradeaccess = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($gradeaccess) {
|
|
|
|
$url = new moodle_url('/course/user.php', array('mode' => 'grade', 'id' => $course->id, 'user' => $user->id));
|
2021-03-16 13:11:07 +01:00
|
|
|
$node = new core_user\output\myprofile\node('reports', 'grade', get_string('grades'), null, $url);
|
2015-04-16 15:57:01 +08:00
|
|
|
$tree->add_node($node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|