Skip to content

Commit

Permalink
Remove Student Assignment Submission files on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisjacquet committed May 3, 2022
1 parent 10135c0 commit eb878a3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -73,6 +73,7 @@ Changes in 9.0
- Accessibility: add select label in Eligibility/TeacherCompletion.php, Student.php, StudentList.php, MassDrops.php & MassSchedule.php
- Two Lists on same page: export only first, no search in Eligibility/Student.php
- Remove photos on delete in Student.php & User.php, thank to @jo125ker
- Remove Student Assignment Submission files on delete in Assignments.php, thank to @khanhchauminh

Changes in 8.9.5
----------------
Expand Down
25 changes: 25 additions & 0 deletions modules/Grades/Assignments.php
@@ -1,6 +1,7 @@
<?php

require_once 'ProgramFunctions/MarkDownHTML.fnc.php';
require_once 'ProgramFunctions/FileUpload.fnc.php';
require_once 'modules/Grades/includes/StudentAssignments.fnc.php';

if ( ! empty( $_SESSION['is_secondary_teacher'] ) )
Expand Down Expand Up @@ -318,6 +319,12 @@
FROM GRADEBOOK_ASSIGNMENTS
WHERE ASSIGNMENT_ID='" . (int) $_REQUEST['assignment_id'] . "'" );

$assignment_course_title = DBGetOne( "SELECT c.TITLE
FROM GRADEBOOK_ASSIGNMENTS ga,COURSES c,GRADEBOOK_ASSIGNMENT_TYPES gat
WHERE c.COURSE_ID=gat.COURSE_ID
AND ga.ASSIGNMENT_ID='" . (int) $_REQUEST['assignment_id'] . "'
AND gat.ASSIGNMENT_TYPE_ID=ga.ASSIGNMENT_TYPE_ID" );

$sql = "DELETE
FROM GRADEBOOK_ASSIGNMENTS
WHERE ASSIGNMENT_ID='" . (int) $_REQUEST['assignment_id'] . "'";
Expand Down Expand Up @@ -385,6 +392,24 @@
unlink( $assignment_file );
}

// Delete Student Assignment Submissions.
DBQuery( "DELETE FROM STUDENT_ASSIGNMENTS
WHERE ASSIGNMENT_ID='" . (int) $_REQUEST['assignment_id'] . "'" );

// Filename match = [course_title]_[assignment_ID]_*.
$student_assignments_file_name = no_accents( $assignment_course_title . '_' . $_REQUEST['assignment_id'] . '_' ) . '*';

// Files uploaded to AssignmentsFiles/[School_Year]/Teacher[teacher_ID]/Quarter[1,2,3,4...]/.
$student_assignments_path = GetAssignmentsFilesPath( User( 'STAFF_ID' ) );

$student_assignments_files = glob( $student_assignments_path . $student_assignments_file_name );

foreach ( $student_assignments_files as $student_assignments_file )
{
// Remove Student Assignment Submission files.
unlink( $student_assignments_file );
}

// Hook.
do_action( 'Grades/Assignments.php|delete_assignment' );

Expand Down

0 comments on commit eb878a3

Please sign in to comment.