Export this data so it can be used as the context for a mustache template.

@param renderer_base $output typically, the renderer that's calling this function
@return stdClass data context for a mustache template
162408
public function export_for_template(\renderer_base $output) {
        return array(
            'message'       => clean_text($this->message),
            'extraclasses'  => implode(' ', $this->extraclasses),
            'announce'      => $this->announce,
            'closebutton'   => $this->closebutton,
            'issuccess'         => $this->messagetype === 'success',
            'isinfo'            => $this->messagetype === 'info',
            'iswarning'         => $this->messagetype === 'warning',
            'iserror'           => $this->messagetype === 'error',
        );
    }
580396
public function export_for_template(renderer_base $output) {
        $r = new stdClass();
        $r->completedcount = $this->feedbackstructure->count_completed_responses($this->mygroupid);
        $r->itemscount = count($this->feedbackstructure->get_items(true));
        if ($this->extradetails && ($timeopen = $this->feedbackstructure->get_feedback()->timeopen)) {
            $r->timeopen = userdate($timeopen);
        }
        if ($this->extradetails && ($timeclose = $this->feedbackstructure->get_feedback()->timeclose)) {
            $r->timeclose = userdate($timeclose);
        }

        return $r;
    }
358018
public function export_for_template(\renderer_base $output) {
        global $PAGE;

        $target = $this->model->get_target();

        $data = new \stdClass();
        $data->insightname = format_string($target->get_name());

        $data->showpredictionheading = true;
        if (!$target->is_linear()) {
            $nclasses = count($target::get_classes());
            $nignoredclasses = count($target->ignored_predicted_classes());
            if ($nclasses - $nignoredclasses <= 1) {
                // Hide the prediction heading if there is only 1 class displayed. Otherwise it is redundant with the insight name.
                $data->showpredictionheading = false;
            }
        }

        $total = 0;

        if ($this->model->uses_insights()) {
            $predictionsdata = $this->model->get_predictions($this->context, true, $this->page, $this->perpage);

            if (!$this->model->is_static()) {
                $notification = new \core\output\notification(get_string('justpredictions', 'report_insights'));
                $data->nostaticmodelnotification = $notification->export_for_template($output);
            }

            $data->predictions = array();
            $predictionvalues = array();
            $insights = array();
            if ($predictionsdata) {
                list($total, $predictions) = $predictionsdata;

                foreach ($predictions as $prediction) {
                    $predictedvalue = $prediction->get_prediction_data()->prediction;

                    // Only need to fill this data once.
                    if (!isset($predictionvalues[$predictedvalue])) {
                        $preddata = array();
                        $preddata['predictiondisplayvalue'] = $target->get_display_value($predictedvalue);
                        list($preddata['style'], $preddata['outcomeicon']) =
                            insight::get_calculation_display($target, floatval($predictedvalue), $output);
                        $predictionvalues[$predictedvalue] = $preddata;
                    }

                    $insightrenderable = new \report_insights\output\insight($prediction, $this->model, true);
                    $insights[$predictedvalue][] = $insightrenderable->export_for_template($output);
                }

                // Order predicted values.
                if ($target->is_linear()) {
                    // During regression what we will be interested on most of the time is in low values so let's show them first.
                    ksort($predictionvalues);
                } else {
                    // During classification targets flag "not that important" samples as 0 so let's show them at the end.
                    krsort($predictionvalues);
                }

                // Ok, now we have all the data we want, put it into a format that mustache can handle.
                foreach ($predictionvalues as $key => $prediction) {
                    if (isset($insights[$key])) {
                        $prediction['insights'] = $insights[$key];
                    }

                    $data->predictions[] = $prediction;
                }
            }

            if (empty($insights) && $this->page == 0) {
                if ($this->model->any_prediction_obtained()) {
                    $data->noinsights = get_string('noinsights', 'analytics');
                } else {
                    $data->noinsights = get_string('nopredictionsyet', 'analytics');
                }
            }
        } else {
            $data->noinsights = get_string('noinsights', 'analytics');
        }

        if (!empty($data->noinsights)) {
            $notification = new \core\output\notification($data->noinsights);
            $data->noinsights = $notification->export_for_template($output);
        }

        if ($this->othermodels) {

            $options = array();
            foreach ($this->othermodels as $model) {
                $options[$model->get_id()] = $model->get_target()->get_name();
            }

            // New moodle_url instance returned by magic_get_url.
            $url = $PAGE->url;
            $url->remove_params('modelid');
            $modelselector = new \single_select($url, 'modelid', $options, '',
                array('' => get_string('selectotherinsights', 'report_insights')));
            $data->modelselector = $modelselector->export_for_template($output);
        }

        $data->pagingbar = $output->render(new \paging_bar($total, $this->page, $this->perpage, $PAGE->url));

        return $data;
    }
311048
public function export_for_template(\renderer_base $output) {
        if ($this->value) {
            $this->edithint = get_string('disable');
            $this->displayvalue = $output->pix_icon('i/hide', get_string('disable'));
        } else {
            $this->edithint = get_string('enable');
            $this->displayvalue = $output->pix_icon('i/show', get_string('enable'));
        }

        return parent::export_for_template($output);
    }
1079190
public function export_for_template(renderer_base $output) {
        $data = new stdClass();

        // Set tab URLs.
        $coursecaturl = new moodle_url('/admin/tool/dataprivacy/defaults.php', ['mode' => CONTEXT_COURSECAT]);
        $courseurl = new moodle_url('/admin/tool/dataprivacy/defaults.php', ['mode' => CONTEXT_COURSE]);
        $moduleurl = new moodle_url('/admin/tool/dataprivacy/defaults.php', ['mode' => CONTEXT_MODULE]);
        $blockurl = new moodle_url('/admin/tool/dataprivacy/defaults.php', ['mode' => CONTEXT_BLOCK]);
        $data->coursecaturl = $coursecaturl;
        $data->courseurl = $courseurl;
        $data->moduleurl = $moduleurl;
        $data->blockurl = $blockurl;

        // Set display mode.
        switch ($this->mode) {
            case CONTEXT_COURSECAT:
                $data->modecoursecat = true;
                break;
            case CONTEXT_COURSE:
                $data->modecourse = true;
                break;
            case CONTEXT_MODULE:
                $data->modemodule = true;
                break;
            case CONTEXT_BLOCK:
                $data->modeblock = true;
                break;
            default:
                $data->modecoursecat = true;
                break;
        }

        // Set config variables.
        $configname = \context_helper::get_class_for_level($this->mode);
        list($purposevar, $categoryvar) = data_registry::var_names_from_context($configname);
        $data->categoryvar = $categoryvar;
        $data->purposevar = $purposevar;

        // Set default category.
        $data->categoryid = $this->category;
        $data->category = category_exporter::get_name($this->category);

        // Set default purpose.
        $data->purposeid = $this->purpose;
        $data->purpose = purpose_exporter::get_name($this->purpose);

        // Set other defaults.
        $otherdefaults = [];
        $url = new moodle_url('#');
        foreach ($this->otherdefaults as $pluginname => $values) {
            $defaults = [
                'name' => $values->name,
                'category' => category_exporter::get_name($values->category),
                'purpose' => purpose_exporter::get_name($values->purpose),
            ];
            if ($this->canedit) {
                $actions = [];
                // Edit link.
                $editattrs = [
                    'data-action' => 'edit-activity-defaults',
                    'data-contextlevel' => $this->mode,
                    'data-activityname' => $pluginname,
                    'data-category' => $values->category,
                    'data-purpose' => $values->purpose,
                ];
                $editlink = new action_menu_link_primary($url, new \pix_icon('t/edit', get_string('edit')),
                    get_string('edit'), $editattrs);
                $actions[] = $editlink->export_for_template($output);

                // Delete link.
                $deleteattrs = [
                    'data-action' => 'delete-activity-defaults',
                    'data-contextlevel' => $this->mode,
                    'data-activityname' => $pluginname,
                    'data-activitydisplayname' => $values->name,
                ];
                $deletelink = new action_menu_link_primary($url, new \pix_icon('t/delete', get_string('delete')),
                    get_string('delete'), $deleteattrs);
                $actions[] = $deletelink->export_for_template($output);

                $defaults['actions'] = $actions;
            }
            $otherdefaults[] = (object)$defaults;
        }
        $data->otherdefaults = $otherdefaults;

        $data->canedit = $this->canedit;
        $data->contextlevel = $this->mode;

        return $data;
    }
1359854
public function export_for_template(\renderer_base $output) {
        global $PAGE;
        $step = $this->step;

        $result = (object) [
            'stepid'    => $step->get_id(),
            'title'     => external_format_text(
                    stepsource::get_string_from_input($step->get_title()),
                    FORMAT_HTML,
                    $PAGE->context->id,
                    'tool_usertours'
                )[0],
            'content'   => external_format_text(
                    stepsource::get_string_from_input($step->get_content()),
                    FORMAT_HTML,
                    $PAGE->context->id,
                    'tool_usertours'
                )[0],
            'element'   => $step->get_target()->convert_to_css(),
        ];

        $result->content = str_replace("\n", "<br>\n", $result->content);

        foreach ($step->get_config_keys() as $key) {
            $result->$key = $step->get_config($key);
        }

        return $result;
    }
777
public function export_for_template(renderer_base $output) {
        global $USER, $OUTPUT;

        $data = new \stdClass();

        if (!isset($this->config->display_picture) || $this->config->display_picture == 1) {
            $data->userpicture = $OUTPUT->user_picture($USER, array('class' => 'userpicture'));
        }

        $data->userfullname = fullname($USER);

        if (!isset($this->config->display_country) || $this->config->display_country == 1) {
            $countries = get_string_manager()->get_list_of_countries(true);
            if (isset($countries[$USER->country])) {
                $data->usercountry = $countries[$USER->country];
            }
        }

        if (!isset($this->config->display_city) || $this->config->display_city == 1) {
            $data->usercity = $USER->city;
        }

        if (!isset($this->config->display_email) || $this->config->display_email == 1) {
            $data->useremail = obfuscate_mailto($USER->email, '');
        }

        if (!empty($this->config->display_icq) && !empty($USER->icq)) {
            $data->usericq = s($USER->icq);
        }

        if (!empty($this->config->display_skype) && !empty($USER->skype)) {
            $data->userskype = s($USER->skype);
        }

        if (!empty($this->config->display_yahoo) && !empty($USER->yahoo)) {
            $data->useryahoo = s($USER->yahoo);
        }

        if (!empty($this->config->display_aim) && !empty($USER->aim)) {
            $data->useraim = s($USER->aim);
        }

        if (!empty($this->config->display_msn) && !empty($USER->msn)) {
            $data->usermsn = s($USER->msn);
        }

        if (!empty($this->config->display_phone1) && !empty($USER->phone1)) {
            $data->userphone1 = s($USER->phone1);
        }

        if (!empty($this->config->display_phone2) && !empty($USER->phone2)) {
            $data->userphone2 = s($USER->phone2);
        }

        if (!empty($this->config->display_institution) && !empty($USER->institution)) {
            $data->userinstitution = format_string($USER->institution);
        }

        if (!empty($this->config->display_address) && !empty($USER->address)) {
            $data->useraddress = format_string($USER->address);
        }

        if (!empty($this->config->display_firstaccess) && !empty($USER->firstaccess)) {
            $data->userfirstaccess = userdate($USER->firstaccess);
        }

        if (!empty($this->config->display_lastaccess) && !empty($USER->lastaccess)) {
            $data->userlastaccess = userdate($USER->lastaccess);
        }

        if (!empty($this->config->display_currentlogin) && !empty($USER->currentlogin)) {
            $data->usercurrentlogin = userdate($USER->currentlogin);
        }

        if (!empty($this->config->display_lastip) && !empty($USER->lastip)) {
            $data->userlastip = $USER->lastip;
        }

        return $data;
    }
665287
public function export_for_template(renderer_base $output) {
        global $USER;

        $nocoursesurl = $output->image_url('courses', 'block_recentlyaccessedcourses')->out(false);

        return [
            'userid' => $USER->id,
            'nocoursesimgurl' => $nocoursesurl,
            'pagingbar' => [
                'next' => true,
                'previous' => true
            ]
        ];
    }
803209
public function export_for_template(renderer_base $output) {
        $data = new stdClass();
        $data->id = $this->id;
        $data->label = $this->label;
        $data->value = $this->value;
        $data->icon = $this->icon->export_for_template($output);

        $options = new stdClass();
        $options->trusted = false;
        $options->noclean = false;
        $options->smiley = false;
        $options->filter = false;
        $options->para = true;
        $options->newlines = false;
        $options->overflowdiv = false;

        $data->description = '';
        if (!empty($this->description)) {
            list($data->description) = external_format_text((string) $this->description, FORMAT_MARKDOWN,
                $this->context->id, null, null, null, $options);
        }

        return $data;
    }
439573
public function export_for_template(renderer_base $output) {
        $url = $this->method === 'get' ? $this->url->out_omit_querystring(true) : $this->url->out_omit_querystring();

        $data = new stdClass();
        $data->id = html_writer::random_id('single_button');
        $data->formid = $this->formid;
        $data->method = $this->method;
        $data->url = $url === '' ? '#' : $url;
        $data->label = $this->label;
        $data->classes = $this->class;
        $data->disabled = $this->disabled;
        $data->tooltip = $this->tooltip;
        $data->primary = $this->primary;

        // Form parameters.
        $params = $this->url->params();
        if ($this->method === 'post') {
            $params['sesskey'] = sesskey();
        }
        $data->params = array_map(function($key) use ($params) {
            return ['name' => $key, 'value' => $params[$key]];
        }, array_keys($params));

        // Button actions.
        $actions = $this->actions;
        $data->actions = array_map(function($action) use ($output) {
            return $action->export_for_template($output);
        }, $actions);
        $data->hasactions = !empty($data->actions);

        return $data;
    }
45065
public function export_for_template(renderer_base $output) {
        $data = new stdClass();

        $url = new moodle_url('/admin/tool/dataprivacy/datadeletion.php');
        $options = [
            CONTEXT_USER => get_string('user'),
            CONTEXT_COURSE => get_string('course'),
            CONTEXT_MODULE => get_string('activitiesandresources', 'tool_dataprivacy'),
            CONTEXT_BLOCK => get_string('blocks'),
        ];
        $filterselector = new single_select($url, 'filter', $options, $this->filter, null);
        $data->filter = $filterselector->export_for_template($output);

        ob_start();
        $this->expiredcontextstable->out(helper::DEFAULT_PAGE_SIZE, true);
        $expiredcontexts = ob_get_contents();
        ob_end_clean();
        $data->expiredcontexts = $expiredcontexts;

        $data->existingcontexts = $this->expiredcontextstable->rawdata ? true : false;

        return $data;
    }
903948
public function export_for_template(renderer_base $output) {
        $data = new stdClass();
        $data->userid = $this->userid;
        $data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
        $data->canreaduserevidence = user_evidence::can_read_user($this->userid);
        $data->canmanageuserplans = plan::can_manage_user($this->userid);

        // Attach standard objects as mustache can not parse \core_competency\plan objects.
        $data->plans = array();
        if ($this->plans) {
            foreach ($this->plans as $plan) {
                $exporter = new plan_exporter($plan, array('template' => $plan->get_template()));
                $record = $exporter->export($output);
                $data->plans[] = $record;
            }
        }

        $data->navigation = array();
        foreach ($this->navigation as $button) {
            $data->navigation[] = $output->render($button);
        }

        return $data;
    }
278996
public function export_for_template(renderer_base $output) {
        $context = parent::export_for_template($output);
        $context['valuechars'] = array_fill(0, strlen($context['value']), 'x');

        return $context;
    }
20575
public function export_for_template(renderer_base $output) {
        $attributes = $this->attributes;

        $data = new stdClass();
        $data->formid = !empty($this->formid) ? $this->formid : html_writer::random_id('url_select_f');
        $data->classes = $this->class;
        $data->label = $this->label;
        $data->disabled = $this->disabled;
        $data->title = $this->tooltip;
        $data->id = !empty($attributes['id']) ? $attributes['id'] : html_writer::random_id('url_select');
        $data->sesskey = sesskey();
        $data->action = (new moodle_url('/course/jumpto.php'))->out(false);

        // Remove attributes passed as property directly.
        unset($attributes['class']);
        unset($attributes['id']);
        unset($attributes['name']);
        unset($attributes['title']);
        unset($attributes['disabled']);

        $data->showbutton = $this->showbutton;

        // Select options.
        $nothing = false;
        if (is_string($this->nothing) && $this->nothing !== '') {
            $nothing = ['' => $this->nothing];
        } else if (is_array($this->nothing)) {
            $nothingvalue = reset($this->nothing);
            if ($nothingvalue === 'choose' || $nothingvalue === 'choosedots') {
                $nothing = [key($this->nothing) => get_string('choosedots')];
            } else {
                $nothing = $this->nothing;
            }
        }
        $data->options = $this->flatten_options($this->urls, $nothing);

        // Label attributes.
        $data->labelattributes = [];
        // Unset label attributes that are already in the template.
        unset($this->labelattributes['for']);
        // Map the label attributes.
        foreach ($this->labelattributes as $key => $value) {
            $data->labelattributes[] = ['name' => $key, 'value' => $value];
        }

        // Help icon.
        $data->helpicon = !empty($this->helpicon) ? $this->helpicon->export_for_template($output) : false;

        // Finally all the remaining attributes.
        $data->attributes = [];
        foreach ($attributes as $key => $value) {
            $data->attributes[] = ['name' => $key, 'value' => $value];
        }

        return $data;
    }
290050
public function export_for_template(renderer_base $output) {
        global $USER;

        $data = new stdClass();
        $data->newdatarequesturl = new moodle_url('/admin/tool/dataprivacy/createdatarequest.php');

        if (!is_https()) {
            $httpwarningmessage = get_string('httpwarning', 'tool_dataprivacy');
            $data->httpsite = array('message' => $httpwarningmessage, 'announce' => 1);
        }

        $requests = [];
        foreach ($this->requests as $request) {
            $requestid = $request->get('id');
            $status = $request->get('status');
            $userid = $request->get('userid');
            $type = $request->get('type');

            $usercontext = context_user::instance($userid, IGNORE_MISSING);
            if (!$usercontext) {
                // Use the context system.
                $outputcontext = \context_system::instance();
            } else {
                $outputcontext = $usercontext;
            }

            $requestexporter = new data_request_exporter($request, ['context' => $outputcontext]);
            $item = $requestexporter->export($output);

            $self = $request->get('userid') == $USER->id;
            if (!$self) {
                // Append user name if it differs from $USER.
                $a = (object)['typename' => $item->typename, 'user' => $item->foruser->fullname];
                $item->typename = get_string('requesttypeuser', 'tool_dataprivacy', $a);
            }

            $candownload = false;
            $cancancel = true;
            switch ($status) {
                case api::DATAREQUEST_STATUS_COMPLETE:
                    $item->statuslabelclass = 'badge-success';
                    $item->statuslabel = get_string('statuscomplete', 'tool_dataprivacy');
                    $cancancel = false;
                    break;
                case api::DATAREQUEST_STATUS_DOWNLOAD_READY:
                    $item->statuslabelclass = 'badge-success';
                    $item->statuslabel = get_string('statusready', 'tool_dataprivacy');
                    $cancancel = false;
                    $candownload = true;

                    if ($usercontext) {
                        $candownload = api::can_download_data_request_for_user(
                                $request->get('userid'), $request->get('requestedby'));
                    }
                    break;
                case api::DATAREQUEST_STATUS_DELETED:
                    $item->statuslabelclass = 'badge-success';
                    $item->statuslabel = get_string('statusdeleted', 'tool_dataprivacy');
                    $cancancel = false;
                    break;
                case api::DATAREQUEST_STATUS_EXPIRED:
                    $item->statuslabelclass = 'badge-secondary';
                    $item->statuslabel = get_string('statusexpired', 'tool_dataprivacy');
                    $item->statuslabeltitle = get_string('downloadexpireduser', 'tool_dataprivacy');
                    $cancancel = false;
                    break;
                case api::DATAREQUEST_STATUS_CANCELLED:
                case api::DATAREQUEST_STATUS_REJECTED:
                    $cancancel = false;
                    break;
            }

            // Prepare actions.
            $actions = [];
            if ($cancancel) {
                $cancelurl = new moodle_url('#');
                $canceldata = ['data-action' => 'cancel', 'data-requestid' => $requestid];
                $canceltext = get_string('cancelrequest', 'tool_dataprivacy');
                $actions[] = new action_menu_link_secondary($cancelurl, null, $canceltext, $canceldata);
            }
            if ($candownload && $usercontext) {
                $actions[] = api::get_download_link($usercontext, $requestid);
            }
            if (!empty($actions)) {
                $actionsmenu = new action_menu($actions);
                $actionsmenu->set_menu_trigger(get_string('actions'));
                $actionsmenu->set_owner_selector('request-actions-' . $requestid);
                $actionsmenu->set_alignment(\action_menu::TL, \action_menu::BL);
                $item->actions = $actionsmenu->export_for_template($output);
            }

            $requests[] = $item;
        }
        $data->requests = $requests;
        return $data;
    }
383819
public function export_for_template(renderer_base $output) {
        global $OUTPUT, $CFG, $SITE, $USER;

        $context = context_module::instance($this->cm->id);
        $chapters = book_preload_chapters($this->book);
        $course = get_course($this->book->course);

        $data = new stdClass();
        // Print dialog link.
        $data->printdialoglink = $output->render_print_book_dialog_link();
        $data->booktitle = $OUTPUT->heading(format_string($this->book->name, true,
                array('context' => $context)), 1);
        $introtext = file_rewrite_pluginfile_urls($this->book->intro, 'pluginfile.php', $context->id, 'mod_book', 'intro', null);
        $data->bookintro = format_text($introtext, $this->book->introformat,
                array('noclean' => true, 'context' => $context));
        $data->sitelink = \html_writer::link(new moodle_url($CFG->wwwroot),
                format_string($SITE->fullname, true, array('context' => $context)));
        $data->coursename = format_string($course->fullname, true, array('context' => $context));
        $data->modulename = format_string($this->book->name, true, array('context' => $context));
        $data->username = fullname($USER, true);
        $data->printdate = userdate(time());
        $data->toc = $output->render_print_book_toc($chapters, $this->book, $this->cm);
        foreach ($chapters as $ch) {
            list($chaptercontent, $chaptervisible) = $output->render_print_book_chapter($ch, $chapters, $this->book,
                    $this->cm);
            $chapter = new stdClass();
            $chapter->content = $chaptercontent;
            $chapter->visible = $chaptervisible;
            $data->chapters[] = $chapter;
        }

        return $data;
    }
952879
public function export_for_template(renderer_base $output) {
        global $USER;

        $data = (object) [
            'pluginbaseurl' => (new moodle_url('/admin/tool/policy'))->out(false),
            'returnurl' => $this->returnurl ? (new moodle_url($this->returnurl))->out(false) : null,
            'numpolicy' => $this->numpolicy ? : null,
            'totalpolicies' => $this->totalpolicies ? : null,
        ];
        if ($this->manage && $this->policy->status != policy_version::STATUS_ARCHIVED) {
            $paramsurl = ['policyid' => $this->policy->policyid, 'versionid' => $this->policy->id];
            $data->editurl = (new moodle_url('/admin/tool/policy/editpolicydoc.php', $paramsurl))->out(false);
        }

        if ($this->policy->agreementstyle == policy_version::AGREEMENTSTYLE_OWNPAGE) {
            if (!api::is_user_version_accepted($USER->id, $this->policy->id)) {
                unset($data->returnurl);
                $data->accepturl = (new moodle_url('/admin/tool/policy/index.php', [
                    'listdoc[]' => $this->policy->id,
                    'status'.$this->policy->id => 1,
                    'submit' => 'accept',
                    'sesskey' => sesskey(),
                ]))->out(false);
                if ($this->policy->optional == policy_version::AGREEMENT_OPTIONAL) {
                    $data->declineurl = (new moodle_url('/admin/tool/policy/index.php', [
                        'listdoc[]' => $this->policy->id,
                        'status'.$this->policy->id => 0,
                        'submit' => 'decline',
                        'sesskey' => sesskey(),
                    ]))->out(false);
                }
            }
        }

        $data->policy = clone($this->policy);

        return $data;
    }