private static function analytics_prediction_actions_context_sql($contextid, $modelids, $usersql = false) {
        global $DB;

        list($insql, $params) = $DB->get_in_or_equal($modelids, SQL_PARAMS_NAMED);
        $sql = " FROM {analytics_predictions} ap
                  JOIN {analytics_prediction_actions} apa ON apa.predictionid = ap.id
                 WHERE ap.contextid = :contextid
                   AND ap.modelid {$insql}";
        $params['contextid'] = $contextid;

        if ($usersql) {
            $sql .= " AND apa.userid {$usersql}";
        }

        return [$sql, $params];
    }