public function generate($samplecontexts, $predictions) {
        global $OUTPUT;

        $analyserclass = $this->target->get_analyser_class();

        // We will need to restore it later.
        $actuallanguage = current_language();

        if ($analyserclass::one_sample_per_analysable()) {

            // Iterate through the predictions and the users in each prediction (likely to be just one).
            foreach ($predictions as $prediction) {

                $context = $samplecontexts[$prediction->get_prediction_data()->contextid];

                $users = $this->target->get_insights_users($context);
                foreach ($users as $user) {

                    $this->set_notification_language($user);
                    list($insighturl, $fullmessage, $fullmessagehtml) = $this->prediction_info($prediction);
                    $this->notification($context, $user, $insighturl, $fullmessage, $fullmessagehtml);
                }
            }

        } else {

            // Iterate through the context and the users in each context.
            foreach ($samplecontexts as $context) {

                $users = $this->target->get_insights_users($context);
                foreach ($users as $user) {

                    $this->set_notification_language($user);

                    $insighturl = $this->target->get_insight_context_url($this->modelid, $context);

                    $fullmessage = get_string('insightinfomessage', 'analytics', $insighturl->out(false));
                    $fullmessagehtml = $OUTPUT->render_from_template('core_analytics/insight_info_message',
                        ['url' => $insighturl->out(false)]
                    );

                    $this->notification($context, $user, $insighturl, $fullmessage, $fullmessagehtml);
                }
            }
        }

        force_current_language($actuallanguage);
    }