Skip to content

Commit

Permalink
Add global default values for plugin settings BT#17134
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Apr 27, 2020
1 parent 229e016 commit 681b6c0
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 52 deletions.
8 changes: 3 additions & 5 deletions main/admin/configure_plugin.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php

/* For licensing terms, see /license.txt */

/**
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2012
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
*
* @package chamilo.admin
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';

// Access restrictions
api_protect_admin_script();

$pluginName = $_GET['name'];
Expand Down Expand Up @@ -49,7 +47,7 @@
$values = $form->getSubmitValues();

// Fix only for bbb
if ($pluginName == 'bbb') {
if ($pluginName === 'bbb') {
if (!isset($values['global_conference_allow_roles'])) {
$values['global_conference_allow_roles'] = [];
}
Expand All @@ -71,7 +69,7 @@
foreach ($values as $key => $value) {
api_add_setting(
$value,
Database::escape_string($pluginName.'_'.$key),
$pluginName.'_'.$key,
$pluginName,
'setting',
'Plugins',
Expand Down
3 changes: 0 additions & 3 deletions main/admin/course_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
use Chamilo\CoreBundle\Entity\CourseCategory;
use Chamilo\CoreBundle\Entity\Repository\CourseCategoryRepository;

/**
* @package chamilo.admin
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
Expand Down
3 changes: 1 addition & 2 deletions main/course_info/infocours.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/* For licensing terms, see /license.txt */

/**
Expand All @@ -12,8 +13,6 @@
* @author Patrick Cool <patrick.cool@UGent.be>
* @author Roan Embrechts, refactoring and improved course visibility|subscribe|unsubscribe options
* @author Julio Montoya <gugli100@gmail.com> Jquery support + lots of fixes
*
* @package chamilo.course_info
*/
require_once __DIR__.'/../inc/global.inc.php';
$current_course_tool = TOOL_COURSE_SETTING;
Expand Down
46 changes: 19 additions & 27 deletions main/inc/lib/add_course.lib.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public static function define_course_keys(
$keys_are_unique = true;

// Check whether they are unique.
$query = "SELECT 1 FROM $course_table
WHERE code='".$keys_course_id."'
$query = "SELECT 1 FROM $course_table
WHERE code='".$keys_course_id."'
LIMIT 0, 1";
$result = Database::query($query);

Expand Down Expand Up @@ -419,7 +419,7 @@ public static function fill_db_course(
$authorId = 0
) {
if (is_null($fill_with_exemplary_content)) {
$fill_with_exemplary_content = api_get_setting('example_material_course_creation') != 'false';
$fill_with_exemplary_content = api_get_setting('example_material_course_creation') !== 'false';
}
$course_id = (int) $course_id;

Expand Down Expand Up @@ -716,7 +716,6 @@ public static function fill_db_course(
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();

$chat_path = $sys_course_path.$course_repository.'/document/chat_files';

if (!is_dir($chat_path)) {
Expand Down Expand Up @@ -777,7 +776,7 @@ public static function fill_db_course(
$path_documents = "/$media_type/";

//hack until feature #5242 is implemented
if ($media_type == 'images') {
if ($media_type === 'images') {
$media_type = 'images/gallery';
$images_folder = $sys_course_path.$course_repository."/document/images/";

Expand Down Expand Up @@ -945,7 +944,6 @@ public static function fill_db_course(
);

/* Links tool */

$link = new Link();
$link->setCourse($courseInfo);
$links = [
Expand Down Expand Up @@ -1058,7 +1056,6 @@ public static function fill_db_course(
$answer->save();

/* Forum tool */

require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';

$params = [
Expand Down Expand Up @@ -1215,13 +1212,10 @@ public static function register_course($params, $accessUrlId = 1)
$course_language = isset($params['course_language']) && !empty($params['course_language']) ? $params['course_language'] : api_get_setting(
'platformLanguage'
);
$user_id = empty($params['user_id']) ? api_get_user_id() : intval($params['user_id']);
$department_name = isset($params['department_name']) ?
$params['department_name'] : null;
$department_url = isset($params['department_url']) ?
$params['department_url'] : null;
$disk_quota = isset($params['disk_quota']) ?
$params['disk_quota'] : null;
$user_id = empty($params['user_id']) ? api_get_user_id() : (int) $params['user_id'];
$department_name = isset($params['department_name']) ? $params['department_name'] : null;
$department_url = isset($params['department_url']) ? $params['department_url'] : null;
$disk_quota = isset($params['disk_quota']) ? $params['disk_quota'] : null;

if (!isset($params['visibility'])) {
$default_course_visibility = api_get_setting(
Expand All @@ -1237,7 +1231,7 @@ public static function register_course($params, $accessUrlId = 1)
}

$subscribe = isset($params['subscribe']) ? (int) $params['subscribe'] : $visibility == COURSE_VISIBILITY_OPEN_PLATFORM ? 1 : 0;
$unsubscribe = isset($params['unsubscribe']) ? intval($params['unsubscribe']) : 0;
$unsubscribe = isset($params['unsubscribe']) ? (int) $params['unsubscribe'] : 0;
$expiration_date = isset($params['expiration_date']) ? $params['expiration_date'] : null;
$teachers = isset($params['teachers']) ? $params['teachers'] : null;
$status = isset($params['status']) ? $params['status'] : null;
Expand Down Expand Up @@ -1292,8 +1286,8 @@ public static function register_course($params, $accessUrlId = 1)
) {
$department_url = 'http://'.$department_url;
}
//just in case
if ($department_url == 'http://') {
// Just in case
if ($department_url === 'http://') {
$department_url = '';
}
$course_id = 0;
Expand All @@ -1311,16 +1305,16 @@ public static function register_course($params, $accessUrlId = 1)
'category_code' => $category_code,
'visibility' => $visibility,
'show_score' => 1,
'disk_quota' => intval($disk_quota),
'disk_quota' => (int) $disk_quota,
'creation_date' => $time,
'expiration_date' => $expiration_date,
'last_edit' => $time,
'last_visit' => null,
'tutor_name' => $tutor_name,
'department_name' => $department_name,
'department_url' => $department_url,
'subscribe' => intval($subscribe),
'unsubscribe' => intval($unsubscribe),
'subscribe' => $subscribe,
'unsubscribe' => $unsubscribe,
'visual_code' => $visual_code,
]
);
Expand All @@ -1335,8 +1329,8 @@ public static function register_course($params, $accessUrlId = 1)
$code
);
if (!empty($user_id)) {
$sql = "INSERT INTO ".$TABLECOURSUSER." SET
c_id = '".$course_id."',
$sql = "INSERT INTO $TABLECOURSUSER SET
c_id = $course_id,
user_id = '".intval($user_id)."',
status = '1',
is_tutor = '0',
Expand All @@ -1352,7 +1346,7 @@ public static function register_course($params, $accessUrlId = 1)
$teachers = [$teachers];
}
foreach ($teachers as $key) {
//just in case
// Just in case.
if ($key == $user_id) {
continue;
}
Expand Down Expand Up @@ -1385,12 +1379,10 @@ public static function register_course($params, $accessUrlId = 1)
$course_id
);

$send_mail_to_admin = api_get_setting(
'send_email_to_admin_when_create_course'
);
$send_mail_to_admin = api_get_setting('send_email_to_admin_when_create_course');

// @todo Improve code to send to all current portal administrators.
if ($send_mail_to_admin == 'true') {
if ($send_mail_to_admin === 'true') {
$siteName = api_get_setting('siteName');
$recipient_email = api_get_setting('emailAdministrator');
$recipient_name = api_get_person_name(
Expand Down
33 changes: 26 additions & 7 deletions main/inc/lib/api.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1966,13 +1966,34 @@ function api_get_course_setting($settingName, $courseInfo = [], $force = false)
}
}

if (isset($courseSettingInfo[$courseId]) && isset($courseSettingInfo[$courseId][$settingName])) {
if (isset($courseSettingInfo[$courseId]) && array_key_exists($settingName, $courseSettingInfo[$courseId])) {
return $courseSettingInfo[$courseId][$settingName];
}

return -1;
}

function api_get_course_plugin_setting($plugin, $settingName, $courseInfo = [])
{
$value = api_get_course_setting($settingName, $courseInfo, true);

if (-1 === $value) {
// Check global settings
$value = api_get_plugin_setting($plugin, $settingName);
if ($value === 'true') {
return 1;
}
if ($value === 'false') {
return 0;
}
if (null === $value) {
return -1;
}
}

return $value;
}

/**
* Gets an anonymous user ID.
*
Expand Down Expand Up @@ -2875,11 +2896,10 @@ function api_get_plugin_setting($plugin, $variable)

if (isset($result[$plugin])) {
$value = $result[$plugin];
$unSerialized = UnserializeApi::unserialize('not_allowed_classes', $value, true);

$unserialized = UnserializeApi::unserialize('not_allowed_classes', $value, true);

if (false !== $unserialized) {
$value = $unserialized;
if (false !== $unSerialized) {
$value = $unSerialized;
}

return $value;
Expand All @@ -2894,9 +2914,8 @@ function api_get_plugin_setting($plugin, $variable)
function api_get_settings_params($params)
{
$table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$result = Database::select('*', $table, ['where' => $params]);

return $result;
return Database::select('*', $table, ['where' => $params]);
}

/**
Expand Down
15 changes: 11 additions & 4 deletions main/inc/lib/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function getSettingsForm()
$help = null;
if ($this->get_lang_plugin_exists($name.'_help')) {
$help = $this->get_lang($name.'_help');
if ($name === "show_main_menu_tab") {
if ($name === 'show_main_menu_tab') {
$pluginName = strtolower(str_replace('Plugin', '', get_class($this)));
$pluginUrl = api_get_path(WEB_PATH)."plugin/$pluginName/index.php";
$pluginUrl = "<a href=$pluginUrl>$pluginUrl</a>";
Expand Down Expand Up @@ -275,6 +275,7 @@ public function getSettingsForm()
$selectedValue = 'checked';
}
}

$element = $result->createElement(
$type,
$name,
Expand All @@ -301,7 +302,8 @@ public function getSettingsForm()
$result->addGroup(
$checkboxGroup,
null,
[$this->get_lang('sms_types'), $help]
['', $help]
//[$this->get_lang('sms_types'), $help]
);
}
$result->setDefaults($defaults);
Expand Down Expand Up @@ -478,6 +480,11 @@ public function install_course_fields($courseId, $add_tool_link = true)
$value = $setting['init_value'];
}

$pluginGlobalValue = api_get_plugin_setting($plugin_name, $variable);
if (null !== $pluginGlobalValue) {
$value = 1;
}

$type = 'textfield';
if (isset($setting['type'])) {
$type = $setting['type'];
Expand Down Expand Up @@ -571,11 +578,11 @@ public function uninstall_course_fields($courseId)

$pluginName = Database::escape_string($pluginName);
$sql = "DELETE FROM $t_tool
WHERE c_id = $courseId AND
WHERE c_id = $courseId AND
(
name = '$pluginName' OR
name = '$pluginName:student' OR
name = '$pluginName:teacher'
name = '$pluginName:teacher'
)";
Database::query($sql);
}
Expand Down
13 changes: 13 additions & 0 deletions main/inc/lib/plugin.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,22 @@ class="panel-collapse collapse" role="tabpanel"
'',
$obj->get_lang($setting['name'])
);

// Check global settings
$courseSetting = api_get_course_setting($setting['name']);
if (-1 === $courseSetting) {
$defaultValue = api_get_plugin_setting($plugin_name, $setting['name']);
if (!empty($defaultValue)) {
if ('true' === $defaultValue) {
$element->setChecked(true);
}
}
}

if (isset($setting['init_value']) && $setting['init_value'] == 1) {
$element->setChecked(true);
}

$form->addElement($element);
if (isset($setting['group'])) {
$groups[$setting['group']][] = $element;
Expand Down
7 changes: 4 additions & 3 deletions plugin/bbb/lib/bbb.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public function __construct(
// Course check
$courseInfo = api_get_course_info();
if ($courseInfo) {
$this->groupSupport = api_get_course_setting(
$this->groupSupport = api_get_course_plugin_setting(
'bbb',
'bbb_enable_conference_in_groups',
$courseInfo
) === '1';
Expand Down Expand Up @@ -356,8 +357,8 @@ public function createMeeting($params)
$params['moderator_pw'] = isset($params['moderator_pw']) ? $params['moderator_pw'] : $this->getModMeetingPassword();
$moderatorPassword = $params['moderator_pw'];

$params['record'] = api_get_course_setting('big_blue_button_record_and_store') == 1 ? true : false;
$max = api_get_course_setting('big_blue_button_max_students_allowed');
$params['record'] = api_get_course_plugin_setting('bbb', 'big_blue_button_record_and_store') == 1 ? true : false;
$max = api_get_course_plugin_setting('bbb', 'big_blue_button_max_students_allowed');
$max = isset($max) ? $max : -1;

$params['status'] = 1;
Expand Down
4 changes: 4 additions & 0 deletions plugin/bbb/lib/bbb_plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ protected function __construct()
'translate_options' => true, // variables will be translated using the plugin->get_lang
],
'allow_regenerate_recording' => 'boolean',
// Default course settings, must be the same as $course_settings
'big_blue_button_record_and_store' => 'checkbox',
'bbb_enable_conference_in_groups' => 'checkbox',
'bbb_force_record_generation' => 'checkbox',
]
);

Expand Down
3 changes: 2 additions & 1 deletion plugin/bbb/listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@
break;
case 'logout':
if ($plugin->get('allow_regenerate_recording') === 'true') {
$allow = api_get_course_setting('bbb_force_record_generation', $courseInfo) == 1 ? true : false;
$setting = api_get_course_plugin_setting('bbb', 'bbb_force_record_generation', $courseInfo);
$allow = $setting == 1 ? true : false;
if ($allow) {
$result = $bbb->getMeetingByRemoteId($_GET['remote_id']);
if (!empty($result)) {
Expand Down

0 comments on commit 681b6c0

Please sign in to comment.