protected function get_module_areas_with_files($extensions = '*') {
        global $DB;

        $params1 = ['contextid' => $this->context->id,
            'emptyfilename' => '.',
            'contextlevel' => CONTEXT_MODULE,
            'course' => $this->course->id];
        $ctxfieldsas = context_helper::get_preload_record_columns_sql('ctx');
        $ctxfields = implode(', ', array_keys(context_helper::get_preload_record_columns('ctx')));
        $sql1 = "SELECT
                    ctx.id AS contextid,
                    f.component,
                    f.filearea,
                    f.itemid,
                    ctx.instanceid AS cmid,
                    {$ctxfieldsas}
            FROM {files} f
            INNER JOIN {context} ctx ON ctx.id = f.contextid
            INNER JOIN {course_modules} cm ON cm.id = ctx.instanceid
            WHERE f.filename <> :emptyfilename
              AND cm.course = :course
              AND ctx.contextlevel = :contextlevel";
        $sql3 = "
            GROUP BY ctx.id, f.component, f.filearea, f.itemid, {$ctxfields}
            ORDER BY ctx.id, f.component, f.filearea, f.itemid";
        list($sql2, $params2) = $this->build_search_files_sql($extensions);
        $areas = [];
        if ($rs = $DB->get_recordset_sql($sql1. $sql2 . $sql3, array_merge($params1, $params2))) {
            foreach ($rs as $record) {
                context_helper::preload_from_record($record);
                $areas[] = $record;
            }
            $rs->close();
        }

        // Sort areas so 'backup' and 'intro' are in the beginning of the list, they are the easiest to check access to.
        usort($areas, function($a, $b) {
            $aeasy = ($a->filearea === 'intro' && substr($a->component, 0, 4) === 'mod_') ||
                ($a->filearea === 'activity' && $a->component === 'backup');
            $beasy = ($b->filearea === 'intro' && substr($b->component, 0, 4) === 'mod_') ||
                ($b->filearea === 'activity' && $b->component === 'backup');
            return $aeasy == $beasy ? 0 : ($aeasy ? -1 : 1);
        });
        return $areas;
    }