Add global default values for plugin settings BT#17134

pull/3213/head
Julio Montoya 5 years ago
parent 229e016fe6
commit 681b6c0ea4
  1. 8
      main/admin/configure_plugin.php
  2. 3
      main/admin/course_add.php
  3. 3
      main/course_info/infocours.php
  4. 42
      main/inc/lib/add_course.lib.inc.php
  5. 33
      main/inc/lib/api.lib.php
  6. 11
      main/inc/lib/plugin.class.php
  7. 13
      main/inc/lib/plugin.lib.php
  8. 7
      plugin/bbb/lib/bbb.lib.php
  9. 4
      plugin/bbb/lib/bbb_plugin.class.php
  10. 3
      plugin/bbb/listing.php

@ -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'];
@ -49,7 +47,7 @@ if (isset($form)) {
$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'] = [];
}
@ -71,7 +69,7 @@ if (isset($form)) {
foreach ($values as $key => $value) {
api_add_setting(
$value,
Database::escape_string($pluginName.'_'.$key),
$pluginName.'_'.$key,
$pluginName,
'setting',
'Plugins',

@ -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;

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
/**
@ -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;

@ -419,7 +419,7 @@ class AddCourse
$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;
@ -716,7 +716,6 @@ class AddCourse
$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)) {
@ -777,7 +776,7 @@ class AddCourse
$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/";
@ -945,7 +944,6 @@ class AddCourse
);
/* Links tool */
$link = new Link();
$link->setCourse($courseInfo);
$links = [
@ -1058,7 +1056,6 @@ class AddCourse
$answer->save();
/* Forum tool */
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
$params = [
@ -1215,13 +1212,10 @@ class AddCourse
$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(
@ -1237,7 +1231,7 @@ class AddCourse
}
$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;
@ -1292,8 +1286,8 @@ class AddCourse
) {
$department_url = 'http://'.$department_url;
}
//just in case
if ($department_url == 'http://') {
// Just in case
if ($department_url === 'http://') {
$department_url = '';
}
$course_id = 0;
@ -1311,7 +1305,7 @@ class AddCourse
'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,
@ -1319,8 +1313,8 @@ class AddCourse
'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,
]
);
@ -1335,8 +1329,8 @@ class AddCourse
$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',
@ -1352,7 +1346,7 @@ class AddCourse
$teachers = [$teachers];
}
foreach ($teachers as $key) {
//just in case
// Just in case.
if ($key == $user_id) {
continue;
}
@ -1385,12 +1379,10 @@ class AddCourse
$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(

@ -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.
*
@ -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;
@ -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]);
}
/**

@ -232,7 +232,7 @@ class Plugin
$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>";
@ -275,6 +275,7 @@ class Plugin
$selectedValue = 'checked';
}
}
$element = $result->createElement(
$type,
$name,
@ -301,7 +302,8 @@ class Plugin
$result->addGroup(
$checkboxGroup,
null,
[$this->get_lang('sms_types'), $help]
['', $help]
//[$this->get_lang('sms_types'), $help]
);
}
$result->setDefaults($defaults);
@ -478,6 +480,11 @@ class Plugin
$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'];

@ -719,9 +719,22 @@ class AppPlugin
'',
$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;

@ -85,7 +85,8 @@ class bbb
// 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';
@ -356,8 +357,8 @@ class bbb
$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;

@ -83,6 +83,10 @@ class BBBPlugin extends Plugin
'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',
]
);

@ -130,7 +130,8 @@ if ($conferenceManager) {
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)) {

Loading…
Cancel
Save