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,240 @@
<?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_summary\local\entities;
use core_reportbuilder\local\filters\select;
use grade_item;
use grade_plugin_return;
use grade_report_summary;
use lang_string;
use stdClass;
use core_reportbuilder\local\entities\base;
use core_reportbuilder\local\report\column;
use core_reportbuilder\local\report\filter;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/grade/report/summary/lib.php');
require_once($CFG->dirroot . '/grade/lib.php');
/**
* Grade summary entity class implementation
*
* @package gradereport_summary
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grade_items extends base {
/** @var stdClass Course */
public $course;
/** @var grade_report_summary Grade report. */
public $report;
/** @var array Ungraded grade items counts with sql info. */
public $ungradedcounts;
/**
* Entity constructor
*
* @param stdClass $course
*/
public function __construct(stdClass $course) {
$this->course = $course;
}
/**
* Database tables that this entity uses
*
* @return string[]
*/
protected function get_default_tables(): array {
return [
'grade_items',
];
}
/**
* The default title for this entity in the list of columns/conditions/filters in the report builder
*
* @return lang_string
*/
protected function get_default_entity_title(): lang_string {
return new lang_string('gradeitem', 'grades');
}
/**
* Initialise the entity
*
* @return base
*/
public function initialise(): base {
$context = \context_course::instance($this->course->id);
$gpr = new grade_plugin_return(
[
'type' => 'report',
'plugin' => 'summary',
'course' => $this->course,
]
);
$this->report = new grade_report_summary($this->course->id, $gpr, $context);
$showonlyactiveenrol = $this->report->show_only_active();
$this->ungradedcounts = $this->report->ungraded_counts(false, false, $showonlyactiveenrol);
$columns = $this->get_all_columns();
foreach ($columns as $column) {
$this->add_column($column);
}
$filters = $this->get_all_filters();
foreach ($filters as $filter) {
$this->add_filter($filter);
}
return $this;
}
/**
* Returns list of all available columns
*
* @return column[]
*/
protected function get_all_columns(): array {
$tablealias = $this->get_table_alias('grade_items');
$selectsql = "$tablealias.id, $tablealias.itemname, $tablealias.iteminstance, $tablealias.calculation,
$tablealias.itemnumber, $tablealias.itemmodule, $tablealias.hidden, $tablealias.courseid";
// Grade item name column.
$columns[] = (new column(
'name',
null,
$this->get_entity_name()
))
->add_joins($this->get_joins())
->set_type(column::TYPE_TEXT)
->add_fields($selectsql)
->add_callback(static function($value, $row): string {
$gradeitem = grade_item::fetch(['id' => $row->id, 'courseid' => $row->courseid]);
$element = ['type' => 'item', 'object' => $gradeitem, 'modinfo' => get_fast_modinfo($row->courseid)];
$fullname = \grade_helper::get_element_header($element, true, false, true, true, true);
$icon = \grade_helper::get_element_icon($element);
$elementtype = \grade_helper::get_element_type_string($element);
$itemtype = \html_writer::span($elementtype, 'd-block text-uppercase small dimmed_text',
['title' => $elementtype]);
$content = \html_writer::div($itemtype . $fullname);
$dimmed = '';
if ($row->hidden) {
$dimmed = ' dimmed_text';
}
return \html_writer::div($icon . $content, "item d-flex align-items-center" . $dimmed);
});
$report = [
'report' => $this->report,
'ungradedcounts' => $this->ungradedcounts
];
// Average column.
$columns[] = (new column(
'average',
new lang_string('average', 'grades'),
$this->get_entity_name()
))
->add_joins($this->get_joins())
->set_type(column::TYPE_TEXT)
->add_field("$tablealias.id")
->add_callback(static function($value) use ($report): string {
$gradeitem = grade_item::fetch(['id' => $value]);
if (!empty($gradeitem->avg)) {
$averageformatted = '-';
}
if ($gradeitem->needsupdate) {
$averageformatted = get_string('error');
}
if (empty($averageformatted)) {
$ungradedcounts = $report['ungradedcounts'];
$aggr = $report['report']->calculate_average($gradeitem, $ungradedcounts);
if (empty($aggr['average'])) {
$averageformatted = '-';
} else {
$averagesdisplaytype = $ungradedcounts['report']['averagesdisplaytype'];
$averagesdecimalpoints = $ungradedcounts['report']['averagesdecimalpoints'];
$shownumberofgrades = $ungradedcounts['report']['shownumberofgrades'];
// Determine which display type to use for this average.
// No ==0 here, please resave the report and user preferences.
if ($averagesdisplaytype == GRADE_REPORT_PREFERENCE_INHERIT) {
$displaytype = $gradeitem->get_displaytype();
} else {
$displaytype = $averagesdisplaytype;
}
// Override grade_item setting if a display preference (not inherit) was set for the averages.
if ($averagesdecimalpoints == GRADE_REPORT_PREFERENCE_INHERIT) {
$decimalpoints = $gradeitem->get_decimals();
} else {
$decimalpoints = $averagesdecimalpoints;
}
$gradehtml = grade_format_gradevalue($aggr['average'],
$gradeitem, true, $displaytype, $decimalpoints);
if ($shownumberofgrades) {
$numberofgrades = $aggr['meancount'];
$gradehtml .= " (" . $numberofgrades . ")";
}
$averageformatted = $gradehtml;
}
}
return $averageformatted;
});
return $columns;
}
/**
* Return list of all available filters
*
* @return filter[]
*/
protected function get_all_filters(): array {
$tablealias = $this->get_table_alias('grade_items');
// Activity type filter (for performance only load options on demand).
$filters[] = (new filter(
select::class,
'name',
new lang_string('activitytype', 'format_singleactivity'),
$this->get_entity_name(),
"coalesce({$tablealias}.itemmodule,{$tablealias}.itemtype)"
))
->add_joins($this->get_joins())
->set_options_callback([$this->report, 'item_types']);
return $filters;
}
}
@@ -0,0 +1,111 @@
<?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_summary\local\systemreports;
use gradereport_summary\local\entities\grade_items;
use core_reportbuilder\local\helpers\database;
use core_reportbuilder\system_report;
/**
* Grade summary system report class implementation
*
* @package gradereport_summary
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class summary extends system_report {
/**
* Initialise report, we need to set the main table, load our entities and set columns/filters
*/
protected function initialise(): void {
global $PAGE;
// We need to ensure page context is always set, as required by output and string formatting.
$course = get_course($this->get_context()->instanceid);
$PAGE->set_context($this->get_context());
// Our main entity, it contains all of the column definitions that we need.
$entitymain = new grade_items($course);
$entitymainalias = $entitymain->get_table_alias('grade_items');
$this->set_main_table('grade_items', $entitymainalias);
$this->add_entity($entitymain);
$param1 = database::generate_param_name();
$param2 = database::generate_param_name();
$param3 = database::generate_param_name();
// Exclude grade categories.
// For now exclude course total as well.
$wheresql = "$entitymainalias.courseid = :$param1";
$wheresql .= " AND $entitymainalias.itemtype <> 'course'";
// Not showing category items.
$wheresql .= " AND $entitymainalias.itemtype <> 'category'";
// Only value and scale grade types may be aggregated.
$wheresql .= " AND ($entitymainalias.gradetype = :$param2 OR $entitymainalias.gradetype = :$param3)";
$this->add_base_condition_sql($wheresql,
[$param1 => $course->id, $param2 => GRADE_TYPE_VALUE, $param3 => GRADE_TYPE_SCALE]);
// Now we can call our helper methods to add the content we want to include in the report.
$this->add_columns();
$this->add_filters();
}
/**
* Validates access to view this report
*
* @return bool
*/
protected function can_view(): bool {
return has_capability('gradereport/summary:view', $this->get_context());
}
/**
* Adds the columns we want to display in the report
*
* They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
* unique identifier
*/
public function add_columns(): void {
$columns = [
'grade_items:name',
'grade_items:average',
];
$this->add_columns_from_entities($columns);
}
/**
* Adds the filters we want to display in the report
*
* They are all provided by the entities we previously added in the {@see initialise} method, referencing each by their
* unique identifier
*/
protected function add_filters(): void {
$filters = [
'grade_items:name',
];
$this->add_filters_from_entities($filters);
}
}
@@ -0,0 +1,44 @@
<?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_summary.
*
* @package gradereport_summary
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace gradereport_summary\privacy;
/**
* Privacy Subsystem for gradereport_summary implementing null_provider.
*
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+38
View File
@@ -0,0 +1,38 @@
<?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/>.
/**
* The gradebook summary view - Database file
*
* @package gradereport_summary
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = [
'gradereport/summary:view' => [
'riskbitmask' => RISK_PERSONAL,
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
'editingteacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
]
]
];
+55
View File
@@ -0,0 +1,55 @@
<?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/>.
/**
* Grade summary.
*
* @package gradereport_summary
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../../config.php');
require_once("{$CFG->libdir}/adminlib.php");
require_once($CFG->dirroot.'/grade/lib.php');
use core_reportbuilder\system_report_factory;
use gradereport_summary\local\systemreports\summary;
$courseid = required_param('id', PARAM_INT);
if (!$course = $DB->get_record('course', ['id' => $courseid])) {
throw new \moodle_exception('invalidcourseid');
}
require_login($course);
$context = context_course::instance($course->id);
$PAGE->set_url('/grade/report/summary/index.php', ['id' => $courseid]);
$PAGE->set_context($context);
$PAGE->set_pagelayout('report');
$PAGE->add_body_class('limitedwidth');
require_capability('gradereport/summary:view', $context);
require_capability('moodle/grade:viewall', $context);
print_grade_page_head($courseid, 'report', 'summary', false,
false, false, true, null, null,
null, null);
$report = system_report_factory::create(summary::class, context_course::instance($courseid));
echo $report->output();
echo $OUTPUT->footer();
@@ -0,0 +1,28 @@
<?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/>.
/**
* Strings for Summary view
*
* @package gradereport_summary
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// General Strings.
$string['pluginname'] = 'Grade summary';
$string['summary:view'] = 'View grade summary report';
$string['privacy:metadata'] = 'The Grade summary report only shows data stored in other locations.';
+90
View File
@@ -0,0 +1,90 @@
<?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/>.
defined('MOODLE_INTERNAL') || die;
/**
* Definition of the summary report class
*
* @package gradereport_summary
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/grade/report/lib.php');
/**
* Class providing an API for the summary report building.
*
* @package gradereport_summary
* @uses grade_report
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grade_report_summary extends grade_report {
/**
* Capability check caching
*
* @var boolean $canviewhidden
*/
public $canviewhidden;
/**
* Constructor. Sets local copies of user preferences and initialises grade_tree.
*
* @param int $courseid
* @param object $gpr grade plugin return tracking object
* @param context_course $context
*/
public function __construct($courseid, $gpr, $context) {
parent::__construct($courseid, $gpr, $context);
$this->canviewhidden = has_capability('moodle/grade:viewhidden', $context);
$this->setup_groups();
}
/**
* Processes a single action against a category, grade_item or grade. Not used in summary report.
*
* @param string $target eid ({type}{id}, e.g. c4 for category4)
* @param string $action Which action to take (edit, delete etc...)
*/
public function process_action($target, $action) {
}
/**
* Handles form data sent by this report for this report. Not used in summary report.
*
* @param array $data
*/
public function process_data($data) {
}
/**
* To check if we only need to include active enrolments.
*
* @return bool
*/
public function show_only_active(): bool {
// Limit to users with an active enrolment.
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
return $showonlyactiveenrol ||
!has_capability('moodle/course:viewsuspendedusers', $this->context);
}
}
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* Standard version file
*
* @package gradereport_summary
* @copyright 2022 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'gradereport_summary'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2024042200;
$plugin->requires = 2024041600;