Title: Code examples
Course: Accessibility toolkit test

PHP:

<?php
namespace core_ai\external;

use core_ai\manager;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;

/**
 * External API to set a users AI policy acceptance.
 *
 * @package    core_ai
 * @copyright  2024 Matt Porritt <matt.porritt@moodle.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class set_policy_status extends external_api {
    /**
     * Set policy parameters.
     *
     * @since  Moodle 4.5
     * @return external_function_parameters
     */
    public static function execute_parameters(): external_function_parameters {
        return new external_function_parameters([
            'contextid' => new external_value(
                PARAM_INT,
                'The context ID',
                VALUE_REQUIRED,
            ),
        ]);
    }

    /**
     * Set a users AI policy acceptance.
     *
     * @since  Moodle 4.5
     * @param int $contextid The context ID.
     * @return array The generated content.
     */
    public static function execute(
        int $contextid,
    ): array {
        global $USER;

        // Parameter validation.
        [
            'contextid' => $contextid,
        ] = self::validate_parameters(self::execute_parameters(), [
            'contextid' => $contextid,
        ]);

        $usercontext = \core\context\user::instance($USER->id);
        require_capability('moodle/ai:acceptpolicy', $usercontext);

        return [
            'success' => manager::user_policy_accepted($USER->id, $contextid),
        ];
    }

    /**
     * Generate content return value.
     *
     * @since  Moodle 4.5
     * @return external_function_parameters
     */
    public static function execute_returns(): external_function_parameters {
        return new external_function_parameters([
            'success' => new external_value(
                PARAM_BOOL,
                'Was the request successful',
                VALUE_REQUIRED,
            ),
        ]);
    }
}


JS:

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

import {getPolicyStatus, setPolicyStatus} from "./repository";

/**
 * The Javascript module to handle the policy acceptance.
 *
 * @module     core_ai/policy
 * @copyright  2024 Andrew Lyons <andrew@nicols.co.uk>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
export default class {
    static #policyAcceptedFor = {};

    static preconfigurePolicyState(userid, state) {
        if (!this.#policyAcceptedFor.hasOwnProperty(userid)) {
            this.#policyAcceptedFor[userid] = state;
        }
    }

    /**
     * Get the policy status for a user.
     *
     * @param {Number} userid The user ID.
     * @return {Promise<Object>} The policy status.
     */
    static async getPolicyStatus(userid) {
        if (this.#policyAcceptedFor[userid]) {
            return this.#policyAcceptedFor[userid];
        }

        const accepted = await getPolicyStatus(userid);

        this.#policyAcceptedFor[userid] = accepted.status;

        return accepted.status;
    }

    static acceptPolicy() {
        this.#policyAcceptedFor[M.cfg.userId] = true;

        return setPolicyStatus(M.cfg.contextid);
    }
}


CSS:

.jsenabled .tox-shadowhost.tox-fullscreen,
.jsenabled .tox.tox-tinymce.tox-fullscreen {
    z-index: 1050;
}

/**
 * These styles are required to ensure that icons loaded from Moodle are displayed correctly in TinyMCE.
 * The first selector targets the menu.
 * The second selector targets the context menu.
 */
.tox .tox-tbtn svg[data-buttonsource="moodle"] image,
.tox-collection__item-icon svg[data-buttonsource="moodle"] image {
    width: inherit;
    height: inherit;
}

.tox.tox-tinymce .tox-toolbar__group {
    padding-right: 0;
}

/* Prevent navbar obscuring modal content (ignores fullscreen). */
.tox.tox-tinymce:not(.tox-fullscreen) + .tox .tox-dialog-wrap {
    padding-top: var(--navbar-height);
}

/* Modify Tiny's max-height calculation here to factor in navbar height on small viewports (ignores fullscreen). */
@media only screen and (max-width: 767px) {
    body:not(.tox-force-desktop) .tox.tox-tinymce:not(.tox-fullscreen) + .tox .tox-dialog-wrap .tox-dialog {
        max-height: calc((100vh - 8px * 2) - var(--navbar-height)) !important; /* stylelint-disable-line declaration-no-important */
    }
}