91334a46b5
Co-authored-by: Cursor <cursoragent@cursor.com>
86 lines
2.9 KiB
PHP
86 lines
2.9 KiB
PHP
<?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/>.
|
||
|
||
/**
|
||
* Admin setting: site-wide role × feature access matrix.
|
||
*
|
||
* @package mod_meetletacbfree
|
||
* @copyright 2026 MeetLet <info@meetlet.net>
|
||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||
*/
|
||
|
||
namespace mod_meetletacbfree\admin;
|
||
|
||
use admin_setting;
|
||
use mod_meetletacbfree\local\featureaccess;
|
||
|
||
defined('MOODLE_INTERNAL') || die();
|
||
|
||
/**
|
||
* Stores the site default feature-access JSON used when an activity does not override.
|
||
*/
|
||
class setting_featureaccess extends admin_setting {
|
||
public function __construct() {
|
||
parent::__construct(
|
||
'meetletacbfree/featureaccess',
|
||
get_string('featureaccess', 'meetletacbfree'),
|
||
get_string('featureaccess_desc', 'meetletacbfree'),
|
||
json_encode(featureaccess::builtin_defaults(), JSON_UNESCAPED_UNICODE)
|
||
);
|
||
}
|
||
|
||
public function get_setting() {
|
||
return $this->config_read($this->name);
|
||
}
|
||
|
||
public function write_setting($data) {
|
||
if (!is_array($data)) {
|
||
$data = [];
|
||
}
|
||
$json = featureaccess::matrix_from_post($data);
|
||
return $this->config_write($this->name, $json) ? '' : get_string('errorsetting', 'admin');
|
||
}
|
||
|
||
public function output_html($data, $query = '') {
|
||
$matrix = featureaccess::builtin_defaults();
|
||
if (is_string($data) && $data !== '') {
|
||
$decoded = json_decode($data, true);
|
||
if (is_array($decoded) && !empty($decoded)) {
|
||
$matrix = featureaccess::normalize($decoded);
|
||
}
|
||
} else if (is_array($data) && !empty($data)) {
|
||
$json = featureaccess::matrix_from_post($data);
|
||
$decoded = json_decode($json, true);
|
||
if (is_array($decoded)) {
|
||
$matrix = featureaccess::normalize($decoded);
|
||
}
|
||
}
|
||
|
||
$html = access_reset_ui::toolbar('featureaccess');
|
||
$html .= featureaccess::render_matrix_html($matrix, $this->get_full_name());
|
||
return format_admin_setting(
|
||
$this,
|
||
$this->visiblename,
|
||
$html,
|
||
$this->description,
|
||
true,
|
||
'',
|
||
get_string('featureaccess_usesite', 'meetletacbfree'),
|
||
$query
|
||
);
|
||
}
|
||
}
|