Skip to content

Commit

Permalink
TW20848847, cleaning up code
Browse files Browse the repository at this point in the history
  • Loading branch information
MichPound authored and learningtechnologyservices committed Jan 10, 2025
1 parent 7788e0c commit 0a25729
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 18 deletions.
58 changes: 53 additions & 5 deletions classes/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@
*/
class report extends grade_report {

/** @var int Activity id. */
public $activityid = 0;
/** @var string Activity name. */
public $activityname = '';
/** @var string Download format. */
public $format = '';
/** @var bool Whether the download is excel. */
public $excel = false;
/** @var bool Whether the download is csv. */
public $csv = false;
/** @var bool Whether to display levels. */
public $displaylevel = false;
/** @var bool Whether to display remarks. */
public $displayremark = false;
/** @var bool Whether to display summary. */
public $displaysummary = false;
/** @var bool Whether to display id numbers. */
public $displayidnumber = false;
/** @var bool Whether to display emails. */
public $displayemail = false;
/** @var bool Whether to display feedback. */
public $displayfeedback = false;
/** @var grade_item Course grade items. */
public $coursegradeitem = null;

/** @var array Defines variables for each gradable activity. */
const GRADABLES = [
'assign' => ['table' => 'assign_grades', 'field' => 'assignment', 'itemoffset' => 0, 'showfeedback' => 1],
Expand All @@ -58,11 +83,36 @@ class report extends grade_report {
* @param int $courseid
* @param object $gpr
* @param string $context
* @param int $activityid
* @param string $format
* @param bool $excel
* @param bool $csv
* @param bool $displaylevel
* @param bool $displayremark
* @param bool $displaysummary
* @param bool $displayidnumber
* @param bool $displayemail
* @param string $activityname
* @param bool $displayfeedback
* @param int|null $page
*/
public function __construct($courseid, $gpr, $context, $page=null) {
public function __construct($courseid, $gpr, $context, $activityid, $format, $excel, $csv, $displaylevel,
$displayremark, $displaysummary, $displayidnumber, $displayemail, $activityname, $displayfeedback, $page=null) {
parent::__construct($courseid, $gpr, $context, $page);
$this->course_grade_item = grade_item::fetch_course_item($this->courseid);

$this->activityid = $activityid;
$this->format = $format;
$this->excel = $excel;
$this->csv = $csv;
$this->displaylevel = $displaylevel;
$this->displayremark = $displayremark;
$this->displaysummary = $displaysummary;
$this->displayidnumber = $displayidnumber;
$this->displayemail = $displayemail;
$this->activityname = $activityname;
$this->displayfeedback = $displayfeedback;

$this->coursegradeitem = grade_item::fetch_course_item($this->courseid);
}

/**
Expand Down Expand Up @@ -100,8 +150,7 @@ public function show() {

// Step one, find all enrolled users to course.
$coursecontext = context_course::instance($this->courseid);
$users = get_enrolled_users($coursecontext, $withcapability = 'mod/assign:submit', $groupid = 0,
$userfields = 'u.*', $orderby = 'u.lastname');
$users = get_enrolled_users($coursecontext, 'mod/assign:submit', 0, 'u.*', 'u.lastname');
$data = [];

// Process relevant grading area id from activityid and courseid.
Expand Down Expand Up @@ -290,7 +339,6 @@ public function show() {
* @return array|string
*/
public function display_table($data, $rubricarray, $csv) {
global $DB, $CFG;
$summaryarray = [];
$csvarray = [];

Expand Down
29 changes: 17 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,23 @@

$gpr = new grade_plugin_return(array('type' => 'report', 'plugin' => 'grader',
'courseid' => $courseid)); // Return tracking object.
$report = new report($courseid, $gpr, $context); // Initialise the grader report object.
$report->activityid = $activityid;
$report->format = $format;
$report->excel = $format == 'excelcsv';
$report->csv = $format == 'csv' || $report->excel;
$report->displaylevel = ($displaylevel == 1);
$report->displayremark = ($displayremark == 1);
$report->displaysummary = ($displaysummary == 1);
$report->displayidnumber = ($displayidnumber == 1);
$report->displayemail = ($displayemail == 1);
$report->activityname = $activityname;
$report->displayfeedback = $displayfeedback ?? false;
$report = new report(
$courseid,
$gpr,
$context,
$activityid,
$format,
$format == 'excelcsv',
$format == 'csv' || $excel,
($displaylevel == 1),
($displayremark == 1),
($displaysummary == 1),
($displayidnumber == 1),
($displayemail == 1),
$activityname,
$displayfeedback ?? false,
null
); // Initialise the grader report object.

$table = $report->show();
echo $table;
Expand Down
2 changes: 1 addition & 1 deletion select_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class report_rubrics_select_form extends moodleform {
* @return void
*/
public function definition() {
global $CFG, $DB;
global $DB;

$sql = "SELECT cm.id, cm.course, con.id AS con_id, con.path, gra.id AS gra_id
FROM {course_modules} cm
Expand Down

0 comments on commit 0a25729

Please sign in to comment.