first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,47 @@
<?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/>.
/**
* Grader report viewed event.
*
* @package gradereport_grader
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace gradereport_grader\event;
defined('MOODLE_INTERNAL') || die();
/**
* Grader report viewed event class.
*
* @package gradereport_grader
* @since Moodle 2.8
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grade_report_viewed extends \core\event\grade_report_viewed {
/**
* Returns localised general event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventgradereportviewed', 'gradereport_grader');
}
}
@@ -0,0 +1,130 @@
<?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/>.
namespace gradereport_grader\external;
use context_course;
use core_user_external;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use grade_report_grader;
use user_picture;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/course/externallib.php');
require_once($CFG->dirroot .'/user/externallib.php');
require_once($CFG->dirroot.'/grade/lib.php');
require_once($CFG->dirroot.'/grade/report/grader/lib.php');
/**
* External grade report grader API
*
* @package gradereport_grader
* @copyright 2022 Mathew May <mathew.solutions>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_users_in_report extends external_api {
/**
* Describes the parameters for get_users_in_report
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters (
[
'courseid' => new external_value(PARAM_INT, 'Course ID', VALUE_REQUIRED)
]
);
}
/**
* Given a course ID find Fetch the grader report and add some fields to the returned users.
*
* @param int $courseid Course ID to fetch the grader report for.
* @return array Users and warnings to pass back to the calling widget.
*/
public static function execute(int $courseid): array {
global $PAGE;
self::validate_parameters(
self::execute_parameters(),
[
'courseid' => $courseid,
]
);
$warnings = [];
$context = context_course::instance($courseid);
self::validate_context($context);
require_capability('gradereport/grader:view', $context);
// Return tracking object.
$gpr = new \grade_plugin_return(
[
'type' => 'report',
'plugin' => 'grader',
'courseid' => $courseid
]
);
$report = new grade_report_grader($courseid, $gpr, $context);
$userfieldsapi = \core_user\fields::for_identity($context, false)->with_userpic();
$extrauserfields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
// For the returned users, Add a couple of extra fields that we need for the search module.
$users = array_map(function ($user) use ($PAGE, $extrauserfields) {
$userforselector = new \stdClass();
$userforselector->id = $user->id;
$userforselector->fullname = fullname($user);
foreach (\core_user\fields::get_name_fields() as $field) {
$userforselector->$field = $user->$field ?? null;
}
$userpicture = new user_picture($user);
$userpicture->size = 1;
$userforselector->profileimageurl = $userpicture->get_url($PAGE)->out(false);
$userpicture->size = 0; // Size f2.
$userforselector->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false);
foreach ($extrauserfields as $field) {
$userforselector->$field = $user->$field ?? null;
}
return $userforselector;
}, $report->load_users(true));
sort($users);
return [
'users' => $users,
'warnings' => $warnings,
];
}
/**
* Returns description of what the users & warnings should return.
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'users' => new external_multiple_structure(core_user_external::user_description()),
'warnings' => new external_warnings(),
]);
}
}
@@ -0,0 +1,184 @@
<?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/>.
namespace gradereport_grader\output;
use core\output\comboboxsearch;
use core_grades\output\general_action_bar;
use moodle_url;
/**
* Renderable class for the action bar elements in the grader report.
*
* @package gradereport_grader
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class action_bar extends \core_grades\output\action_bar {
/** @var string $usersearch The content that the current user is looking for. */
protected string $usersearch = '';
/** @var int $userid The ID of the user that the current user is looking for. */
protected int $userid = 0;
/**
* The class constructor.
*
* @param \context_course $context The context object.
*/
public function __construct(\context_course $context) {
parent::__construct($context);
$this->userid = optional_param('gpr_userid', 0, PARAM_INT);
$this->usersearch = optional_param('gpr_search', '', PARAM_NOTAGS);
if ($this->userid) {
$user = \core_user::get_user($this->userid);
$this->usersearch = fullname($user);
}
}
/**
* Returns the template for the action bar.
*
* @return string
*/
public function get_template(): string {
return 'gradereport_grader/action_bar';
}
/**
* Export the data for the mustache template.
*
* @param \renderer_base $output renderer to be used to render the action bar elements.
* @return array
* @throws \moodle_exception
*/
public function export_for_template(\renderer_base $output): array {
global $PAGE, $OUTPUT, $SESSION, $USER;
// If in the course context, we should display the general navigation selector in gradebook.
$courseid = $this->context->instanceid;
// Get the data used to output the general navigation selector.
$generalnavselector = new general_action_bar($this->context,
new moodle_url('/grade/report/grader/index.php', ['id' => $courseid]), 'gradereport', 'grader');
$data = $generalnavselector->export_for_template($output);
// If the user has the capability to view all grades, display the group selector (if applicable), the user selector
// and the view mode selector (if applicable).
if (has_capability('moodle/grade:viewall', $this->context)) {
$course = get_course($courseid);
$gradesrenderer = $PAGE->get_renderer('core_grades');
$initialscontent = $gradesrenderer->initials_selector(
$course,
$this->context,
'/grade/report/grader/index.php'
);
$firstnameinitial = $SESSION->gradereport["filterfirstname-{$this->context->id}"] ?? '';
$lastnameinitial = $SESSION->gradereport["filtersurname-{$this->context->id}"] ?? '';
$initialselector = new comboboxsearch(
false,
$initialscontent->buttoncontent,
$initialscontent->dropdowncontent,
'initials-selector',
'initialswidget',
'initialsdropdown',
$initialscontent->buttonheader,
true,
get_string('filterbyname', 'core_grades'),
'nameinitials',
json_encode([
'first' => $firstnameinitial,
'last' => $lastnameinitial,
])
);
$data['initialselector'] = $initialselector->export_for_template($output);
$data['groupselector'] = $gradesrenderer->group_selector($course);
$resetlink = new moodle_url('/grade/report/grader/index.php', ['id' => $courseid]);
$searchinput = $OUTPUT->render_from_template('core_user/comboboxsearch/user_selector', [
'currentvalue' => $this->usersearch,
'courseid' => $courseid,
'instance' => rand(),
'resetlink' => $resetlink->out(false),
'group' => 0,
'name' => 'usersearch',
'value' => json_encode([
'userid' => $this->userid,
'search' => $this->usersearch,
]),
]);
$searchdropdown = new comboboxsearch(
true,
$searchinput,
null,
'user-search d-flex',
null,
'usersearchdropdown overflow-auto',
null,
false,
);
$data['searchdropdown'] = $searchdropdown->export_for_template($output);
// The collapsed column dialog is aligned to the edge of the screen, we need to place it such that it also aligns.
$collapsemenudirection = right_to_left() ? 'dropdown-menu-left' : 'dropdown-menu-right';
$collapse = new comboboxsearch(
true,
get_string('collapsedcolumns', 'gradereport_grader', 0),
null,
'collapse-columns',
'collapsecolumn',
'collapsecolumndropdown p-3 flex-column ' . $collapsemenudirection,
null,
true,
get_string('aria:dropdowncolumns', 'gradereport_grader'),
'collapsedcolumns'
);
$data['collapsedcolumns'] = [
'classes' => 'd-none',
'content' => $collapse->export_for_template($output)
];
if ($course->groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $this->context)) {
$allowedgroups = groups_get_all_groups($course->id, 0, $course->defaultgroupingid);
} else {
$allowedgroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid);
}
if (
$firstnameinitial ||
$lastnameinitial ||
groups_get_course_group($course, true, $allowedgroups) ||
$this->usersearch
) {
$reset = new moodle_url('/grade/report/grader/index.php', [
'id' => $courseid,
'group' => 0,
'sifirst' => '',
'silast' => ''
]);
$data['pagereset'] = $reset->out(false);
}
}
return $data;
}
}
@@ -0,0 +1,170 @@
<?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/>.
/**
* Privacy Subsystem implementation for gradereport_grader.
*
* @package gradereport_grader
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace gradereport_grader\privacy;
defined('MOODLE_INTERNAL') || die();
use \core_privacy\local\metadata\collection;
use \core_privacy\local\request\transform;
use \core_privacy\local\request\writer;
require_once $CFG->libdir.'/grade/constants.php';
/**
* Privacy Subsystem for gradereport_grader implementing null_provider.
*
* @copyright 2018 Sara Arjona <sara@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
\core_privacy\local\request\user_preference_provider {
/**
* Returns meta data about this system.
*
* @param collection $itemcollection The initialised item collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $items): collection {
// There are several user preferences (shared between different courses).
// Show/hide toggles preferences.
$items->add_user_preference('grade_report_showaverages', 'privacy:metadata:preference:grade_report_showaverages');
$items->add_user_preference('grade_report_showuserimage', 'privacy:metadata:preference:grade_report_showuserimage');
$items->add_user_preference('grade_report_showranges', 'privacy:metadata:preference:grade_report_showranges');
// Special rows preferences.
$items->add_user_preference('grade_report_rangesdisplaytype', 'privacy:metadata:preference:grade_report_rangesdisplaytype');
$items->add_user_preference('grade_report_rangesdecimalpoints', 'privacy:metadata:preference:grade_report_rangesdecimalpoints');
$items->add_user_preference('grade_report_averagesdisplaytype', 'privacy:metadata:preference:grade_report_averagesdisplaytype');
$items->add_user_preference('grade_report_averagesdecimalpoints', 'privacy:metadata:preference:grade_report_averagesdecimalpoints');
$items->add_user_preference('grade_report_meanselection', 'privacy:metadata:preference:grade_report_meanselection');
$items->add_user_preference('grade_report_shownumberofgrades', 'privacy:metadata:preference:grade_report_shownumberofgrades');
// General preferences.
$items->add_user_preference('grade_report_quickgrading', 'privacy:metadata:preference:grade_report_quickgrading');
$items->add_user_preference('grade_report_studentsperpage', 'privacy:metadata:preference:grade_report_studentsperpage');
$items->add_user_preference('grade_report_showonlyactiveenrol', 'privacy:metadata:preference:grade_report_showonlyactiveenrol');
$items->add_user_preference('grade_report_aggregationposition', 'privacy:metadata:preference:grade_report_aggregationposition');
// There is also one user preference which can be defined on each course.
$items->add_user_preference('grade_report_grader_collapsed_categories', 'privacy:metadata:preference:grade_report_grader_collapsed_categories');
return $items;
}
/**
* Store all user preferences for the plugin.
*
* @param int $userid The userid of the user whose data is to be exported.
*/
public static function export_user_preferences(int $userid) {
$preferences = get_user_preferences(null, null, $userid);
foreach ($preferences as $name => $value) {
$prefname = null;
$prefdescription = null;
$transformedvalue = null;
switch ($name) {
case 'grade_report_showaverages':
case 'grade_report_showuserimage':
case 'grade_report_showranges':
case 'grade_report_shownumberofgrades':
case 'grade_report_quickgrading':
case 'grade_report_showonlyactiveenrol':
case 'grade_report_meanselection':
$prefname = $name;
switch ($value) {
case GRADE_REPORT_MEAN_ALL:
$transformedvalue = get_string('meanall', 'grades');
break;
case GRADE_REPORT_MEAN_GRADED:
$transformedvalue = get_string('meangraded', 'grades');
break;
}
break;
case 'grade_report_rangesdecimalpoints':
case 'grade_report_averagesdecimalpoints':
case 'grade_report_studentsperpage':
$prefname = $name;
$transformedvalue = $value;
break;
case 'grade_report_rangesdisplaytype':
case 'grade_report_averagesdisplaytype':
$prefname = $name;
switch ($value) {
case GRADE_REPORT_PREFERENCE_INHERIT:
$transformedvalue = get_string('inherit', 'grades');
break;
case GRADE_DISPLAY_TYPE_REAL:
$transformedvalue = get_string('real', 'grades');
break;
case GRADE_DISPLAY_TYPE_PERCENTAGE:
$transformedvalue = get_string('percentage', 'grades');
break;
case GRADE_DISPLAY_TYPE_LETTER:
$transformedvalue = get_string('letter', 'grades');
break;
}
break;
case 'grade_report_aggregationposition':
$prefname = $name;
switch ($value) {
case GRADE_REPORT_AGGREGATION_POSITION_FIRST:
$transformedvalue = get_string('positionfirst', 'grades');
break;
case GRADE_REPORT_AGGREGATION_POSITION_LAST:
$transformedvalue = get_string('positionlast', 'grades');
break;
}
break;
default:
if (strpos($name, 'grade_report_grader_collapsed_categories') === 0) {
$prefname = 'grade_report_grader_collapsed_categories';
$courseid = substr($name, strlen('grade_report_grader_collapsed_categories'));
$transformedvalue = $value;
$course = get_course($courseid);
$prefdescription = get_string(
'privacy:request:preference:'.$prefname,
'gradereport_grader',
(object) [
'name' => $course->fullname,
]
);
}
}
if ($prefname !== null) {
if ($prefdescription == null) {
$prefdescription = get_string('privacy:metadata:preference:'.$prefname, 'gradereport_grader');
}
writer::export_user_preference(
'gradereport_grader',
$prefname,
$transformedvalue,
$prefdescription
);
}
}
}
}