Unenrol student (with PHP)

Re: Unenrol student (with PHP)

by Rachel Martin -
Number of replies: 0

We have an old plugin which does an OK job for our needs, but it is not perfect as I have noticed some gaps here and there.  Most of our courses are on-demand and don't use the forums/assignments and such.  Below is the array of tables we clear.

$todelete = array (

array( 'table' => 'post', 'where' => "userid = $userid AND courseid = $courseid" ),

array( 'table' => 'course_completions', 'where' => "userid = $userid AND course = $courseid" ),

array( 'table' => 'course_completion_crit_compl', 'where' => "userid = $userid AND course = $courseid" ),

array( 'table' => 'event','where' => "userid = $userid AND courseid = $courseid" ),

array( 'table' => 'scorm_scoes_track','where' => "userid = $userid AND scormidIN (SELECT id FROM {scorm}WHERE course = $courseid)" ),

array( 'table' => 'groups_members', 'where' => "userid = $userid AND groupidIN (SELECT id FROM {groups} WHERE courseid = $courseid)" ),

array( 'table' => 'lesson_attempts','where' => "userid = $userid AND lessonid IN (SELECT id FROM {lesson} WHERE course = $courseid)" ),

array( 'table' => 'lesson_branch','where' => "userid = $userid AND lessonid IN (SELECT id FROM {lesson} WHERE course = $courseid)" ),

array( 'table' => 'lesson_grades','where' => "userid = $userid AND lessonid IN (SELECT id FROM {lesson} WHERE course = $courseid)" ),

array( 'table' => 'lesson_overrides', 'where' => "userid = $userid AND lessonid IN (SELECT id FROM {lesson} WHERE course = $courseid)" ),

array( 'table' => 'lesson_timer', 'where' => "userid = $userid AND lessonid IN (SELECT id FROM {lesson} WHERE course = $courseid)" ),

array( 'table' => 'lti_submission', 'where' => "userid = $userid AND ltiidIN (SELECT id FROM {lti}WHERE course = $courseid)" ),

array( 'table' => 'grade_grades', 'where' => "userid = $userid AND itemid IN (SELECT id FROM {grade_items}WHERE courseid = $courseid)" ),

array( 'table' => 'assign_grades','where' => "userid = $userid AND assignment IN (SELECT id FROM {assign} WHERE course = $courseid)" ),

array( 'table' => 'assignment_submissions','where' => "userid = $userid AND assignment IN (SELECT id FROM {assignment} WHERE course = $courseid)" ),

array( 'table' => 'quiz_attempts','where' => "userid = $userid AND quiz IN (SELECT id FROM {quiz} WHERE course = $courseid)" ),

array( 'table' => 'quiz_grades','where' => "userid = $userid AND quiz IN (SELECT id FROM {quiz} WHERE course = $courseid)" ),

array( 'table' => 'course_modules_completion','where' => "userid = $userid AND coursemoduleid IN (SELECT id FROM {course_modules} WHERE course = $courseid)" ),

array( 'table' => 'certificate_issues', 'where' => "userid = $userid AND certificateidIN (SELECT id FROM {certificate}WHERE course = $courseid)" ),

array( 'table' => 'user_enrolments','where' => "userid = $userid AND enrolidIN (SELECT id FROM {enrol}WHERE courseid = $courseid)" ),

array( 'table' => 'feedback_value', 'where' => "completed IN (SELECT {feedback_completed}.id FROM {feedback_completed}, {feedback}

WHERE feedback={feedback}.id AND userid = $userid AND course = $courseid)" ),

array( 'table' => 'feedback_completedtmp', 'where' => "userid = $userid AND feedbackIN (SELECT id FROM {feedback} WHERE course = $courseid)" ),

array( 'table' => 'feedback_completed', 'where' => "userid = $userid AND feedbackIN (SELECT id FROM {feedback} WHERE course = $courseid)" ),

array( 'table' => 'repository_instances', 'where' => "userid = $userid

AND contextid IN (SELECT id FROM {context}WHERE instanceid = $courseid AND contextlevel = ".CONTEXT_COURSE.')' ),

array( 'table' => 'role_assignments', 'where' => "userid = $userid

AND contextid IN (SELECT id FROM {context}WHERE instanceid = $courseid AND contextlevel = ".CONTEXT_COURSE.')' )

);