2023-05-17 21:19:14 +02:00
< ? php
2023-08-24 23:02:41 +02:00
// This file is part of the Studyplan plugin for Moodle
//
// 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 <https://www.gnu.org/licenses/>.
/**
*
* @ package local_treestudyplan
* @ copyright 2023 P . M . Kuipers
* @ license https :// www . gnu . org / copyleft / gpl . html GNU GPL v3 or later
*/
2023-05-17 21:19:14 +02:00
namespace local_treestudyplan\local\ungradedscanners ;
class assign_scanner extends scanner_base {
2023-08-24 23:02:41 +02:00
protected function get_ungraded_submissions () {
2023-05-17 21:19:14 +02:00
global $DB ;
2023-08-24 23:02:41 +02:00
//SELECT asgn_sub.id as submissionid, a.id as instanceid, asgn_sub.userid as userid, asgn_sub.timemodified as timesubmitted, asgn_sub.attemptnumber , a.maxattempts.
2023-05-17 21:19:14 +02:00
$sql = " SELECT DISTINCT asgn_sub.userid
FROM { assign_submission } asgn_sub
JOIN { assign } a ON a . id = asgn_sub . assignment
LEFT JOIN { assign_grades } ag ON ag . assignment = asgn_sub . assignment AND ag . userid = asgn_sub . userid AND
asgn_sub . attemptnumber = ag . attemptnumber
2023-08-24 23:02:41 +02:00
WHERE a . id = { $this -> gi -> iteminstance }
2023-05-17 21:19:14 +02:00
AND asgn_sub . status = 'submitted'
2023-08-24 23:02:41 +02:00
AND asgn_sub . userid > 0
2023-05-17 21:19:14 +02:00
AND a . grade <> 0 AND ( ag . id IS NULL OR asgn_sub . timemodified >= ag . timemodified )
" ;
2023-08-24 23:02:41 +02:00
2023-05-17 21:19:14 +02:00
return $DB -> get_fieldset_sql ( $sql );
}
2023-08-24 23:02:41 +02:00
protected function get_graded_users () {
2023-05-17 21:19:14 +02:00
global $DB ;
2023-08-24 23:02:41 +02:00
$sql = " SELECT DISTINCT g.userid
FROM { grade_grades } g
LEFT JOIN { grade_items } gi on g . itemid = gi . id
2023-05-17 21:19:14 +02:00
WHERE gi . itemmodule = 'assign' AND gi . iteminstance = { $this -> gi -> iteminstance }
2023-08-24 23:02:41 +02:00
AND g . finalgrade IS NOT NULL " ; // MAy turn out to be needed, dunno.
2023-05-17 21:19:14 +02:00
return $DB -> get_fieldset_sql ( $sql );
}
2023-08-25 09:33:42 +02:00
public function count_ungraded ( $courseuserids = []) {
2023-05-17 21:19:14 +02:00
$ungraded = $this -> get_ungraded_submissions ();
2023-08-25 09:33:42 +02:00
if ( count ( $courseuserids ) > 0 ) {
$ungraded = array_intersect ( $ungraded , $courseuserids );
2023-05-17 21:19:14 +02:00
}
return count ( $ungraded );
}
2023-08-25 09:33:42 +02:00
public function count_graded ( $courseuserids = []) {
2023-05-17 21:19:14 +02:00
$ungraded = $this -> get_ungraded_submissions ();
$graded = $this -> get_graded_users ();
2023-08-25 09:33:42 +02:00
if ( count ( $courseuserids ) > 0 ) {
$ungraded = array_intersect ( $ungraded , $courseuserids );
$graded = array_intersect ( $graded , $courseuserids );
2023-05-17 21:19:14 +02:00
}
2023-08-24 23:02:41 +02:00
// determine how many id's have a grade, but also an ungraded submission.
$dual = array_intersect ( $ungraded , $graded );
// subtract those from the graded count.
2023-05-17 21:19:14 +02:00
return count ( $graded ) - count ( $dual );
}
2023-08-24 23:02:41 +02:00
public function has_ungraded_submission ( $userid ) {
2023-05-17 21:19:14 +02:00
$ungraded = $this -> get_ungraded_submissions ();
2023-08-24 23:02:41 +02:00
return in_array ( $userid , $ungraded );
2023-05-17 21:19:14 +02:00
}
}