public static function get_course_completion_join_sql(int $userid, string $prefix, string $joinfield) : array {
        $cccalias = "{$prefix}_ccc"; // Course completion criteria.
        $cmcalias = "{$prefix}_cmc"; // Course modules completion.
        $ccccalias = "{$prefix}_cccc"; // Course completion criteria completion.

        $join = "JOIN {course_completion_criteria} {$cccalias} ON {$joinfield} = {$cccalias}.course
             LEFT JOIN {course_modules_completion} {$cmcalias} ON {$cccalias}.moduleinstance = {$cmcalias}.coursemoduleid
                        AND {$cmcalias}.userid = :{$prefix}_moduleuserid
             LEFT JOIN {course_completion_crit_compl} {$ccccalias} ON {$ccccalias}.criteriaid = {$cccalias}.id
                        AND {$ccccalias}.userid = :{$prefix}_courseuserid";
        $where = "{$cmcalias}.id IS NOT NULL OR {$ccccalias}.id IS NOT NULL";
        $params = ["{$prefix}_moduleuserid" => $userid, "{$prefix}_courseuserid" => $userid];

        return [$join, $where, $params];
    }