Skip to content

Commit

Permalink
codechecker fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssj365 committed Nov 8, 2024
1 parent 354f0f8 commit f991d15
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 42 deletions.
4 changes: 2 additions & 2 deletions classes/bigbluebuttonbn/action_url_addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace bbbext_bnlocksettings\bigbluebuttonbn;

use bbbext_bnlocksettings\utils;
use bbbext_bnlocksettings\lock;

/**
* A single action class to mutate the action URL.
Expand All @@ -40,7 +40,7 @@ class action_url_addons extends \mod_bigbluebuttonbn\local\extension\action_url_
*/
public function execute(string $action = '', array $data = [], array $metadata = [], ?int $instanceid = null): array {
if ($instanceid && $action == 'create') {
$locksettings = utils::get_lock_settings($instanceid);
$locksettings = lock::get_lock_settings($instanceid);
if ($locksettings) {
foreach ($locksettings as $locksetting => $lockvalue) {
$data[$locksetting] = $lockvalue;
Expand Down
62 changes: 41 additions & 21 deletions classes/bigbluebuttonbn/mod_form_addons.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function remove_lock_settings() {
'disablepublicchat',
'disablenote',
'hideuserlist',
'no_locksettings'
'no_locksettings',
];
foreach ($lockelements as $lockelement) {
if ($this->mform->elementExists($lockelement)) {
Expand All @@ -123,30 +123,50 @@ private function remove_lock_settings() {
}

/**
* Add new form field definition
* Add new form field definition.
*
* @return void
*/
public function add_fields(): void {
$this->mform->addElement('header', 'bnlocksettings', get_string('mod_form_lockoverride_header', 'bbbext_bnlocksettings'));
$this->mform->addElement('checkbox', 'enablecam', get_string('mod_form_overridecam', 'bbbext_bnlocksettings'));
$this->mform->addElement('checkbox', 'enablemic', get_string('mod_form_overridemic', 'bbbext_bnlocksettings'));
$this->mform->addElement('checkbox', 'enableprivatechat', get_string('mod_form_overrideprivatechat', 'bbbext_bnlocksettings'));
$this->mform->addElement('checkbox', 'enablepublicchat', get_string('mod_form_overridepublicchat', 'bbbext_bnlocksettings'));
$this->mform->addElement('checkbox', 'enablenote', get_string('mod_form_overridenote', 'bbbext_bnlocksettings'));
$this->mform->addElement('checkbox', 'enableuserlist', get_string('mod_form_overrideuserlist', 'bbbext_bnlocksettings'));
$this->mform->addElement('header', 'bnlocksettings', get_string('pluginname', 'bbbext_bnlocksettings'));
$editsettings = false;
$config = get_config('bbbext_bnlocksettings');
$locksettings = [
'enablecam' => 'mod_form_overridecam',
'enablemic' => 'mod_form_overridemic',
'enableprivatechat' => 'mod_form_overrideprivatechat',
'enablepublicchat' => 'mod_form_overridepublicchat',
'enablenote' => 'mod_form_overridenote',
'enableuserlist' => 'mod_form_overrideuserlist',
];

$this->mform->setType('enablecam', PARAM_INT);
$this->mform->setType('enablemic', PARAM_INT);
$this->mform->setType('enableprivatechat', PARAM_INT);
$this->mform->setType('enablepublicchat', PARAM_INT);
$this->mform->setType('enablenote', PARAM_INT);
$this->mform->setType('enableuserlist', PARAM_INT);
// Check if setting should be shown in the activity.
foreach ($locksettings as $configname => $string) {
if ($config->{$configname . '_settings'} === 'editable') {
$this->add_checkbox_field($configname, $string);
$editsettings = true;
} else {
$this->mform->addElement('hidden', $configname, 0);
$this->mform->setType($configname, PARAM_INT);
}
}
// Output a string if no settings are editable.
if (!$editsettings) {
$this->mform->addElement('static', 'no_settings', '', get_string('mod_form_no_settings', 'bbbext_bnlocksettings'));
}
}

$this->mform->setDefault('enablecam', 1);
$this->mform->setDefault('enablemic', 1);
$this->mform->setDefault('enableprivatechat', 1);
$this->mform->setDefault('enablepublicchat', 1);
$this->mform->setDefault('enablenote', 1);
$this->mform->setDefault('enableuserlist', 1);
/**
* Helper method to add a checkbox element to the form.
*
* @param string $name The name of the checkbox.
* @param string $string The string for the field.
* @return void
*/
private function add_checkbox_field(string $name, string $string): void {
$this->mform->addElement('checkbox', $name, get_string($string, 'bbbext_bnlocksettings'));
$this->mform->setType($name, PARAM_INT);
$this->mform->setDefault($name, 1);
}

/**
Expand Down
100 changes: 100 additions & 0 deletions classes/lock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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 bbbext_bnlocksettings;

use bbbext_bnlocksettings\bigbluebuttonbn\mod_instance_helper;

/**
* BBB Lock class
*
* @package bbbext_bnlocksettings
* @copyright 2023 onwards, Blindside Networks Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Shamiso Jaravaza ([email protected])
*/
class lock {
/**
* Get lock settings that need to be passed.
* @param int $instanceid
* @return string
*/
public static function get_lock_settings(int $instanceid) {
$lockconfig = get_config('bbbext_bnlocksettings');
$locksettingnames = [
'lockSettingsDisableCam' => 'enablecam',
'lockSettingsDisableMic' => 'enablemic',
'lockSettingsDisablePrivateChat' => 'enableprivatechat',
'lockSettingsDisablePublicChat' => 'enablepublicchat',
'lockSettingsDisableNotes' => 'enablenote',
'lockSettingsHideUserList' => 'enableuserlist',
];
$locksettings = [];
foreach ($locksettingnames as $key => $settingname) {
$locksettings[$key] = self::get_setting($settingname, $lockconfig, $instanceid);
}
return $locksettings;
}

/**
* Get configuration at subplugin or activity level.
*
* @param string $settingname the name of the lock setting
* @param object $lockconfig the subplugin settings
* @param int $instanceid
* @return string The value of the lock
*/
private static function get_setting(string $settingname, object $lockconfig, int $instanceid) {
if ($lockconfig->{$settingname . '_settings'} === 'editable') {
return self::get_editable_value($settingname, $instanceid);
}
return self::get_default_value($settingname, $lockconfig);
}

/**
* Get activity lock setting.
*
* @param string $lockname
* @param int $instanceid
* @return array
*/
private static function get_editable_value(string $lockname, int $instanceid) {
global $DB;
$record = $DB->get_record(mod_instance_helper::SUBPLUGIN_TABLE, [
'bigbluebuttonbnid' => $instanceid,
]);
if ($record) {
// We need to invert boolean values to match API.
return $record->$lockname ? 'false' : 'true';
}
return 'false';
}

/**
* Get subplugin default lock setting.
*
* @param string $lockname
* @param object $config setting value
* @return array
*/
private static function get_default_value(string $lockname, object $config) {
if ($config->{$lockname . '_settings'} === 'disable') {
// We need to invert boolean values to match API.
return 'true';
}
return 'false';
}
}
67 changes: 51 additions & 16 deletions classes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,68 @@ class utils {
* @return string
*/
public static function get_lock_settings(int $instanceid) {
$lockconfig = get_config('bbbext_bnlocksettings');
$locksettingnames = [
'lockSettingsDisableCam' => 'enablecam',
'lockSettingsDisableMic' => 'enablemic',
'lockSettingsDisablePrivateChat' => 'enableprivatechat',
'lockSettingsDisablePublicChat' => 'enablepublicchat',
'lockSettingsDisableNotes' => 'enablenote',
'lockSettingsHideUserList' => 'enableuserlist',
];
$locksettings = [];
foreach ($locksettingnames as $key => $settingname) {
$locksettings[$key] = self::get_setting($settingname, $lockconfig, $instanceid);
}
return $locksettings;
}

/**
* Get configuration at subplugin or activity level.
*
* @param string $settingname the name of the lock setting
* @param object $lockconfig the subplugin settings
* @param int $instanceid
* @return string The value of the lock
*/
private static function get_setting(string $settingname, object $lockconfig, int $instanceid) {
if ($lockconfig->{$settingname . '_settings'} === 'editable') {
return self::get_editable_value($settingname, $instanceid);
}
return self::get_default_value($settingname, $lockconfig);
}

/**
* Get activity lock setting.
*
* @param string $lockname
* @param int $instanceid
* @return array
*/
private static function get_editable_value(string $lockname, int $instanceid) {
global $DB;
$record = $DB->get_record(mod_instance_helper::SUBPLUGIN_TABLE, [
'bigbluebuttonbnid' => $instanceid,
]);
if ($record) {
// Retrieve configurations.
return self::generate_lock_settings($record);
// We need to invert boolean values to match API.
return $record->$lockname ? 'false' : 'true';
}
return false;
return 'false';
}

/**
* Generate the lock settings based on the database record.
* Get subplugin default lock setting.
*
* @param object $record
* @param string $lockname
* @param object $config setting value
* @return array
*/
private static function generate_lock_settings($record) {
// Retrieve configurations from subplugin. We invert values to match API.
$locksettings = [
'lockSettingsDisableCam' => $record->enablecam ? 'false' : 'true',
'lockSettingsDisableMic' => $record->enablemic ? 'false' : 'true',
'lockSettingsDisablePrivateChat' => $record->enableprivatechat ? 'false' : 'true',
'lockSettingsDisablePublicChat' => $record->enablepublicchat ? 'false' : 'true',
'lockSettingsDisableNotes' => $record->enablenote ? 'false' : 'true',
'lockSettingsHideUserList' => $record->enableuserlist ? 'false' : 'true',
];
return $locksettings;
private static function get_default_value(string $lockname, object $config) {
if ($config->{$lockname . '_settings'} === 'disable') {
// We need to invert boolean values to match API.
return 'true';
}
return 'false';
}
}
25 changes: 23 additions & 2 deletions lang/en/bbbext_bnlocksettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,33 @@
*/

defined('MOODLE_INTERNAL') || die();
$string['mod_form_lockoverride_header'] = 'Override Lock Settings';
$string['mod_form_no_settings'] = 'No lock settings can be edited';
$string['mod_form_overridecam'] = 'Enable webcam';
$string['mod_form_overridemic'] = 'Enable microphone';
$string['mod_form_overridenote'] = 'Enable shared notes';
$string['mod_form_overrideprivatechat'] = 'Enable private chat';
$string['mod_form_overridepublicchat'] = 'Enable public chat';
$string['mod_form_overridenote'] = 'Enable shared notes';
$string['mod_form_overrideuserlist'] = 'Enable user list';

$string['pluginname'] = 'BN Lock Settings';

$string['settings_disable'] = 'Disable by default';
$string['settings_editable'] = 'Edit default per activity';
$string['settings_enable'] = 'Enable by default';
$string['settings_enablecam'] = 'Webcam settings';
$string['settings_enablecam_description'] = 'If enabled webcam use is allowed';
$string['settings_enablemic'] = 'Microphone settings';
$string['settings_enablemic_description'] = 'If enabled microphone use is allowed';
$string['settings_enablenote'] = 'Shared notes settings';
$string['settings_enablenote_description'] = 'If enabled shared notes can be edited';
$string['settings_enableprivatechat'] = 'Private chat settings';
$string['settings_enableprivatechat_description'] = 'If enabled users can engage in private chats in the session';
$string['settings_enablepublicchat'] = 'Public chat settings';
$string['settings_enablepublicchat_description'] = 'If enabled users can engage in public chats in the session';
$string['settings_enableuserlist'] = 'User list settings';
$string['settings_enableuserlist_description'] = 'If enabled user list can be seen';

$string['settings_header_chat'] = 'Chat Configuration';
$string['settings_header_notes'] = 'Shared Notes Configuration';
$string['settings_header_userlist'] = 'User List Configuration';
$string['settings_header_webcam'] = 'Webcam and Microphone Configuration';
26 changes: 25 additions & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,28 @@
* @author Shamiso Jaravaza ([email protected])
*/

defined('MOODLE_INTERNAL') || die;
defined('MOODLE_INTERNAL') || die();

$addsetting = function($settings, $name) {
$options = [
'enable' => get_string("settings_enable", 'bbbext_bnlocksettings'),
'disable' => get_string("settings_disable", 'bbbext_bnlocksettings'),
'editable' => get_string("settings_editable", 'bbbext_bnlocksettings'),
];

$settings->add(new admin_setting_configselect(
"bbbext_bnlocksettings/{$name}_settings",
get_string("settings_{$name}", 'bbbext_bnlocksettings'),
get_string("settings_{$name}_description", 'bbbext_bnlocksettings'),
'editable',
$options
));
};

$addsetting($settings, 'enablecam');
$addsetting($settings, 'enablemic');
$addsetting($settings, 'enableprivatechat');
$addsetting($settings, 'enablepublicchat');
$addsetting($settings, 'enablenote');
$addsetting($settings, 'enableuserlist');

0 comments on commit f991d15

Please sign in to comment.