original_string: public static function delete_completion(\stdClass $user = null, int $courseid = null, int $cmid = null) {
          global $DB;
  
          if (isset($cmid)) {
              $params = (isset($user)) ? ['userid' => $user->id, 'coursemoduleid' => $cmid] : ['coursemoduleid' => $cmid];
              // Only delete the record for course modules completion.
              $DB->delete_records('course_modules_completion', $params);
              return;
          }
  
          if (isset($courseid)) {
  
              $usersql = isset($user) ? 'AND cmc.userid = :userid' : '';
              $params = isset($user) ? ['course' => $courseid, 'userid' => $user->id] : ['course' => $courseid];
  
              // Find records relating to course modules.
              $sql = "SELECT cmc.id
                        FROM {course_completion_criteria} ccc
                        JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid
                       WHERE ccc.course = :course $usersql";
              $recordids = $DB->get_records_sql($sql, $params);
              $ids = array_keys($recordids);
              if (!empty($ids)) {
                  list($deletesql, $deleteparams) = $DB->get_in_or_equal($ids);
                  $deletesql = 'id ' . $deletesql;
                  $DB->delete_records_select('course_modules_completion', $deletesql, $deleteparams);
              }
              $DB->delete_records('course_completion_crit_compl', $params);
              $DB->delete_records('course_completions', $params);
          }
      }
code: public static function delete_completion(\stdClass $user = null, int $courseid = null, int $cmid = null) {
          global $DB;
  
          if (isset($cmid)) {
              $params = (isset($user)) ? ['userid' => $user->id, 'coursemoduleid' => $cmid] : ['coursemoduleid' => $cmid];
              // Only delete the record for course modules completion.
              $DB->delete_records('course_modules_completion', $params);
              return;
          }
  
          if (isset($courseid)) {
  
              $usersql = isset($user) ? 'AND cmc.userid = :userid' : '';
              $params = isset($user) ? ['course' => $courseid, 'userid' => $user->id] : ['course' => $courseid];
  
              // Find records relating to course modules.
              $sql = "SELECT cmc.id
                        FROM {course_completion_criteria} ccc
                        JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid
                       WHERE ccc.course = :course $usersql";
              $recordids = $DB->get_records_sql($sql, $params);
              $ids = array_keys($recordids);
              if (!empty($ids)) {
                  list($deletesql, $deleteparams) = $DB->get_in_or_equal($ids);
                  $deletesql = 'id ' . $deletesql;
                  $DB->delete_records_select('course_modules_completion', $deletesql, $deleteparams);
              }
              $DB->delete_records('course_completion_crit_compl', $params);
              $DB->delete_records('course_completions', $params);
          }
      }
code_tokens: public static function delete_completion ( \ stdClass $ user = null , int $ courseid = null , int $ cmid = null ) { global $ DB ; if ( isset ( $ cmid ) ) { $ params = ( isset ( $ user ) ) ? [ 'userid' => $ user -> id , 'coursemoduleid' => $ cmid ] : [ 'coursemoduleid' => $ cmid ] ; // Only delete the record for course modules completion. $ DB -> delete_records ( 'course_modules_completion' , $ params ) ; return ; } if ( isset ( $ courseid ) ) { $ usersql = isset ( $ user ) ? 'AND cmc.userid = :userid' : '' ; $ params = isset ( $ user ) ? [ 'course' => $ courseid , 'userid' => $ user -> id ] : [ 'course' => $ courseid ] ; // Find records relating to course modules. $ sql = "SELECT cmc.id
                        FROM {course_completion_criteria} ccc
                        JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid
                       WHERE ccc.course = :course $usersql" ; $ recordids = $ DB -> get_records_sql ( $ sql , $ params ) ; $ ids = array_keys ( $ recordids ) ; if ( ! empty ( $ ids ) ) { list ( $ deletesql , $ deleteparams ) = $ DB -> get_in_or_equal ( $ ids ) ; $ deletesql = 'id ' . $ deletesql ; $ DB -> delete_records_select ( 'course_modules_completion' , $ deletesql , $ deleteparams ) ; } $ DB -> delete_records ( 'course_completion_crit_compl' , $ params ) ; $ DB -> delete_records ( 'course_completions' , $ params ) ; } }
docstring: Delete completion information for users.
  
  @param \stdClass $user The user. If provided will delete completion information for just this user. Else all users.
  @param int $courseid The course id. Provide this if you want course completion and activity completion deleted.
  @param int $cmid The course module id. Provide this if you only want activity completion deleted.
docstring_tokens: Delete completion information for users .