Commit 0db24a20 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

Merge branch 'MDL-49423-master' of git://github.com/jleyva/moodle

parents 9f43d505 b2551b4c
{{!
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/>.
}}
{{!
@template core_admin/setting_configmultiselect_optgroup
Admin multiselect setting template with optgroup support.
Context variables required for this template:
* name - form element name
* id - element id
* size - element size
* options - list of options not grouped
* optgroups - list of options grouped containing the group label and for each option: name, value, selected
Example context (json):
{
"name": "test",
"id": "test0",
"size": "3",
"options": [
{ "name": "Option 1", "value": "V", "selected": false },
{ "name": "Option 2", "value": "V", "selected": true }
],
"optgroups": [
{
"label": "Group 1",
"options": [
{ "name": "Option 3", "value": "V", "selected": false },
{ "name": "Option 4", "value": "V", "selected": true }
]
},
{
"label": "Group 2",
"options": [
{ "name": "Option 5", "value": "V", "selected": false },
{ "name": "Option 6", "value": "V", "selected": true }
]
}
]
}
}}
<div class="form-select">
<input type="hidden" name="{{name}}[xxxxx]" value="1">
<select id="{{id}}" name="{{name}}[]" size="{{size}}" multiple>
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
{{#optgroups}}
<optgroup label="{{label}}">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</optgroup>
{{/optgroups}}
</select>
</div>
{{!
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/>.
}}
{{!
@template core_admin/setting_configselect_optgroup
Admin select with optgroup setting template.
Context variables required for this template:
* name - form element name
* id - element id
* options - list of options (not grouped)
* optgroups - list of options grouped containing the group label and for each option: name, value, selected
Example context (json):
{
"name": "test",
"id": "test0",
"options": [
{ "name": "Option 1", "value": "V", "selected": false },
{ "name": "Option 2", "value": "V", "selected": false }
],
"optgroups": [
{
"label": "Group 1",
"options": [
{ "name": "Option 3", "value": "V", "selected": true },
{ "name": "Option 4", "value": "V", "selected": false }
]
},
{
"label": "Group 2",
"options": [
{ "name": "Option 5", "value": "V", "selected": false },
{ "name": "Option 6", "value": "V", "selected": false }
]
}
]
}
}}
<div class="form-select defaultsnext">
<select id="{{id}}" name="{{name}}">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
{{#optgroups}}
<optgroup label="{{label}}">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</optgroup>
{{/optgroups}}
</select>
</div>
......@@ -29,9 +29,10 @@ use core_plugin_manager;
use context_system;
use moodle_url;
use moodle_exception;
use lang_string;
/**
* API exposed by tool_mobile, to be used mostly by external functions.
* API exposed by tool_mobile, to be used mostly by external functions and the plugin settings.
*
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
......@@ -127,6 +128,7 @@ class api {
'maintenanceenabled' => $CFG->maintenance_enabled,
'maintenancemessage' => $maintenancemessage,
'mobilecssurl' => !empty($CFG->mobilecssurl) ? $CFG->mobilecssurl : '',
'tool_mobile_disabledfeatures' => get_config('tool_mobile', 'disabledfeatures'),
);
$typeoflogin = get_config('tool_mobile', 'typeoflogin');
......@@ -207,6 +209,7 @@ class api {
if (empty($section) or $section == 'mobileapp') {
$settings->tool_mobile_forcelogout = get_config('tool_mobile', 'forcelogout');
$settings->tool_mobile_customlangstrings = get_config('tool_mobile', 'customlangstrings');
$settings->tool_mobile_disabledfeatures = get_config('tool_mobile', 'disabledfeatures');
}
return $settings;
......@@ -251,4 +254,87 @@ class api {
$validuntil = time() + self::LOGIN_KEY_TTL;
return create_user_key('tool_mobile', $USER->id, null, $iprestriction, $validuntil);
}
/**
* Get a list of the Mobile app features.
*
* @return array array with the features grouped by theirs ubication in the app.
* @since Moodle 3.3
*/
public static function get_features_list() {
global $CFG;
$general = new lang_string('general');
$mainmenu = new lang_string('mainmenu', 'tool_mobile');
$course = new lang_string('course');
$modules = new lang_string('managemodules');
$user = new lang_string('user');
$files = new lang_string('files');
$remoteaddons = new lang_string('remoteaddons', 'tool_mobile');
$availablemods = core_plugin_manager::instance()->get_plugins_of_type('mod');
$coursemodules = array();
$appsupportedmodules = array('assign', 'book', 'chat', 'choice', 'folder', 'forum', 'glossary', 'imscp', 'label',
'lti', 'page', 'quiz', 'resource', 'scorm', 'survey', 'url', 'wiki');
foreach ($availablemods as $mod) {
if (in_array($mod->name, $appsupportedmodules)) {
$coursemodules['$mmCourseDelegate_mmaMod' . ucfirst($mod->name)] = $mod->displayname;
}
}
$remoteaddonslist = array();
$mobileplugins = self::get_plugins_supporting_mobile();
foreach ($mobileplugins as $plugin) {
$displayname = core_plugin_manager::instance()->plugin_name($plugin['component']) . " - " . $plugin['addon'];
$remoteaddonslist['remoteAddOn_' . $plugin['component'] . '_' . $plugin['addon']] = $displayname;
}
$features = array(
'$mmLoginEmailSignup' => new lang_string('startsignup'),
"$mainmenu" => array(
'$mmSideMenuDelegate_mmCourses' => new lang_string('mycourses'),
'$mmSideMenuDelegate_mmaFrontpage' => new lang_string('sitehome'),
'$mmSideMenuDelegate_mmaGrades' => new lang_string('grades', 'grades'),
'$mmSideMenuDelegate_mmaCompetency' => new lang_string('myplans', 'tool_lp'),
'$mmSideMenuDelegate_mmaNotifications' => new lang_string('notifications', 'message'),
'$mmSideMenuDelegate_mmaMessages' => new lang_string('messages', 'message'),
'$mmSideMenuDelegate_mmaCalendar' => new lang_string('calendar', 'calendar'),
'$mmSideMenuDelegate_mmaFiles' => new lang_string('files'),
'$mmSideMenuDelegate_website' => new lang_string('webpage'),
'$mmSideMenuDelegate_help' => new lang_string('help'),
),
"$course" => array(
'$mmCoursesDelegate_search' => new lang_string('search'),
'$mmCoursesDelegate_mmaCompetency' => new lang_string('competencies', 'competency'),
'$mmCoursesDelegate_mmaParticipants' => new lang_string('participants'),
'$mmCoursesDelegate_mmaGrades' => new lang_string('grades', 'grades'),
'$mmCoursesDelegate_mmaCourseCompletion' => new lang_string('coursecompletion', 'completion'),
'$mmCoursesDelegate_mmaNotes' => new lang_string('notes', 'notes'),
),
"$user" => array(
'$mmUserDelegate_mmaBadges' => new lang_string('badges', 'badges'),
'$mmUserDelegate_mmaCompetency:learningPlan' => new lang_string('competencies', 'competency'),
'$mmUserDelegate_mmaCourseCompletion:viewCompletion' => new lang_string('coursecompletion', 'completion'),
'$mmUserDelegate_mmaGrades:viewGrades' => new lang_string('grades', 'grades'),
'$mmUserDelegate_mmaMessages:sendMessage' => new lang_string('sendmessage', 'message'),
'$mmUserDelegate_mmaMessages:addContact' => new lang_string('addcontact', 'message'),
'$mmUserDelegate_mmaMessages:blockContact' => new lang_string('blockcontact', 'message'),
'$mmUserDelegate_mmaNotes:addNote' => new lang_string('addnewnote', 'notes'),
'$mmUserDelegate_picture' => new lang_string('userpic'),
),
"$files" => array(
'files_privatefiles' => new lang_string('privatefiles'),
'files_sitefiles' => new lang_string('sitefiles'),
'files_upload' => new lang_string('upload'),
),
"$modules" => $coursemodules,
);
if (!empty($remoteaddonslist)) {
$features["$remoteaddons"] = $remoteaddonslist;
}
return $features;
}
}
......@@ -149,6 +149,7 @@ class external extends external_api {
'typeoflogin' => new external_value(PARAM_INT, 'The type of login. 1 for app, 2 for browser, 3 for embedded.'),
'launchurl' => new external_value(PARAM_URL, 'SSO login launch URL. Empty if it won\'t be used.', VALUE_OPTIONAL),
'mobilecssurl' => new external_value(PARAM_URL, 'Mobile custom CSS theme', VALUE_OPTIONAL),
'tool_mobile_disabledfeatures' => new external_value(PARAM_RAW, 'Disabled features in the app', VALUE_OPTIONAL),
'warnings' => new external_warnings(),
)
);
......
......@@ -33,6 +33,8 @@ mm.user.student|Learner|en
mm.user.student|Aprendiz|es
</pre>
For a complete list of string identifiers and more information, see the <a href="{$a}">documentation page</a>.';
$string['disabledfeatures'] = 'Disabled features';
$string['disabledfeatures_desc'] = 'Select here the features you want to disable in the Mobile app for your site. Please note that some features listed here could be already disabled via other site settings. You will have to log out and log in again in the app to see the changes.';
$string['enablesmartappbanners'] = 'Enable Smart App Banners';
$string['enablesmartappbanners_desc'] = 'This will display a banner promoting the Moodle Mobile app when visiting the site in Mobile Safari.';
$string['forcedurlscheme'] = 'If you want to allow only your custom branded app to be opened via a browser window, then specify its URL scheme here; otherwise leave the field empty.';
......@@ -46,6 +48,7 @@ $string['iosappid_desc'] = 'This setting may be left as default unless you have
$string['loginintheapp'] = 'Via the app';
$string['logininthebrowser'] = 'Via a browser window (for SSO plugins)';
$string['loginintheembeddedbrowser'] = 'Via an embedded browser (for SSO plugins)';
$string['mainmenu'] = 'Main menu';
$string['mobileapp'] = 'Mobile app';
$string['mobileappearance'] = 'Mobile appearance';
$string['mobileauthentication'] = 'Mobile authentication';
......@@ -55,5 +58,6 @@ $string['mobilesettings'] = 'Mobile settings';
$string['pluginname'] = 'Moodle Mobile tools';
$string['smartappbanners'] = 'Smart App Banners (iOS only)';
$string['pluginnotenabledorconfigured'] = 'Plugin not enabled or configured.';
$string['remoteaddons'] = 'Remote add-ons';
$string['typeoflogin'] = 'Type of login';
$string['typeoflogin_desc'] = 'Choose the type of login.';
......@@ -92,6 +92,14 @@ if ($hassiteconfig) {
new lang_string('forcelogout', 'tool_mobile'),
new lang_string('forcelogout_desc', 'tool_mobile'), 0));
$temp->add(new admin_setting_heading('tool_mobile/features',
new lang_string('mobilefeatures', 'tool_mobile'), ''));
$options = tool_mobile\api::get_features_list();
$temp->add(new admin_setting_configmultiselect('tool_mobile/disabledfeatures',
new lang_string('disabledfeatures', 'tool_mobile'),
new lang_string('disabledfeatures_desc', 'tool_mobile'), array(), $options));
$temp->add(new admin_setting_heading('tool_mobile/language',
new lang_string('language'), ''));
......
......@@ -84,6 +84,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
'maintenancemessage' => $maintenancemessage,
'typeoflogin' => api::LOGIN_VIA_APP,
'mobilecssurl' => '',
'tool_mobile_disabledfeatures' => '',
'warnings' => array()
);
$this->assertEquals($expected, $result);
......@@ -146,6 +147,7 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase {
array('name' => 'mygradesurl', 'value' => user_mygrades_url()->out(false)),
array('name' => 'tool_mobile_forcelogout', 'value' => 0),
array('name' => 'tool_mobile_customlangstrings', 'value' => ''),
array('name' => 'tool_mobile_disabledfeatures', 'value' => ''),
);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($expected, $result['settings']);
......
......@@ -23,7 +23,7 @@
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016120502; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2016120503; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2016112900; // Requires this Moodle version.
$plugin->component = 'tool_mobile'; // Full name of the plugin (used for diagnostics).
$plugin->dependencies = array(
......
This files describes API changes in /admin/*.
=== 3.3 ===
* The admin settings admin_setting_configselect and admin_setting_configmultiselect now support the optgroup tag.
Grouping of options can be created with this new tag.
For using it, the option parameters needs the Group names as indexes:
[
"Spain" => ["madrid" => "Madrid", "barcelona" => "Barcelona"],
"France" => ["paris" => "Paris", "marseille" => "Marseille"],
]
=== 3.2 ===
* Admin settings have been refined to better support right-to-left languages. In RTL,
......
......@@ -2946,6 +2946,8 @@ class admin_setting_configmulticheckbox2 extends admin_setting_configmulticheckb
class admin_setting_configselect extends admin_setting {
/** @var array Array of choices value=>label */
public $choices;
/** @var array Array of choices grouped using optgroups */
public $optgroups;
/**
* Constructor
......@@ -2956,7 +2958,18 @@ class admin_setting_configselect extends admin_setting {
* @param array $choices array of $value=>$label for each selection
*/
public function __construct($name, $visiblename, $description, $defaultsetting, $choices) {
$this->choices = $choices;
// Look for optgroup and single options.
if (is_array($choices)) {
foreach ($choices as $key => $val) {
if (is_array($val)) {
$this->optgroups[$key] = $val;
$this->choices = array_merge($this->choices, $val);
} else {
$this->choices[$key] = $val;
}
}
}
parent::__construct($name, $visiblename, $description, $defaultsetting);
}
......@@ -3089,6 +3102,27 @@ class admin_setting_configselect extends admin_setting {
}
$options = [];
$template = 'core_admin/setting_configselect';
if (!empty($this->optgroups)) {
$optgroups = [];
foreach ($this->optgroups as $label => $choices) {
$optgroup = array('label' => $label, 'options' => []);
foreach ($choices as $value => $name) {
$optgroup['options'][] = [
'value' => $value,
'name' => $name,
'selected' => (string) $value == $data
];
unset($this->choices[$value]);
}
$optgroups[] = $optgroup;
}
$context->options = $options;
$context->optgroups = $optgroups;
$template = 'core_admin/setting_configselect_optgroup';
}
foreach ($this->choices as $value => $name) {
$options[] = [
'value' => $value,
......@@ -3098,7 +3132,7 @@ class admin_setting_configselect extends admin_setting {
}
$context->options = $options;
$element = $OUTPUT->render_from_template('core_admin/setting_configselect', $context);
$element = $OUTPUT->render_from_template($template, $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, $warning, $defaultinfo, $query);
}
......@@ -3221,6 +3255,29 @@ class admin_setting_configmultiselect extends admin_setting_configselect {
$defaults = [];
$options = [];
$template = 'core_admin/setting_configmultiselect';
if (!empty($this->optgroups)) {
$optgroups = [];
foreach ($this->optgroups as $label => $choices) {
$optgroup = array('label' => $label, 'options' => []);
foreach ($choices as $value => $name) {
if (in_array($value, $default)) {
$defaults[] = $name;
}
$optgroup['options'][] = [
'value' => $value,
'name' => $name,
'selected' => in_array($value, $data)
];
unset($this->choices[$value]);
}
$optgroups[] = $optgroup;
}
$context->optgroups = $optgroups;
$template = 'core_admin/setting_configmultiselect_optgroup';
}
foreach ($this->choices as $value => $name) {
if (in_array($value, $default)) {
$defaults[] = $name;
......@@ -3241,7 +3298,7 @@ class admin_setting_configmultiselect extends admin_setting_configselect {
$defaultinfo = get_string('none');
}
$element = $OUTPUT->render_from_template('core_admin/setting_configmultiselect', $context);
$element = $OUTPUT->render_from_template($template, $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
}
......
{{!
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/>.
}}
{{!
Setting configmultiselect with optgroup support.
}}
<div class="form-select">
<input type="hidden" name="{{name}}[xxxxx]" value="1">
<select id="{{id}}" name="{{name}}[]" size="{{size}}" class="form-control" multiple>
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
{{#optgroups}}
<optgroup label="{{label}}">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</optgroup>
{{/optgroups}}
</select>
</div>
{{!
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/>.
}}
{{!
Setting configselect with optgroup support.
}}
<div class="form-select defaultsnext">
<select id="{{id}}" name="{{name}}" class="custom-select">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
{{#optgroups}}
<optgroup label="{{label}}">
{{#options}}
<option value="{{value}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/options}}
</optgroup>
{{/optgroups}}
</select>
</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment