diff --git a/admin_dashboard/courses_without_teachers.php b/admin_dashboard/courses_without_teachers.php index 6bdc9c8..69046ec 100644 --- a/admin_dashboard/courses_without_teachers.php +++ b/admin_dashboard/courses_without_teachers.php @@ -36,12 +36,11 @@ $delete = optional_param('delete', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_INT); $instance = optional_param('instance', 0, PARAM_INT); +$page = optional_param('page', 0, PARAM_INT); +$perpage = optional_param('perpage', 10, PARAM_INT); $site = get_site(); -$page = optional_param('page', 0, PARAM_INT); -$perpage = optional_param('perpage', 2, PARAM_INT); // how many per page - $PAGE = new moodle_page(); $PAGE->set_context(context_system::instance()); $PAGE->set_heading(get_string('title', 'report_coursemanager')); @@ -95,7 +94,7 @@ echo html_writer::div(get_string('adminnoteachercoursesnote', 'report_coursemanager')); // Checl for entries in coursemanager table for courses without teachers. -$existsnoteacherincourse = $DB->get_records('report_coursemanager_reports', ['report' => 'no_teacher_in_course']); +$existsnoteacherincourse = $DB->get_records('report_coursemanager_reports', ['report' => 'no_teacher_in_course'], ['weight DESC']); if (count($existsnoteacherincourse) > 0) { $table = new html_table(); diff --git a/admin_dashboard/orphaned_submissions.php b/admin_dashboard/orphaned_submissions.php index 81b47ba..9fa6de6 100644 --- a/admin_dashboard/orphaned_submissions.php +++ b/admin_dashboard/orphaned_submissions.php @@ -36,6 +36,9 @@ $delete = optional_param('delete', 0, PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_INT); $instance = optional_param('instance', 0, PARAM_INT); +$course = optional_param('course', 0, PARAM_INT); +$page = optional_param('page', 0, PARAM_INT); +$perpage = optional_param('perpage', 10, PARAM_INT); $site = get_site(); @@ -92,6 +95,8 @@ foreach ($dbresultlistusersorphansubmissions as $userorphan) { $delete = $targetassign->remove_submission($userorphan->id); } + // Now that files are deleted, delete report entry. + $purgereport = $DB->delete_records('report_coursemanager_orphans', ['cmid' => $instance, 'course' => $course, ]); $returnurl = "orphaned_submissions.php"; redirect($returnurl); exit(); @@ -106,7 +111,7 @@ echo $OUTPUT->heading(get_string('title_admin_orphan_submissions', 'report_coursemanager')); $urlconfirmdelete = new moodle_url('orphaned_submissions.php', - ['confirm' => 1, 'delete' => 1, 'instance' => $instance, 'sesskey' => sesskey()]); + ['confirm' => 1, 'delete' => 1, 'instance' => $instance, 'course' => $course, 'sesskey' => sesskey()]); echo $OUTPUT->confirm(get_string('deleteorphansubmissionsconfirm', 'report_coursemanager'), $urlconfirmdelete, @@ -132,78 +137,27 @@ $table->head[] = get_string('table_files_weight', 'report_coursemanager'); $table->head[] = get_string('table_actions', 'report_coursemanager'); -$listcourses = get_courses(); -foreach ($listcourses as $course) { - - $sql = 'SELECT cm.instance, a.name, cm.id - FROM {course_modules} cm - JOIN {course} c ON c.id = cm.course - JOIN {modules} m ON m.id = cm.module - JOIN {assign} a ON a.id = cm.instance - WHERE m.name =\'assign\' - AND c.id = ?'; - $paramsdb = [$course->id]; - $dbresult = $DB->get_records_sql($sql, $paramsdb); - - if (count($dbresult) > 0) { - foreach ($dbresult as $assigninstance) { - $sqlassignsorphans = "SELECT DISTINCT(f.filesize) AS filesize - FROM - {files} AS f, - {assignsubmission_file} AS asf, - {assign} AS a, - {user} AS u, - {course} AS c, - {course_modules} AS cm - WHERE - component = 'assignsubmission_file' - AND asf.submission=f.itemid - AND a.id = asf.assignment - AND f.userid = u.id - AND filename != '.' - AND c.id = a.course - AND a.id = ? - AND a.id = cm.instance - AND u.id NOT IN - (SELECT us.id - FROM - {course} AS course, - {enrol} AS en, - {user_enrolments} AS ue, - {user} AS us - WHERE c.id=course.id - AND en.courseid = course.id - AND ue.enrolid = en.id - AND us.id = ue.userid - ) - GROUP BY filesize - "; - $paramsdbassignsorphans = [$assigninstance->instance]; - $dbresultassignsorphans = $DB->get_records_sql($sqlassignsorphans, $paramsdbassignsorphans); - - if ($dbresultassignsorphans) { - $row = []; - $totalsize = 0; - $totalfiles = 0; - foreach ($dbresultassignsorphans as $orphansubmission) { - $totalsize += $orphansubmission->filesize; - $totalfiles = $totalfiles + 1; - } - $row[] = html_writer::link("/course/view.php?id=".$course->id, $course->fullname); - $row[] = html_writer::link("/mod/assign/view.php?id=".$assigninstance->id, $assigninstance->name); - $row[] = html_writer::label($totalfiles, null); - $row[] = html_writer::label(number_format(ceil($totalsize / 1048576), 0, ',', '')." Mo", null); - $content = "".get_string('deleteorphans', 'report_coursemanager').""; - $row[] = html_writer::label($content, null); - $table->data[] = $row; - - } - } - } else { - $row[] = html_writer::label(get_string('noassign', 'report_coursemanager'), null); - } +// Let's retrieve all records in orphans table. +$listassigns = $DB->get_records('report_coursemanager_orphans', [], 'weight DESC'); +$selectedassigns = array_slice($listassigns, $page * $perpage, $perpage); +foreach ($selectedassigns as $assign) { + $cm = get_coursemodule_from_id('assign', $assign->cmid); + $course = $DB->get_record('course', array('id' => $assign->course)); + // $context = context_module::instance($cm->id); + $row = []; + $row[] = html_writer::link("/course/view.php?id=".$assign->course, $course->fullname); + $row[] = html_writer::link("/mod/assign/view.php?id=".$assign->cmid, $cm->name); + $row[] = html_writer::label($assign->files, null); + $row[] = html_writer::label(number_format(ceil($assign->weight / 1048576), 0, ',', '')." Mo", null); + $content = "".get_string('deleteorphans', 'report_coursemanager').""; + $row[] = html_writer::label($content, null); + $table->data[] = $row; } echo html_writer::table($table); + +$baseurl = new moodle_url('/report/coursemanager/admin_dashboard/orphaned_submissions.php', array('perpage' => $perpage)); +echo $OUTPUT->paging_bar(count($listassigns), $page, $perpage, $baseurl); + echo $OUTPUT->footer(); diff --git a/admin_dashboard/stats.php b/admin_dashboard/stats.php index 2464fdc..e1bf451 100644 --- a/admin_dashboard/stats.php +++ b/admin_dashboard/stats.php @@ -97,15 +97,19 @@ $countemptycourses = $DB->count_records('report_coursemanager_reports', ['report' => 'empty']); // Count courses with orphan submissions in Course Manager table. -$countorphansubmissionscourses = $DB->count_records('report_coursemanager_reports', ['report' => 'orphan_submissions']); +$countorphansubmissionscourses = $DB->count_records('report_coursemanager_orphans'); // Sum filesize in Mo for orphan submissions. if (!empty($countorphansubmissionscourses)) { - $sqltotalorphans = "SELECT ROUND(SUM(detail)/1024/1024) - FROM {report_coursemanager_reports} - WHERE report = 'orphan_submissions' + $sqltotalsizeorphans = "SELECT ROUND(SUM(weight)/1024/1024) + FROM {report_coursemanager_orphans} "; - $totalorphans = $DB->get_field_sql($sqltotalorphans); + $totalsizeorphans = $DB->get_field_sql($sqltotalsizeorphans); + + $sqltotalfilesorphans = "SELECT SUM(files) + FROM {report_coursemanager_orphans} + "; + $totalfilesorphans = $DB->get_field_sql($sqltotalfilesorphans); } // Count courses without teachers in Course Manager table. @@ -187,10 +191,10 @@
'.$countorphansubmissionscourses.'
+ .get_string('stats_files_orphan_submissions_desc', 'report_coursemanager').' +'.$totalfilesorphans.'
'.$totalorphans.' Mo
+'.$totalsizeorphans.' Mo
'; diff --git a/classes/task/mailing_task.php b/classes/task/mailing_task.php index c7a5ce0..5dbf8a9 100644 --- a/classes/task/mailing_task.php +++ b/classes/task/mailing_task.php @@ -128,8 +128,14 @@ public function execute() { // For each report, we test each course for a teacher. foreach ($dbresultlistcoursesforteacher as $listcourse) { // If a report exists for a course, add course name to the list with direct link. - $checkreport = $DB->get_record('report_coursemanager_reports', - ['course' => $listcourse->courseid, 'report' => $report['report']]); + if ($report['report'] == 'orphan_submissions') { + $checkreport = $DB->get_records('report_coursemanager_orphans', + ['course' => $listcourse->courseid]); + } else { + $checkreport = $DB->get_record('report_coursemanager_reports', + ['course' => $listcourse->courseid, 'report' => $report['report']]); + } + if (!empty($checkreport)) { // Heavy report leads to the specific page about course files. if ($report['report'] == 'heavy') { diff --git a/classes/task/run_orphan_submissions_report_task.php b/classes/task/run_orphan_submissions_report_task.php index 63283b0..d5fd339 100644 --- a/classes/task/run_orphan_submissions_report_task.php +++ b/classes/task/run_orphan_submissions_report_task.php @@ -60,7 +60,6 @@ public function execute() { AND instance = ? '; $dbresultcontextid = $DB->get_record_sql($sqlcontextid, [$assign->id]); - $cm = get_coursemodule_from_id('assign', $dbresultcontextid->id); $context = \context_module::instance($cm->id); @@ -90,13 +89,13 @@ public function execute() { foreach ($dbresultassignsorphans as $orphan) { // First check if this report exists. $existsorphans = $DB->get_record('report_coursemanager_orphans', - ['course' => $assign->course, 'contextid' => $context->id]); + ['course' => $assign->course, 'cmid' => $cm->id]); if ($orphan->total_files > 0) { // Orphaned submissions detected for this assign, create or update entry. $data = new \stdClass(); $data->course = $assign->course; - $data->contextid = $context->id; + $data->cmid = $cm->id; $data->weight = $orphan->total_size; $data->files = $orphan->total_files; $data->timecreated = time(); diff --git a/db/install.xml b/db/install.xml index 703cc4b..c1150d6 100644 --- a/db/install.xml +++ b/db/install.xml @@ -1,32 +1,32 @@ - -