Merge branch 'MDL-84862-main-test' of https://github.com/yusufwib01/moodle
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
namespace core_admin\admin;
|
||||
|
||||
use admin_setting;
|
||||
|
||||
/**
|
||||
* Render a notification as part of other admin settings.
|
||||
*
|
||||
* @package core_admin
|
||||
* @subpackage admin
|
||||
* @copyright 2025 Matt Porritt <[email protected]>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class admin_setting_notification extends admin_setting {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name The name of the setting.
|
||||
* @param string $notification The notification to display.
|
||||
* @param string $type The type of notification.
|
||||
* @param bool $cancelable Whether the notification can be canceled.
|
||||
*/
|
||||
public function __construct(
|
||||
string $name,
|
||||
/** @var string The notification to display. */
|
||||
protected string $notification,
|
||||
/** @var string The type of notification. */
|
||||
protected string $type = 'info',
|
||||
/** @var bool Whether the notification can be canceled. */
|
||||
protected bool $cancelable = false
|
||||
) {
|
||||
$this->nosave = true;
|
||||
|
||||
parent::__construct($name, '', '', '');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function get_setting(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function get_defaultsetting(): bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function write_setting($data): string {
|
||||
// Do not write any setting.
|
||||
return '';
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function output_html($data, $query = ''): string {
|
||||
global $OUTPUT;
|
||||
|
||||
return $OUTPUT->notification($this->notification, $this->type, $this->cancelable);
|
||||
}
|
||||
}
|
||||
@@ -32,19 +32,29 @@ if ($hassiteconfig) {
|
||||
$providers->add(new admin_setting_heading('availableproviders',
|
||||
get_string('availableproviders', 'core_ai'),
|
||||
get_string('availableproviders_desc', 'core_ai')));
|
||||
// Add call to action to add a new provider.
|
||||
$providers->add(new \core_admin\admin\admin_setting_template_render(
|
||||
name: 'addnewprovider',
|
||||
templatename: 'core_ai/admin_add_provider',
|
||||
context: ['addnewproviderurl' => new moodle_url('/ai/configure.php')]
|
||||
));
|
||||
|
||||
$providers->add(new \core_ai\admin\admin_setting_provider_manager(
|
||||
if (!empty(core_plugin_manager::instance()->get_plugins_of_type("aiprovider"))) {
|
||||
// Add call to action to add a new provider.
|
||||
$providers->add(new \core_admin\admin\admin_setting_template_render(
|
||||
name: 'addnewprovider',
|
||||
templatename: 'core_ai/admin_add_provider',
|
||||
context: ['addnewproviderurl' => new moodle_url('/ai/configure.php')]
|
||||
));
|
||||
|
||||
$providers->add(new \core_ai\admin\admin_setting_provider_manager(
|
||||
'aiprovider',
|
||||
\core_ai\table\aiprovider_management_table::class,
|
||||
'manageaiproviders',
|
||||
new lang_string('manageaiproviders', 'core_ai'),
|
||||
));
|
||||
));
|
||||
} else {
|
||||
$providers->add(new \core_admin\admin\admin_setting_notification(
|
||||
name:'noproviderplugins',
|
||||
notification: get_string('noproviderplugins', 'core_ai'),
|
||||
type: 'danger'
|
||||
));
|
||||
}
|
||||
|
||||
$ADMIN->add('ai', $providers);
|
||||
|
||||
// Add settings page for AI placement settings.
|
||||
|
||||
@@ -72,6 +72,12 @@ $PAGE->set_pagelayout('admin');
|
||||
$PAGE->set_title($title);
|
||||
$PAGE->set_heading($title);
|
||||
|
||||
// Explode if there are no provider plugins installed.
|
||||
$plugins = core_plugin_manager::instance()->get_plugins_of_type('aiprovider');
|
||||
if (empty($plugins)) {
|
||||
throw new moodle_exception('noproviderplugins', 'core_ai');
|
||||
}
|
||||
|
||||
// Provider instance form processing.
|
||||
$mform = new \core_ai\form\ai_provider_form(customdata: $data);
|
||||
if ($mform->is_cancelled()) {
|
||||
|
||||
@@ -123,6 +123,7 @@ $string['globalratelimit'] = 'Maximum number of site-wide requests';
|
||||
$string['globalratelimit_help'] = 'The number of site-wide requests allowed per hour.';
|
||||
$string['manageaiplacements'] = 'Manage AI placements';
|
||||
$string['manageaiproviders'] = 'Manage AI providers';
|
||||
$string['noproviderplugins'] = 'There are no provider plugins installed. Install a provider plugin to enable provider instance creation.';
|
||||
$string['noproviders'] = 'This action is unavailable. No <a href="{$a}">AI providers</a> are configured for this action.';
|
||||
$string['off'] = 'Off';
|
||||
$string['on'] = 'On';
|
||||
|
||||
Reference in New Issue
Block a user