Skip to content

Commit

Permalink
using feedback_tracker methods for getting due dates and missing mark…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
Matthias Opitz committed Jan 8, 2025
1 parent 0cc28ba commit 7b44e91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 99 deletions.
113 changes: 14 additions & 99 deletions block_my_feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use core_course\external\course_summary_exporter;
use local_assess_type\assess_type; // UCL plugin.
use mod_quiz\question\display_options;
use report_feedback_tracker\local\admin as feedback_tracker;

/**
* Block definition class for the block_my_feedback plugin.
Expand Down Expand Up @@ -208,25 +209,18 @@ public static function fetch_marking(stdClass $user): ?array {
*/
public static function get_mod_data($mod, $assess): ?stdClass {
global $CFG, $DB;
// Mods have different fields for due date.
switch ($mod->modname) {
case 'assign':
// Check mod due date is relevant.
$duedate = self::duedate_in_range($mod->customdata['duedate']);
break;
case 'quiz':
$record = $DB->get_record('quiz', ['id' => $mod->instance], 'timeclose');
// Check if mod due date is present and relevant.
$duedate = isset($record->timeclose) ? self::duedate_in_range($record->timeclose) : false;
break;
case 'turnitintooltwo':
$record = $DB->get_record('turnitintooltwo_parts', ['id' => $assess->partid], 'dtdue');
// Check if mod due date is present and relevant.
$duedate = isset($record->dtdue) ? self::duedate_in_range($record->dtdue) : false;
break;
default:

// Turnitin features a due date per part and therefore needs to be treated separately here.
if ($mod->modname === 'turnitintooltwo') {
if (!isset($assess->partid)) { // If there is no Turnitin part ID there is no due date.
return null;
}
$record = $DB->get_record('turnitintooltwo_parts', ['id' => $assess->partid], 'dtdue');
$duedate = $record->dtdue;
} else {
$duedate = feedback_tracker::get_duedate($mod);
}
$duedate = self::duedate_in_range($duedate);
if (!$duedate) {
return null;
}
Expand All @@ -236,7 +230,8 @@ public static function get_mod_data($mod, $assess): ?stdClass {
$assess->duedate = date('jS M', $duedate);

// Require marking.
$assess->requiremarking = self::get_required_markings($mod);
require_once($CFG->dirroot.'/mod/assign/locallib.php');
$assess->requiremarking = feedback_tracker::count_missing_grades($mod);
if (!$assess->requiremarking) {
return null;
}
Expand All @@ -249,94 +244,14 @@ public static function get_mod_data($mod, $assess): ?stdClass {

}

/**
* Get the required markings for an assessment module.
*
* @param cm_info $mod
* @return int
* @throws dml_exception
*/
protected static function get_required_markings(cm_info $mod) {
global $CFG, $DB;

// Assignments provide a way to count submissions that needs grading.
if ($mod->modname === 'assign') {
require_once($CFG->dirroot.'/mod/assign/locallib.php');
$context = context_module::instance($mod->id);
$assignment = new assign($context, $mod, $mod->course);
return $assignment->count_submissions_need_grading();
}

// For modules other than assignments get the student IDs that have submissions.
if ($submissions = self::get_module_submissions($mod)) {
$sql = "SELECT DISTINCT gg.userid
FROM {grade_grades} gg
WHERE gg.itemid = :modid AND gg.finalgrade > :finalgrade";
$params = ['modid' => $mod->id, 'finalgrade' => -1];

// Execute the query.
$studentids = $DB->get_fieldset_sql($sql, $params);
// Count and return all student IDs in submission that are not (yet) to be found in gradings.
$missinggrades = 0;
foreach ($submissions as $submitterid) {
if (!in_array($submitterid, $studentids)) {
$missinggrades++;
}
}
return $missinggrades;
}
// No submissions - no missing grades.
return 0;
}

/**
* Get an array of distinct student IDs with submissions for a given module.
*
* @param cm_info $mod
* @return array
*/
public static function get_module_submissions(cm_info $mod): array {
global $DB;

if ($mod) {
switch ($mod->modname) {
case 'assign':
// No need to support here, as assignments provide their own methods to count submissions and gradings.
return [];
case 'lesson':
$sql = "SELECT DISTINCT userid FROM {lesson_attempts} WHERE lessonid = :lessonid";
$params = ['lessonid' => $mod->instance, 'correct' => 1];
break;
case 'quiz':
$sql = "SELECT DISTINCT userid FROM {quiz_attempts} WHERE quiz = :quiz AND state = :state";
$params = ['quiz' => $mod->instance, 'state' => 'finished'];
break;
case 'turnitintooltwo':
$sql = "SELECT DISTINCT userid FROM {turnitintooltwo_submissions} WHERE turnitintooltwoid = :turnitintooltwoid";
$params = ['turnitintooltwoid' => $mod->instance];
break;
case 'scorm':
return [];
case 'workshop':
$sql = "SELECT DISTINCT authorid FROM {workshop_submissions} WHERE workshopid = :workshopid";
$params = ['workshopid' => $mod->instance];
break;
default:
return [];
}
return $DB->get_fieldset_sql($sql, $params);
}
return [];
}

/**
* Get separate parts for a turnitin module.
*
* @param cm_info $mod
* @return array
* @throws dml_exception
*/
public static function get_turnitin_parts(cm_info $mod) {
private static function get_turnitin_parts(cm_info $mod) {
global $DB;

$sql = "SELECT * FROM {turnitintooltwo_parts} WHERE turnitintooltwoid = :iteminstance";
Expand Down
1 change: 1 addition & 0 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
$plugin->component = 'block_my_feedback'; // Full name of the plugin (used for diagnostics).
$plugin->dependencies = [
'local_assess_type' => 2024091300,
'report_feedback_tracker' => 2025010600,
];

0 comments on commit 7b44e91

Please sign in to comment.